From 58d5339baacbab5ddccb8a3ada0f3343232db981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Botond=20D=C3=A9nes?= Date: Fri, 22 Dec 2023 03:23:01 -0500 Subject: [PATCH] test/cql-pytest: test_tools.py: extract some fixture logic to functions Namely, the fixture for preparing an sstable and the fixture for producing a reference dump (from an sstable). In the next patch we will add more similar fixtures, this patch enables them to share their core logic, without repeating code. --- test/cql-pytest/test_tools.py | 43 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/test/cql-pytest/test_tools.py b/test/cql-pytest/test_tools.py index 5bb955f34f..bd2985e2b4 100644 --- a/test/cql-pytest/test_tools.py +++ b/test/cql-pytest/test_tools.py @@ -534,24 +534,35 @@ class TestScyllaSsstableSchemaLoadingBase: return glob.glob(os.path.join(temp_workdir, "*-Data.db"))[0] -@pytest.fixture(scope="class") -def system_scylla_local_sstable_prepared(cql, scylla_data_dir): - """ Prepares the system.scylla_local table for the needs of the schema loading tests. +@contextlib.contextmanager +def _prepare_sstable(cql, scylla_data_dir, table, write_fun=None): + """ Prepares the table for the needs of the schema loading tests. Namely: - * Disable auto-compaction for the system-schema keyspace and system.scylla_local table. + * Disable auto-compaction for the system-schema keyspace and table's keyspace. * Flushes said keyspaces. - * Locates an sstable belonging to system.scylla_local and returns it. + * Locates an sstable belonging to the table and returns it. """ - with nodetool.no_autocompaction_context(cql, "system.scylla_local", "system_schema"): + keyspace_name, table_name = table.split(".") + with nodetool.no_autocompaction_context(cql, keyspace_name, "system_schema"): + if write_fun is not None: + write_fun() + # Need to flush system keyspaces whose sstables we want to meddle # with, to make sure they are actually on disk. nodetool.flush_keyspace(cql, "system_schema") - nodetool.flush_keyspace(cql, "system") - sstables = glob.glob(os.path.join(scylla_data_dir, "system", "scylla_local-*", "*-Data.db")) + nodetool.flush_keyspace(cql, keyspace_name) + + sstables = glob.glob(os.path.join(scylla_data_dir, keyspace_name, table_name + "-*", "*-Data.db")) yield sstables[0] +@pytest.fixture(scope="class") +def system_scylla_local_sstable_prepared(cql, scylla_data_dir): + with _prepare_sstable(cql, scylla_data_dir, "system.scylla_local") as sst: + yield sst + + @pytest.fixture(scope="class") def system_scylla_local_schema_file(): """ Prepares a schema.cql with the schema of system.scylla_local. """ @@ -582,23 +593,25 @@ def scylla_home_dir(scylla_data_dir): yield scylla_home -@pytest.fixture(scope="class") -def system_scylla_local_reference_dump(scylla_path, system_scylla_local_sstable_prepared): - """ Produce a reference json dump of the system.scylla_local sstable. """ +def _produce_reference_dump(scylla_path, schema_args, sstable): + """ Produce a json dump, to be used as a reference, of the specified sstable. """ dump_reference = subprocess.check_output([ scylla_path, "sstable", "dump-data", "--output-format", "json", "--logger-log-level", "scylla-sstable=debug", - "--system-schema", - "--keyspace", "system", - "--table", "scylla_local", - system_scylla_local_sstable_prepared]) + ] + schema_args + [sstable]) dump_reference = json.loads(dump_reference)["sstables"] return list(dump_reference.values())[0] +@pytest.fixture(scope="class") +def system_scylla_local_reference_dump(scylla_path, system_scylla_local_sstable_prepared): + return _produce_reference_dump(scylla_path, ["--system-schema", "--keyspace", "system", "--table", "scylla_local"], + system_scylla_local_sstable_prepared) + + class TestScyllaSsstableSchemaLoading(TestScyllaSsstableSchemaLoadingBase): """ Test class containing all the schema loader tests.