]> 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:18:32 +0000 (15:18 +0200)
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/run.py

index 8430981e93cee9b179e08288644b213e35227e7c..820cbe3ba9ead8d5986846cfa2484af10d693a51 100644 (file)
@@ -84,12 +84,22 @@ class Dig:
 
 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