mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
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:
+9
-2
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user