aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/test_framework/util.py')
-rw-r--r--test/functional/test_framework/util.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py
index 4098fd8615..a14cda07d0 100644
--- a/test/functional/test_framework/util.py
+++ b/test/functional/test_framework/util.py
@@ -157,6 +157,28 @@ def str_to_b64str(string):
def satoshi_round(amount):
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
+def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None):
+ if attempts == float('inf') and timeout == float('inf'):
+ timeout = 60
+ attempt = 0
+ timeout += time.time()
+
+ while attempt < attempts and time.time() < timeout:
+ if lock:
+ with lock:
+ if predicate():
+ return
+ else:
+ if predicate():
+ return
+ attempt += 1
+ time.sleep(0.05)
+
+ # Print the cause of the timeout
+ assert_greater_than(attempts, attempt)
+ assert_greater_than(timeout, time.time())
+ raise RuntimeError('Unreachable')
+
# RPC/P2P connection constants and functions
############################################