]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Improve logging from isctest.run.retry_with_timeout
authorNicki Křížek <nicki@isc.org>
Fri, 6 Jun 2025 13:11:44 +0000 (15:11 +0200)
committerNicki Křížek <nicki@isc.org>
Thu, 19 Jun 2025 13:06:39 +0000 (13:06 +0000)
Allow use of exception (and by extension, assert statements) in the
called function in order to extract essential debug information about
the type of failure that was encountered.

In case the called function fails to succeed on the last retry and
raised an exception, log it as error and set it as the assert message to
propagate it through the pytest framework.

(cherry picked from commit 620c884133f1cac13efebaf381855462a123927c)

bin/tests/system/isctest/kasp.py
bin/tests/system/isctest/run.py

index 1aec27c3f5fa24f034b8d500a0451ea9fc5d5d39..501bd5f4a48148489742334b97192aedc4b14af4 100644 (file)
@@ -643,7 +643,9 @@ def check_keys(zone, keys, expected):
     def _verify_keys():
         # check number of keys matches expected.
         if len(keys) != len(expected):
-            return False
+            assert (
+                False
+            ), f"check_keys(): mismatched number of keys, expected {len(expected)}, got {len(keys)}"
 
         if len(keys) == 0:
             return True
@@ -662,7 +664,7 @@ def check_keys(zone, keys, expected):
                         expected[i].key = key
                 i += 1
             if not found:
-                return False
+                assert False, f"check_keys(): key {key} not found"
 
         return True
 
index c3b37ac0599ce40eadfc9238d0831fac63017efb..b26190e4a3d6259400a526007beb061064d6fb70 100644 (file)
@@ -127,12 +127,22 @@ def perl(script: str, args: Optional[List[str]] = None) -> None:
 
 def retry_with_timeout(func, timeout, delay=1, msg=None):
     start_time = time.time()
+    exc_msg = None
     while time.time() < start_time + timeout:
-        if func():
-            return
+        exc_msg = None
+        try:
+            if func():
+                return
+        except AssertionError as exc:
+            exc_msg = str(exc)
         time.sleep(delay)
+    if exc_msg is not None:
+        isctest.log.error(exc_msg)
     if msg is None:
-        msg = f"{func.__module__}.{func.__qualname__} timed out after {timeout} s"
+        if exc_msg is not None:
+            msg = exc_msg
+        else:
+            msg = f"{func.__module__}.{func.__qualname__} timed out after {timeout} s"
     assert False, msg