Skip to content

Commit 5e4fed9

Browse files
committed
Merge #19657: test: Wait until is_connected in add_p2p_connection
fa4dfd2 test: Wait until is_connected in add_p2p_connection (MarcoFalke) Pull request description: Moving the wait_until from the individual test scripts to the test framework simplifies two tests ACKs for top commit: jnewbery: Code review ACK fa4dfd2 theStack: ACK bitcoin/bitcoin@fa4dfd2 ☕ Tree-SHA512: 36eda7eb323614a4c4f9215f1d7b40b9f9c4036d1c08eb701ea705f3e2986fdabd2fc558965a6aadabeed861034aeaeef3c00f968ca17ed7a27e42e506cda87d
2 parents 214e665 + fa4dfd2 commit 5e4fed9

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

test/functional/p2p_filter.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,6 @@ def run_test(self):
218218
# Add peer but do not send version yet
219219
filter_peer_without_nrelay = self.nodes[0].add_p2p_connection(P2PBloomFilter(), send_version=False, wait_for_verack=False)
220220
# Send version with fRelay=False
221-
filter_peer_without_nrelay.wait_until(
222-
lambda: filter_peer_without_nrelay.is_connected,
223-
timeout=10,
224-
check_connected=False,
225-
)
226221
version_without_fRelay = msg_version()
227222
version_without_fRelay.nRelay = 0
228223
filter_peer_without_nrelay.send_message(version_without_fRelay)

test/functional/p2p_leak.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,20 @@ def on_cmpctblock(self, message): self.bad_message(message)
6363
def on_getblocktxn(self, message): self.bad_message(message)
6464
def on_blocktxn(self, message): self.bad_message(message)
6565

66+
6667
# Node that never sends a version. We'll use this to send a bunch of messages
6768
# anyway, and eventually get disconnected.
6869
class CNodeNoVersionMisbehavior(CLazyNode):
69-
# Send enough veracks without a message to reach the peer discouragement
70-
# threshold. This should get us disconnected. NOTE: implementation-specific
71-
# test; update if our discouragement policy for peer misbehavior changes.
72-
def on_open(self):
73-
super().on_open()
74-
for _ in range(DISCOURAGEMENT_THRESHOLD):
75-
self.send_message(msg_verack())
70+
pass
71+
7672

7773
# Node that never sends a version. This one just sits idle and hopes to receive
7874
# any message (it shouldn't!)
7975
class CNodeNoVersionIdle(CLazyNode):
8076
def __init__(self):
8177
super().__init__()
8278

79+
8380
# Node that sends a version but not a verack.
8481
class CNodeNoVerackIdle(CLazyNode):
8582
def __init__(self):
@@ -114,6 +111,11 @@ def run_test(self):
114111
no_version_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVersionIdle(), send_version=False, wait_for_verack=False)
115112
no_verack_idlenode = self.nodes[0].add_p2p_connection(CNodeNoVerackIdle(), wait_for_verack=False)
116113

114+
# Send enough veracks without a message to reach the peer discouragement
115+
# threshold. This should get us disconnected.
116+
for _ in range(DISCOURAGEMENT_THRESHOLD):
117+
no_version_disconnect_node.send_message(msg_verack())
118+
117119
# Wait until we got the verack in response to the version. Though, don't wait for the other node to receive the
118120
# verack, since we never sent one
119121
no_verack_idlenode.wait_for_verack()
@@ -153,7 +155,6 @@ def run_test(self):
153155
p2p_old_node = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
154156
old_version_msg = msg_version()
155157
old_version_msg.nVersion = 31799
156-
wait_until(lambda: p2p_old_node.is_connected)
157158
with self.nodes[0].assert_debug_log(['peer=4 using obsolete version 31799; disconnecting']):
158159
p2p_old_node.send_message(old_version_msg)
159160
p2p_old_node.wait_for_disconnect()

test/functional/test_framework/mininode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def wait_for_verack(self, timeout=60):
474474
def test_function():
475475
return "verack" in self.last_message
476476

477-
self.wait_until(test_function, timeout=timeout, check_connected=False)
477+
self.wait_until(test_function, timeout=timeout)
478478

479479
# Message sending helper functions
480480

test/functional/test_framework/test_node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, **kwargs):
524524

525525
p2p_conn.peer_connect(**kwargs, net=self.chain, timeout_factor=self.timeout_factor)()
526526
self.p2ps.append(p2p_conn)
527+
p2p_conn.wait_until(lambda: p2p_conn.is_connected, check_connected=False)
527528
if wait_for_verack:
528529
# Wait for the node to send us the version and verack
529530
p2p_conn.wait_for_verack()

0 commit comments

Comments
 (0)