Skip to content

Commit a5c807a

Browse files
committed
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>
1 parent b5a292d commit a5c807a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

test/infamy/util.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,20 @@ def parallel(*fns):
3838

3939

4040
def until(fn, attempts=10, interval=1):
41+
last_exc = None
4142
for attempt in range(attempts):
42-
result = fn()
43+
try:
44+
result = fn()
45+
except Exception as e:
46+
last_exc = e
47+
result = False
4348
if result:
4449
return result
4550

4651
time.sleep(interval)
4752

53+
if last_exc:
54+
raise last_exc
4855
raise Exception("Expected condition did not materialize")
4956

5057

@@ -119,4 +126,4 @@ def curl(url, timeout=10, silent=False):
119126
except (urllib.error.URLError, ConnectionResetError, UnicodeEncodeError, TimeoutError) as e:
120127
if not silent:
121128
print(f"[WARN] curl: failed to fetch {url}: {e}")
122-
return ""
129+
return ""

0 commit comments

Comments
 (0)