MCPcopy Create free account
hub / github.com/ElementsProject/elements / wait_until_helper

Function wait_until_helper

test/functional/test_framework/util.py:256–289  ·  view source on GitHub ↗

Sleep until the predicate resolves to be True. Warning: Note that this method is not recommended to be used in tests as it is not aware of the context of the test framework. Using the `wait_until()` members from `BitcoinTestFramework` or `P2PInterface` class ensures the timeout is p

(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0)

Source from the content-addressed store, hash-verified

254
255
256def wait_until_helper(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0):
257 """Sleep until the predicate resolves to be True.
258
259 Warning: Note that this method is not recommended to be used in tests as it is
260 not aware of the context of the test framework. Using the `wait_until()` members
261 from `BitcoinTestFramework` or `P2PInterface` class ensures the timeout is
262 properly scaled. Furthermore, `wait_until()` from `P2PInterface` class in
263 `p2p.py` has a preset lock.
264 """
265 if attempts == float('inf') and timeout == float('inf'):
266 timeout = 60
267 timeout = timeout * timeout_factor
268 attempt = 0
269 time_end = time.time() + timeout
270
271 while attempt < attempts and time.time() < time_end:
272 if lock:
273 with lock:
274 if predicate():
275 return
276 else:
277 if predicate():
278 return
279 attempt += 1
280 time.sleep(0.05)
281
282 # Print the cause of the timeout
283 predicate_source = "''''\n" + inspect.getsource(predicate) + "'''"
284 logger.error("wait_until() failed. Predicate: {}".format(predicate_source))
285 if attempt >= attempts:
286 raise AssertionError("Predicate {} not true after {} attempts".format(predicate_source, attempts))
287 elif time.time() >= time_end:
288 raise AssertionError("Predicate {} not true after {} seconds".format(predicate_source, timeout))
289 raise RuntimeError('Unreachable')
290
291
292def sha256sum_file(filename):

Callers 9

wait_untilMethod · 0.90
wait_for_connectMethod · 0.90
closeMethod · 0.90
connect_nodesMethod · 0.85
wait_untilMethod · 0.85
wait_until_stoppedMethod · 0.85
disconnect_p2psMethod · 0.85

Calls 1

formatMethod · 0.80

Tested by 6

connect_nodesMethod · 0.68
wait_untilMethod · 0.68
wait_until_stoppedMethod · 0.68
disconnect_p2psMethod · 0.68