Skip to content

Commit 86cca2c

Browse files
stratosphertheStack
andcommitted
test: Support disconnect waiting for add_p2p_connection
Adds a new boolean parameter `expect_success` to the `add_p2p_connection` method. If set, the node under test doesn't wait for connection to be established and is useful for testing scenarios when disconnection is expected. Without this parameter, intermittent test failures can happen if the disconnection happens before wait_until for is_connected is hit inside `add_p2p_connection`. Co-Authored-By: Sebastian Falbesoner <[email protected]>
1 parent bf9669a commit 86cca2c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

test/functional/test_framework/test_node.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, mat
667667
assert_msg += "with expected error " + expected_msg
668668
self._raise_assertion_error(assert_msg)
669669

670-
def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=True, supports_v2_p2p=None, wait_for_v2_handshake=True, **kwargs):
670+
def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=True, supports_v2_p2p=None, wait_for_v2_handshake=True, expect_success=True, **kwargs):
671671
"""Add an inbound p2p connection to the node.
672672
673673
This method adds the p2p connection to the self.p2ps list and also
@@ -687,14 +687,15 @@ def add_p2p_connection(self, p2p_conn, *, wait_for_verack=True, send_version=Tru
687687
if supports_v2_p2p is None:
688688
supports_v2_p2p = self.use_v2transport
689689

690-
691690
p2p_conn.p2p_connected_to_node = True
692691
if self.use_v2transport:
693692
kwargs['services'] = kwargs.get('services', P2P_SERVICES) | NODE_P2P_V2
694693
supports_v2_p2p = self.use_v2transport and supports_v2_p2p
695694
p2p_conn.peer_connect(**kwargs, send_version=send_version, net=self.chain, timeout_factor=self.timeout_factor, supports_v2_p2p=supports_v2_p2p)()
696695

697696
self.p2ps.append(p2p_conn)
697+
if not expect_success:
698+
return p2p_conn
698699
p2p_conn.wait_until(lambda: p2p_conn.is_connected, check_connected=False)
699700
if supports_v2_p2p and wait_for_v2_handshake:
700701
p2p_conn.wait_until(lambda: p2p_conn.v2_state.tried_v2_handshake)

0 commit comments

Comments
 (0)