mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 03:03:22 -03:00
Merge bitcoin/bitcoin#26197: [24.x] test: Avoid race in disconnect_nodes helper
faeea28753
test: Avoid race in disconnect_nodes helper (MacroFake) Pull request description: Backport of https://github.com/bitcoin/bitcoin/pull/26138 ACKs for top commit: fanquake: ACKfaeea28753
Tree-SHA512: f967c38750220bd6c245db953055f8e6d5402b3a24081ca03795a8403c2ed4eab772b2e9c2d3b581c3bc55d191dd4e22711b5f97d39856d676f10799fc64a9c7
This commit is contained in:
commit
f34c98a460
1 changed files with 9 additions and 8 deletions
|
@ -596,24 +596,24 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
self.wait_until(lambda: sum(peer['bytesrecv_per_msg'].pop('verack', 0) == 24 for peer in to_connection.getpeerinfo()) == to_num_peers)
|
||||
|
||||
def disconnect_nodes(self, a, b):
|
||||
def disconnect_nodes_helper(from_connection, node_num):
|
||||
def get_peer_ids():
|
||||
def disconnect_nodes_helper(node_a, node_b):
|
||||
def get_peer_ids(from_connection, node_num):
|
||||
result = []
|
||||
for peer in from_connection.getpeerinfo():
|
||||
if "testnode{}".format(node_num) in peer['subver']:
|
||||
result.append(peer['id'])
|
||||
return result
|
||||
|
||||
peer_ids = get_peer_ids()
|
||||
peer_ids = get_peer_ids(node_a, node_b.index)
|
||||
if not peer_ids:
|
||||
self.log.warning("disconnect_nodes: {} and {} were not connected".format(
|
||||
from_connection.index,
|
||||
node_num,
|
||||
node_a.index,
|
||||
node_b.index,
|
||||
))
|
||||
return
|
||||
for peer_id in peer_ids:
|
||||
try:
|
||||
from_connection.disconnectnode(nodeid=peer_id)
|
||||
node_a.disconnectnode(nodeid=peer_id)
|
||||
except JSONRPCException as e:
|
||||
# If this node is disconnected between calculating the peer id
|
||||
# and issuing the disconnect, don't worry about it.
|
||||
|
@ -622,9 +622,10 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
|||
raise
|
||||
|
||||
# wait to disconnect
|
||||
self.wait_until(lambda: not get_peer_ids(), timeout=5)
|
||||
self.wait_until(lambda: not get_peer_ids(node_a, node_b.index), timeout=5)
|
||||
self.wait_until(lambda: not get_peer_ids(node_b, node_a.index), timeout=5)
|
||||
|
||||
disconnect_nodes_helper(self.nodes[a], b)
|
||||
disconnect_nodes_helper(self.nodes[a], self.nodes[b])
|
||||
|
||||
def split_network(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue