]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add wait_for_zones_loaded fixture
authorMichał Kępień <michal@isc.org>
Tue, 19 Dec 2023 14:58:36 +0000 (15:58 +0100)
committerMichał Kępień <michal@isc.org>
Fri, 22 Dec 2023 14:02:58 +0000 (15:02 +0100)
The wait_for_zones_loaded fixture waits for the "all zones loaded"
message in the named log file before the test function can proceed.

bin/tests/system/conftest.py
bin/tests/system/pytest.ini

index 89b399eb4cd9487723d0cf9a3b228374c5646f10..671a36395c1a6ceb3521eebdd64f6a36f172d0f0 100644 (file)
@@ -356,6 +356,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."""
index 1559595852d3f79843d15a25d7533703769c0e55..a8733cefb6b2237870a41bd2db4c4b6612a38695 100644 (file)
@@ -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