Skip to content

Commit b2da6dd

Browse files
committed
Merge bitcoin/bitcoin#26138: test: Avoid race in disconnect_nodes helper
faeea28 test: Avoid race in disconnect_nodes helper (MacroFake) Pull request description: Also wait for the other node to notice the closed socket. Otherwise, the other node is not able to use the connect helper. Fixes bitcoin/bitcoin#26014 ACKs for top commit: stickies-v: ACK faeea28 glozow: ACK faeea28 Tree-SHA512: 2f0fa6812c0519aba3eaf21f0c70073b768fcd4dad23989d57e138ee9057a7da1a6b281645e9bff4051259cdca51568700e066491ac6b6daae99f30e395159ca
2 parents 9fcdb9f + faeea28 commit b2da6dd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -596,24 +596,24 @@ def connect_nodes(self, a, b):
596596
self.wait_until(lambda: sum(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in to_connection.getpeerinfo()) == to_num_peers)
597597

598598
def disconnect_nodes(self, a, b):
599-
def disconnect_nodes_helper(from_connection, node_num):
600-
def get_peer_ids():
599+
def disconnect_nodes_helper(node_a, node_b):
600+
def get_peer_ids(from_connection, node_num):
601601
result = []
602602
for peer in from_connection.getpeerinfo():
603603
if "testnode{}".format(node_num) in peer['subver']:
604604
result.append(peer['id'])
605605
return result
606606

607-
peer_ids = get_peer_ids()
607+
peer_ids = get_peer_ids(node_a, node_b.index)
608608
if not peer_ids:
609609
self.log.warning("disconnect_nodes: {} and {} were not connected".format(
610-
from_connection.index,
611-
node_num,
610+
node_a.index,
611+
node_b.index,
612612
))
613613
return
614614
for peer_id in peer_ids:
615615
try:
616-
from_connection.disconnectnode(nodeid=peer_id)
616+
node_a.disconnectnode(nodeid=peer_id)
617617
except JSONRPCException as e:
618618
# If this node is disconnected between calculating the peer id
619619
# and issuing the disconnect, don't worry about it.
@@ -622,9 +622,10 @@ def get_peer_ids():
622622
raise
623623

624624
# wait to disconnect
625-
self.wait_until(lambda: not get_peer_ids(), timeout=5)
625+
self.wait_until(lambda: not get_peer_ids(node_a, node_b.index), timeout=5)
626+
self.wait_until(lambda: not get_peer_ids(node_b, node_a.index), timeout=5)
626627

627-
disconnect_nodes_helper(self.nodes[a], b)
628+
disconnect_nodes_helper(self.nodes[a], self.nodes[b])
628629

629630
def split_network(self):
630631
"""

0 commit comments

Comments
 (0)