1 | | A possible pattern for fixing issues like this would be to keep retrying the assertion in a `while` loop, with a small sleep in between each attempt, and a relatively large cumulative amount of time before giving up. That would make it as pass as quickly as possible, without waiting longer than necessary. |
| 1 | A possible pattern for fixing issues like this would be to keep retrying the assertion in a `while` loop, with a small sleep in between each attempt, and a relatively large cumulative amount of time before giving up. That would make it as pass as quickly as possible, without waiting longer than necessary. I'm thinking something like-- |
| 2 | |
| 3 | {{{#!python |
| 4 | def assert_with_retries(self, assert_func, interval_time, total_time, *args, **kwargs): |
| 5 | start = time.time() |
| 6 | while True: |
| 7 | try: |
| 8 | assert_func(*args, **kwargs) |
| 9 | except Exception as exc: |
| 10 | if time.time() - start > total_time: |
| 11 | raise RuntimeError(f'Total retry time exceeded.') from exc |
| 12 | else: |
| 13 | break |
| 14 | time.sleep(interval_time) |
| 15 | }}} |