def delete_data(self, conn_string): """ :param conn_string: :return: """ drop_test_table(conn_string)
def test_compression_negative(self, request, install_postgres): """ Test for compression feature. Scenario: 1. Create tablespace with compression 2. Run pgbench for tablespace with compression and kill postgres process 3. Run postgres process and check that postgres is running 4. Check that cfm files created 5. Check that pgbench tables don't created """ version = request.config.getoption('--product_version') name = request.config.getoption('--product_name') edition = request.config.getoption('--product_edition') product_info = " ".join([self.dist, name, edition, version]) # pylint: disable=no-member tag_mark = pytest.allure.label(LabelType.TAG, product_info) request.node.add_marker(tag_mark) # Step 1 compression_files_directory = self.create_tablespace( 'compression_negative', compression=True) print(compression_files_directory) install_postgres.set_option('default_tablespace', 'compression_negative') postgres_pid = install_postgres.get_postmaster_pid() print(postgres_pid) # Step 2 create_table_process = Process(target=create_test_table, args=( '20', 'pgbench', )) create_table_process.start() time.sleep(10) # Step 3 if create_table_process.is_alive(): process = psutil.Process(postgres_pid) process.kill() compression_files = self.get_filenames(compression_files_directory) # Step 4 # Files for tables created but no any table was created # because transaction was corruped assert '.cfm' in compression_files install_postgres.manage_psql('start') # Step 5 conn_string = "host='localhost' user='******' " conn = psycopg2.connect(conn_string) cursor = conn.cursor() cursor.execute("SELECT * FROM pg_tables" " WHERE tablespace=\'compression_negative\';") assert len(cursor.fetchall()) == 0 drop_test_table(conn_string)
def test_compression_standalone_positive(self, request, install_postgres): """ Test for compression feature. Scenario: 1. Create test tables 1. Create tablespace with compression 2. Save size of created tables by fixture in file system (count and size of files) 3. Run data generator for tablespace with compression 4. Save size of table with compression 5. Check that files for table in tablespace without compression > that files in tablespace with compression 6. Check tablespace folder for files with *.cfm extension 7. Check that tables has some data """ # Step 1 create_test_table('20', 'pgbench') # Step 2 compression_files_directory = self.create_tablespace('compression', compression=True) # Step 3 data_size_without_compression = self.get_directory_size( install_postgres.get_option('data_directory')) # Step 4 print(data_size_without_compression) install_postgres.set_option('default_tablespace', 'compression') create_test_table(size='20', schema='pgbench') # Step 5 data_size_with_compression = self.get_directory_size( install_postgres.get_option('data_directory')) print(data_size_with_compression) print(compression_files_directory) # Step 6 assert data_size_with_compression < data_size_without_compression # Step 7 compression_files = self.get_filenames(compression_files_directory) assert '.cfm' in compression_files # Step 8 conn_string = "host='localhost' user='******' " conn = psycopg2.connect(conn_string) cursor = conn.cursor() cursor.execute("SELECT * FROM pgbench_tellers LIMIT 10;") result = cursor.fetchall() print(result) assert result != 0 conn.close() drop_test_table(conn_string)
def install_postgres(request): """This fixture for postgres installation on different platforms :param request default param for pytest it helps us to pass command line variables from pytest_addoption() method :return: """ from helpers.pginstance import PgInstance from helpers.sql_helpers import drop_test_table skip_install = request.config.getoption("--skip_install") version = request.config.getoption('--product_version') milestone = request.config.getoption('--product_milestone') name = request.config.getoption('--product_name') edition = request.config.getoption('--product_edition') branch = request.config.getoption('--branch') if skip_install: local = True windows = False yield PgInstance(version, milestone, name, edition, local, branch, windows=windows) if request.node.name != "test_delete_packages": drop_test_table("host='localhost' user='******'") else: if request.config.getoption('--target')[0:3] == 'win': local = False windows = True pginstance = PgInstance( version=version, milestone=milestone, name=name, edition=edition, skip_install=local, branch=branch, windows=windows) pginstance.install_product( version=version, milestone=milestone, name=name, edition=edition, branch=branch, windows=windows) yield pginstance if request.node.name != "test_delete_packages": drop_test_table("host='localhost' user='******'") else: local = False windows = False pginstance = PgInstance(version, milestone, name, edition, local, branch, windows=windows) pginstance.install_product( version=version, milestone=milestone, name=name, edition=edition, branch=branch, windows=windows) yield pginstance if request.node.name != "test_delete_packages": drop_test_table("host='localhost' user='******'")
def delete_tables(): drop_test_table("host='localhost' user='******'")