Skip to content

Commit 1d8a5f0

Browse files
committed
Merge bitcoin/bitcoin#29750: test: makes timeout a forced named argument in tests methods that use it
61560d5 test: makes timeout a forced named argument in tests methods that use it (Sergi Delgado Segura) Pull request description: This makes calls to such methods more explicit and less error-prone. Motivated by bitcoin/bitcoin#29736 (comment) ACKs for top commit: maflcko: lgtm ACK 61560d5 brunoerg: ACK 61560d5 BrandonOdiwuor: crACK 61560d5 AngusP: ACK 61560d5 stratospher: tested ACK 61560d5. Tree-SHA512: 8d6ec3fe1076c868ddbd3050f3c242dbd83cc123f560db3d3b0ed74968e6050dc9ebf4e7c716af9cc1b290c97d736c2fc2ac936b0b69ebdbceed934dae7d55d9
2 parents 23ba394 + 61560d5 commit 1d8a5f0

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

test/functional/feature_assumevalid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def run_test(self):
159159
for i in range(2202):
160160
p2p1.send_message(msg_block(self.blocks[i]))
161161
# Syncing 2200 blocks can take a while on slow systems. Give it plenty of time to sync.
162-
p2p1.sync_with_ping(960)
162+
p2p1.sync_with_ping(timeout=960)
163163
assert_equal(self.nodes[1].getblock(self.nodes[1].getbestblockhash())['height'], 2202)
164164

165165
p2p2 = self.nodes[2].add_p2p_connection(BaseNode())

test/functional/p2p_compactblocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def send_await_disconnect(self, message, timeout=30):
139139
This is used when we want to send a message into the node that we expect
140140
will get us disconnected, eg an invalid block."""
141141
self.send_message(message)
142-
self.wait_for_disconnect(timeout)
142+
self.wait_for_disconnect(timeout=timeout)
143143

144144
class CompactBlocksTest(BitcoinTestFramework):
145145
def set_test_params(self):

test/functional/p2p_node_network_limited.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def run_test(self):
138138

139139
self.log.info("Requesting block at height 2 (tip-289) must fail (ignored).")
140140
node.send_getdata_for_block(blocks[0]) # first block outside of the 288+2 limit
141-
node.wait_for_disconnect(5)
141+
node.wait_for_disconnect(timeout=5)
142142
self.nodes[0].disconnect_p2ps()
143143

144144
# connect unsynced node 2 with pruned NODE_NETWORK_LIMITED peer

test/functional/p2p_segwit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ def announce_block_and_wait_for_getdata(self, block, use_header, timeout=60):
198198
self.send_message(msg)
199199
else:
200200
self.send_message(msg_inv(inv=[CInv(MSG_BLOCK, block.sha256)]))
201-
self.wait_for_getheaders()
201+
self.wait_for_getheaders(timeout=timeout)
202202
self.send_message(msg)
203-
self.wait_for_getdata([block.sha256])
203+
self.wait_for_getdata([block.sha256], timeout=timeout)
204204

205205
def request_block(self, blockhash, inv_type, timeout=60):
206206
with p2p_lock:
207207
self.last_message.pop("block", None)
208208
self.send_message(msg_getdata(inv=[CInv(inv_type, blockhash)]))
209-
self.wait_for_block(blockhash, timeout)
209+
self.wait_for_block(blockhash, timeout=timeout)
210210
return self.last_message["block"].block
211211

212212
class SegWitTest(BitcoinTestFramework):
@@ -2056,7 +2056,7 @@ def received_wtxidrelay():
20562056
test_transaction_acceptance(self.nodes[0], self.wtx_node, tx2, with_witness=True, accepted=False)
20572057

20582058
# Expect a request for parent (tx) by txid despite use of WTX peer
2059-
self.wtx_node.wait_for_getdata([tx.sha256], 60)
2059+
self.wtx_node.wait_for_getdata([tx.sha256], timeout=60)
20602060
with p2p_lock:
20612061
lgd = self.wtx_node.lastgetdata[:]
20622062
assert_equal(lgd, [CInv(MSG_WITNESS_TX, tx.sha256)])

test/functional/test_framework/p2p.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -585,36 +585,36 @@ def test_function():
585585

586586
wait_until_helper_internal(test_function, timeout=timeout, lock=p2p_lock, timeout_factor=self.timeout_factor)
587587

588-
def wait_for_connect(self, timeout=60):
588+
def wait_for_connect(self, *, timeout=60):
589589
test_function = lambda: self.is_connected
590590
self.wait_until(test_function, timeout=timeout, check_connected=False)
591591

592-
def wait_for_disconnect(self, timeout=60):
592+
def wait_for_disconnect(self, *, timeout=60):
593593
test_function = lambda: not self.is_connected
594594
self.wait_until(test_function, timeout=timeout, check_connected=False)
595595

596-
def wait_for_reconnect(self, timeout=60):
596+
def wait_for_reconnect(self, *, timeout=60):
597597
def test_function():
598598
return self.is_connected and self.last_message.get('version') and not self.supports_v2_p2p
599599
self.wait_until(test_function, timeout=timeout, check_connected=False)
600600

601601
# Message receiving helper methods
602602

603-
def wait_for_tx(self, txid, timeout=60):
603+
def wait_for_tx(self, txid, *, timeout=60):
604604
def test_function():
605605
if not self.last_message.get('tx'):
606606
return False
607607
return self.last_message['tx'].tx.rehash() == txid
608608

609609
self.wait_until(test_function, timeout=timeout)
610610

611-
def wait_for_block(self, blockhash, timeout=60):
611+
def wait_for_block(self, blockhash, *, timeout=60):
612612
def test_function():
613613
return self.last_message.get("block") and self.last_message["block"].block.rehash() == blockhash
614614

615615
self.wait_until(test_function, timeout=timeout)
616616

617-
def wait_for_header(self, blockhash, timeout=60):
617+
def wait_for_header(self, blockhash, *, timeout=60):
618618
def test_function():
619619
last_headers = self.last_message.get('headers')
620620
if not last_headers:
@@ -623,7 +623,7 @@ def test_function():
623623

624624
self.wait_until(test_function, timeout=timeout)
625625

626-
def wait_for_merkleblock(self, blockhash, timeout=60):
626+
def wait_for_merkleblock(self, blockhash, *, timeout=60):
627627
def test_function():
628628
last_filtered_block = self.last_message.get('merkleblock')
629629
if not last_filtered_block:
@@ -632,7 +632,7 @@ def test_function():
632632

633633
self.wait_until(test_function, timeout=timeout)
634634

635-
def wait_for_getdata(self, hash_list, timeout=60):
635+
def wait_for_getdata(self, hash_list, *, timeout=60):
636636
"""Waits for a getdata message.
637637
638638
The object hashes in the inventory vector must match the provided hash_list."""
@@ -644,7 +644,7 @@ def test_function():
644644

645645
self.wait_until(test_function, timeout=timeout)
646646

647-
def wait_for_getheaders(self, timeout=60):
647+
def wait_for_getheaders(self, *, timeout=60):
648648
"""Waits for a getheaders message.
649649
650650
Receiving any getheaders message will satisfy the predicate. the last_message["getheaders"]
@@ -656,7 +656,7 @@ def test_function():
656656

657657
self.wait_until(test_function, timeout=timeout)
658658

659-
def wait_for_inv(self, expected_inv, timeout=60):
659+
def wait_for_inv(self, expected_inv, *, timeout=60):
660660
"""Waits for an INV message and checks that the first inv object in the message was as expected."""
661661
if len(expected_inv) > 1:
662662
raise NotImplementedError("wait_for_inv() will only verify the first inv object")
@@ -668,7 +668,7 @@ def test_function():
668668

669669
self.wait_until(test_function, timeout=timeout)
670670

671-
def wait_for_verack(self, timeout=60):
671+
def wait_for_verack(self, *, timeout=60):
672672
def test_function():
673673
return "verack" in self.last_message
674674

@@ -681,11 +681,11 @@ def send_version(self):
681681
self.send_message(self.on_connection_send_msg)
682682
self.on_connection_send_msg = None # Never used again
683683

684-
def send_and_ping(self, message, timeout=60):
684+
def send_and_ping(self, message, *, timeout=60):
685685
self.send_message(message)
686686
self.sync_with_ping(timeout=timeout)
687687

688-
def sync_with_ping(self, timeout=60):
688+
def sync_with_ping(self, *, timeout=60):
689689
"""Ensure ProcessMessages and SendMessages is called on this connection"""
690690
# Sending two pings back-to-back, requires that the node calls
691691
# `ProcessMessage` twice, and thus ensures `SendMessages` must have
@@ -726,7 +726,7 @@ def run(self):
726726
"""Start the network thread."""
727727
self.network_event_loop.run_forever()
728728

729-
def close(self, timeout=10):
729+
def close(self, *, timeout=10):
730730
"""Close the connections and network event loop."""
731731
self.network_event_loop.call_soon_threadsafe(self.network_event_loop.stop)
732732
wait_until_helper_internal(lambda: not self.network_event_loop.is_running(), timeout=timeout)
@@ -933,7 +933,7 @@ def get_invs(self):
933933
with p2p_lock:
934934
return list(self.tx_invs_received.keys())
935935

936-
def wait_for_broadcast(self, txns, timeout=60):
936+
def wait_for_broadcast(self, txns, *, timeout=60):
937937
"""Waits for the txns (list of txids) to complete initial broadcast.
938938
The mempool should mark unbroadcast=False for these transactions.
939939
"""

0 commit comments

Comments
 (0)