test/infamy: make until() exception-safe

Any exception raised by fn() propagated immediately out of the retry
loop, effectively making until() a single-shot call the moment any
transient error occurred.

Fix by wrapping fn() in a try/except inside the loop and treating any
exception as a "not yet" result.  The last exception is preserved and
re-raised if all attempts are exhausted, so failure output is still
meaningful.  Also fix a missing newline at end of file.

Fixes #1403

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-02-26 19:05:43 +01:00
parent b5a292d7dd
commit a5c807abe0
+9 -2
View File
@@ -38,13 +38,20 @@ def parallel(*fns):
def until(fn, attempts=10, interval=1):
last_exc = None
for attempt in range(attempts):
result = fn()
try:
result = fn()
except Exception as e:
last_exc = e
result = False
if result:
return result
time.sleep(interval)
if last_exc:
raise last_exc
raise Exception("Expected condition did not materialize")
@@ -119,4 +126,4 @@ def curl(url, timeout=10, silent=False):
except (urllib.error.URLError, ConnectionResetError, UnicodeEncodeError, TimeoutError) as e:
if not silent:
print(f"[WARN] curl: failed to fetch {url}: {e}")
return ""
return ""