Skip to content

Commit 4af01b3

Browse files
committed
Merge #19060: test: Remove global wait_until from p2p_getdata
fa80b47 test: Remove global wait_until from p2p_getdata (MarcoFalke) 999922b test: Default mininode.wait_until timeout to 60s (MarcoFalke) fab4737 test: pep-8 p2p_getdata.py (MarcoFalke) Pull request description: Using the global wait_until makes it impossible to adjust the timeout based on the hardware the test is running on. Fix that by using the mininode member function. So for example, `./test/functional/p2p_getdata.py --timeout-factor=0.04` gives a timeout of 2.4 seconds. ACKs for top commit: laanwj: ACK fa80b47 Tree-SHA512: ebb1b7860a64451de2b8ee9a0966faddb13b84af711f6744e8260d7c9bc0b382e8fb259897df5212190821e850ed30d4d5c2d7af45a97f207fd4511b06b6674a
2 parents dcacea0 + fa80b47 commit 4af01b3

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

test/functional/p2p_getdata.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
CInv,
1010
msg_getdata,
1111
)
12-
from test_framework.mininode import (
13-
mininode_lock,
14-
P2PInterface,
15-
)
12+
from test_framework.mininode import P2PInterface
1613
from test_framework.test_framework import BitcoinTestFramework
17-
from test_framework.util import wait_until
1814

19-
class P2PStoreBlock(P2PInterface):
2015

16+
class P2PStoreBlock(P2PInterface):
2117
def __init__(self):
2218
super().__init__()
2319
self.blocks = defaultdict(int)
@@ -26,26 +22,28 @@ def on_block(self, message):
2622
message.block.calc_sha256()
2723
self.blocks[message.block.sha256] += 1
2824

25+
2926
class GetdataTest(BitcoinTestFramework):
3027
def set_test_params(self):
3128
self.num_nodes = 1
3229

3330
def run_test(self):
34-
self.nodes[0].add_p2p_connection(P2PStoreBlock())
31+
p2p_block_store = self.nodes[0].add_p2p_connection(P2PStoreBlock())
3532

3633
self.log.info("test that an invalid GETDATA doesn't prevent processing of future messages")
3734

3835
# Send invalid message and verify that node responds to later ping
3936
invalid_getdata = msg_getdata()
4037
invalid_getdata.inv.append(CInv(t=0, h=0)) # INV type 0 is invalid.
41-
self.nodes[0].p2ps[0].send_and_ping(invalid_getdata)
38+
p2p_block_store.send_and_ping(invalid_getdata)
4239

4340
# Check getdata still works by fetching tip block
4441
best_block = int(self.nodes[0].getbestblockhash(), 16)
4542
good_getdata = msg_getdata()
4643
good_getdata.inv.append(CInv(t=2, h=best_block))
47-
self.nodes[0].p2ps[0].send_and_ping(good_getdata)
48-
wait_until(lambda: self.nodes[0].p2ps[0].blocks[best_block] == 1, timeout=30, lock=mininode_lock)
44+
p2p_block_store.send_and_ping(good_getdata)
45+
p2p_block_store.wait_until(lambda: self.nodes[0].p2ps[0].blocks[best_block] == 1)
46+
4947

5048
if __name__ == '__main__':
5149
GetdataTest().main()

test/functional/test_framework/mininode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def on_version(self, message):
374374

375375
# Connection helper methods
376376

377-
def wait_until(self, test_function, timeout):
377+
def wait_until(self, test_function, timeout=60):
378378
wait_until(test_function, timeout=timeout, lock=mininode_lock, timeout_factor=self.timeout_factor)
379379

380380
def wait_for_disconnect(self, timeout=60):

0 commit comments

Comments
 (0)