Skip to content

Commit 9642aef

Browse files
committed
test: fix intermittent failure in p2p_v2_earlykeyresponse
This fixes a possible race between the python NetworkThread and the actual test, which will both call initiate_v2_handshake.
1 parent cad2df2 commit 9642aef

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

test/functional/p2p_v2_earlykeyresponse.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class PeerEarlyKey(P2PInterface):
4949
def __init__(self):
5050
super().__init__()
5151
self.v2_state = None
52+
self.connection_opened = False
5253

5354
def connection_made(self, transport):
5455
"""64 bytes ellswift is sent in 2 parts during `initial_v2_handshake()`"""
@@ -59,6 +60,8 @@ def data_received(self, t):
5960
# check that data can be received on recvbuf only when mismatch from V1_PREFIX happens (send_net_magic = False)
6061
assert self.v2_state.can_data_be_received and not self.v2_state.send_net_magic
6162

63+
def on_open(self):
64+
self.connection_opened = True
6265

6366
class P2PEarlyKey(BitcoinTestFramework):
6467
def set_test_params(self):
@@ -73,6 +76,7 @@ def run_test(self):
7376
self.log.info('If a response is received, assertion failure would happen in our custom data_received() function')
7477
# send happens in `initiate_v2_handshake()` in `connection_made()`
7578
peer1 = node0.add_p2p_connection(PeerEarlyKey(), wait_for_verack=False, send_version=False, supports_v2_p2p=True)
79+
self.wait_until(lambda: peer1.connection_opened)
7680
self.log.info('Sending remaining ellswift and garbage which are different from V1_PREFIX. Since a response is')
7781
self.log.info('expected now, our custom data_received() function wouldn\'t result in assertion failure')
7882
ellswift_and_garbage_data = peer1.v2_state.initiate_v2_handshake()

0 commit comments

Comments
 (0)