From 24fd30f7eba4b7560ae1e6da1be7ec96acdca7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Tue, 19 Dec 2023 15:58:36 +0100 Subject: [PATCH] Add wait_for_zones_loaded fixture The wait_for_zones_loaded fixture waits for the "all zones loaded" message in the named log file before the test function can proceed. (cherry picked from commit 662a88055c59d0abc00d3db06c573bab2eca5463) --- bin/tests/system/conftest.py | 21 +++++++++++++++++++++ bin/tests/system/pytest.ini | 2 ++ 2 files changed, 23 insertions(+) diff --git a/bin/tests/system/conftest.py b/bin/tests/system/conftest.py index 692743115c..a1a42770cf 100644 --- a/bin/tests/system/conftest.py +++ b/bin/tests/system/conftest.py @@ -357,6 +357,27 @@ def mlogger(system_test_name): return logging.getLogger(system_test_name) +def _get_marker(node, marker): + try: + # pytest >= 4.x + return node.get_closest_marker(marker) + except AttributeError: + # pytest < 4.x + return node.get_marker(marker) + + +@pytest.fixture(autouse=True) +def wait_for_zones_loaded(request, servers): + """Wait for all zones to be loaded by specified named instances.""" + instances = _get_marker(request.node, "requires_zones_loaded") + if not instances: + return + + for instance in instances.args: + with servers[instance].watch_log_from_start() as watcher: + watcher.wait_for_line("all zones loaded") + + @pytest.fixture def logger(request, system_test_name): """Logging facility specific to a particular test.""" diff --git a/bin/tests/system/pytest.ini b/bin/tests/system/pytest.ini index 1559595852..a8733cefb6 100644 --- a/bin/tests/system/pytest.ini +++ b/bin/tests/system/pytest.ini @@ -18,3 +18,5 @@ log_level = INFO python_files = tests_*.py junit_logging = log junit_log_passing_tests = 0 +markers = + requires_zones_loaded: ensures the test does not start until the specified named instances load all configured zones