From 8442cccd372de5d2d58ef5143235e377a2fddc2e Mon Sep 17 00:00:00 2001 From: Kamil Braun Date: Thu, 26 Jan 2023 17:35:53 +0100 Subject: [PATCH] test/topology: don't drop random_tables keyspace after a failed test After a failed test, the cluster might be down so dropping the random_tables keyspace might be impossible. The cluster will be marked dirty so it doesn't matter that we leave any garbage there. Note: we already drop only if the cluster is not marked as dirty, and we mark the cluster as dirty after a failed test. However, marking the cluster as dirty after a failed test happens at the end of the `manager` fixture and the `random_tables` fixture depends on the `manager` fixture, so at the end of the `random_tables` fixture the cluster still wasn't marked as dirty. Hence the fixture must access the pytest-provided `request` fixture where we store a flag whether the test has failed. --- test/topology/conftest.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/topology/conftest.py b/test/topology/conftest.py index 4e024f703c..da83ee17ce 100644 --- a/test/topology/conftest.py +++ b/test/topology/conftest.py @@ -216,10 +216,18 @@ def fails_without_consistent_cluster_management(request, check_pre_consistent_cl # "random_tables" fixture: Creates and returns a temporary RandomTables object # used in tests to make schema changes. Tables are dropped after test finishes -# unless the cluster is dirty. +# unless the cluster is dirty or the test has failed. @pytest.fixture(scope="function") async def random_tables(request, manager): tables = RandomTables(request.node.name, manager, unique_name()) yield tables - if not await manager.is_dirty(): + + # Don't drop tables at the end if we failed or the cluster is dirty - it may be impossible + # (e.g. the cluster is completely dead) and it doesn't matter (we won't reuse the cluster + # anyway). + # The cluster will be marked as dirty if the test failed, but that happens + # at the end of `manager` fixture which we depend on (so these steps will be + # executed after us) - so at this point, we need to check for failure ourselves too. + failed = request.node.stash[FAILED_KEY] + if not failed and not await manager.is_dirty(): tables.drop_all()