Wait up to 10 seconds (by default) for predicate to be true. E.g.: wait_until(lambda: client.primary == ('a', 1), 'connect to the primary') If the lambda-expression isn't true after 10 seconds, we raise AssertionError("Didn't ever connect to the primary").
(predicate, success_description, timeout=10)
| 55 | |
| 56 | |
| 57 | def wait_until(predicate, success_description, timeout=10): |
| 58 | """Wait up to 10 seconds (by default) for predicate to be true. |
| 59 | |
| 60 | E.g.: |
| 61 | |
| 62 | wait_until(lambda: client.primary == ('a', 1), |
| 63 | 'connect to the primary') |
| 64 | |
| 65 | If the lambda-expression isn't true after 10 seconds, we raise |
| 66 | AssertionError("Didn't ever connect to the primary"). |
| 67 | |
| 68 | Returns the predicate's first true value. |
| 69 | """ |
| 70 | start = time.time() |
| 71 | interval = min(float(timeout) / 100, 0.1) |
| 72 | while True: |
| 73 | if iscoroutinefunction(predicate): |
| 74 | retval = predicate() |
| 75 | else: |
| 76 | retval = predicate() |
| 77 | if retval: |
| 78 | return retval |
| 79 | |
| 80 | if time.time() - start > timeout: |
| 81 | raise AssertionError("Didn't ever %s" % success_description) |
| 82 | |
| 83 | time.sleep(interval) |
| 84 | |
| 85 | |
| 86 | def is_mongos(client): |