aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/util.py
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2017-08-16 18:17:34 +0200
committerMarcoFalke <falke.marco@gmail.com>2017-08-17 15:17:09 +0200
commit08ce33f8e95efa81b37ddc6b3350462c61bbfd51 (patch)
tree6aba3f369154013dc943169a89320fb8364af1a6 /test/functional/test_framework/util.py
parent22e301a3d56dc9e6878380ee92c7d19ca43119d2 (diff)
downloadbitcoin-08ce33f8e95efa81b37ddc6b3350462c61bbfd51.tar.xz
qa: Move wait_until to util
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
############################################