Skip to content

Commit fad2794

Browse files
author
MarcoFalke
committed
test: Rename wait until helper to wait_until_helper
1 parent facb41b commit fad2794

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

test/functional/example_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ def run_test(self):
207207
self.log.info("Check that each block was received only once")
208208
# The network thread uses a global lock on data access to the P2PConnection objects when sending and receiving
209209
# messages. The test thread should acquire the global lock before accessing any P2PConnection data to avoid locking
210-
# and synchronization issues. Note wait_until() acquires this global lock when testing the predicate.
210+
# and synchronization issues. Note p2p.wait_until() acquires this global lock internally when testing the predicate.
211211
with p2p_lock:
212212
for block in self.nodes[2].p2p.block_receive_map.values():
213213
assert_equal(block, 1)
214214

215+
215216
if __name__ == '__main__':
216217
ExampleTest().main()

test/functional/test_framework/p2p.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
NODE_WITNESS,
7070
sha256,
7171
)
72-
from test_framework.util import wait_until
72+
from test_framework.util import wait_until_helper
7373

7474
logger = logging.getLogger("TestFramework.p2p")
7575

@@ -293,7 +293,7 @@ def __init__(self):
293293

294294
# Track the most recent message of each type.
295295
# To wait for a message to be received, pop that message from
296-
# this and use wait_until.
296+
# this and use self.wait_until.
297297
self.last_message = {}
298298

299299
# A count of the number of ping messages we've sent to the node
@@ -398,7 +398,7 @@ def test_function():
398398
assert self.is_connected
399399
return test_function_in()
400400

401-
wait_until(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor)
401+
wait_until_helper(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor)
402402

403403
def wait_for_disconnect(self, timeout=60):
404404
test_function = lambda: not self.is_connected
@@ -522,7 +522,7 @@ def run(self):
522522
def close(self, timeout=10):
523523
"""Close the connections and network event loop."""
524524
self.network_event_loop.call_soon_threadsafe(self.network_event_loop.stop)
525-
wait_until(lambda: not self.network_event_loop.is_running(), timeout=timeout)
525+
wait_until_helper(lambda: not self.network_event_loop.is_running(), timeout=timeout)
526526
self.network_event_loop.close()
527527
self.join(timeout)
528528
# Safe to remove event loop.

test/functional/test_framework/test_framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
disconnect_nodes,
3232
get_datadir_path,
3333
initialize_datadir,
34-
wait_until,
34+
wait_until_helper,
3535
)
3636

3737

@@ -604,7 +604,7 @@ def sync_all(self, nodes=None):
604604
self.sync_mempools(nodes)
605605

606606
def wait_until(self, test_function, timeout=60, lock=None):
607-
return wait_until(test_function, timeout=timeout, lock=lock, timeout_factor=self.options.timeout_factor)
607+
return wait_until_helper(test_function, timeout=timeout, lock=lock, timeout_factor=self.options.timeout_factor)
608608

609609
# Private helper methods. These should not be accessed by the subclass test scripts.
610610

test/functional/test_framework/test_node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
get_auth_cookie,
3232
get_rpc_proxy,
3333
rpc_url,
34-
wait_until,
34+
wait_until_helper,
3535
p2p_port,
3636
EncodeDecimal,
3737
)
@@ -231,7 +231,7 @@ def wait_for_rpc_connection(self):
231231
if self.version_is_at_least(190000):
232232
# getmempoolinfo.loaded is available since commit
233233
# bb8ae2c (version 0.19.0)
234-
wait_until(lambda: rpc.getmempoolinfo()['loaded'])
234+
wait_until_helper(lambda: rpc.getmempoolinfo()['loaded'], timeout_factor=self.timeout_factor)
235235
# Wait for the node to finish reindex, block import, and
236236
# loading the mempool. Usually importing happens fast or
237237
# even "immediate" when the node is started. However, there
@@ -359,7 +359,7 @@ def is_node_stopped(self):
359359
return True
360360

361361
def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):
362-
wait_until(self.is_node_stopped, timeout=timeout, timeout_factor=self.timeout_factor)
362+
wait_until_helper(self.is_node_stopped, timeout=timeout, timeout_factor=self.timeout_factor)
363363

364364
@contextlib.contextmanager
365365
def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2):
@@ -560,7 +560,7 @@ def disconnect_p2ps(self):
560560
for p in self.p2ps:
561561
p.peer_disconnect()
562562
del self.p2ps[:]
563-
wait_until(lambda: self.num_test_p2p_connections() == 0)
563+
wait_until_helper(lambda: self.num_test_p2p_connections() == 0, timeout_factor=self.timeout_factor)
564564

565565

566566
class TestNodeCLIAttr:

test/functional/test_framework/util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ def satoshi_round(amount):
225225
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
226226

227227

228-
def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0):
228+
def wait_until_helper(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None, timeout_factor=1.0):
229229
"""Sleep until the predicate resolves to be True.
230230
231231
Warning: Note that this method is not recommended to be used in tests as it is
232-
not aware of the context of the test framework. Using `wait_until()` counterpart
233-
from `BitcoinTestFramework` or `P2PInterface` class ensures an understandable
234-
amount of timeout and a common shared timeout_factor. Furthermore, `wait_until()`
235-
from `P2PInterface` class in `mininode.py` has a preset lock.
232+
not aware of the context of the test framework. Using the `wait_until()` members
233+
from `BitcoinTestFramework` or `P2PInterface` class ensures the timeout is
234+
properly scaled. Furthermore, `wait_until()` from `P2PInterface` class in
235+
`p2p.py` has a preset lock.
236236
"""
237237
if attempts == float('inf') and timeout == float('inf'):
238238
timeout = 60
@@ -437,7 +437,7 @@ def get_peer_ids():
437437
raise
438438

439439
# wait to disconnect
440-
wait_until(lambda: not get_peer_ids(), timeout=5)
440+
wait_until_helper(lambda: not get_peer_ids(), timeout=5)
441441

442442

443443
def connect_nodes(from_connection, node_num):
@@ -448,8 +448,8 @@ def connect_nodes(from_connection, node_num):
448448
# See comments in net_processing:
449449
# * Must have a version message before anything else
450450
# * Must have a verack message before anything else
451-
wait_until(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo()))
452-
wait_until(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo()))
451+
wait_until_helper(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo()))
452+
wait_until_helper(lambda: all(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in from_connection.getpeerinfo()))
453453

454454

455455
# Transaction/Block functions

0 commit comments

Comments
 (0)