0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-06 14:19:59 -05:00

test: Avoid race in disconnect_nodes helper

This commit is contained in:
MacroFake 2022-09-20 16:00:43 +02:00
parent 9f650062fc
commit faeea28753
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -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) 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(self, a, b):
def disconnect_nodes_helper(from_connection, node_num): def disconnect_nodes_helper(node_a, node_b):
def get_peer_ids(): def get_peer_ids(from_connection, node_num):
result = [] result = []
for peer in from_connection.getpeerinfo(): for peer in from_connection.getpeerinfo():
if "testnode{}".format(node_num) in peer['subver']: if "testnode{}".format(node_num) in peer['subver']:
result.append(peer['id']) result.append(peer['id'])
return result return result
peer_ids = get_peer_ids() peer_ids = get_peer_ids(node_a, node_b.index)
if not peer_ids: if not peer_ids:
self.log.warning("disconnect_nodes: {} and {} were not connected".format( self.log.warning("disconnect_nodes: {} and {} were not connected".format(
from_connection.index, node_a.index,
node_num, node_b.index,
)) ))
return return
for peer_id in peer_ids: for peer_id in peer_ids:
try: try:
from_connection.disconnectnode(nodeid=peer_id) node_a.disconnectnode(nodeid=peer_id)
except JSONRPCException as e: except JSONRPCException as e:
# If this node is disconnected between calculating the peer id # If this node is disconnected between calculating the peer id
# and issuing the disconnect, don't worry about it. # and issuing the disconnect, don't worry about it.
@ -622,9 +622,10 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
raise raise
# wait to disconnect # 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): def split_network(self):
""" """