Skip to content

Commit

Permalink
munet: fix retry expected failure case
Browse files Browse the repository at this point in the history
Also try and pass `seconds_left` to the retried function, if not
handled (exception raised) call function again w/o arg. This allows
the called function to differ (e.g., log at different levels) if it
will be retrying or not.

Signed-off-by: Christian Hopps <chopps@labn.net>
  • Loading branch information
choppsv1 committed Sep 8, 2024
1 parent 6d088c1 commit 52652f1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions munet/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,21 @@ def func_retry(*args, **kwargs):
while True:
seconds_left = (retry_until - datetime.datetime.now()).total_seconds()
try:
ret = func(*args, **kwargs)
if _expected and ret is None:
try:
ret = func(*args, seconds_left=seconds_left, **kwargs)
except TypeError as error:
if "seconds_left" not in str(error):
raise
ret = func(*args, **kwargs)

logging.debug("Function returned %s", ret)

positive_result = ret is None
if _expected == positive_result:
logging.debug("Function succeeds")
return ret
logging.debug("Function returned %s", ret)
except Exception as error:
logging.info("Function raised exception: %s", str(error))
logging.info('Function raised exception: "%s"', error)
ret = error

if seconds_left < 0:
Expand Down

0 comments on commit 52652f1

Please sign in to comment.