Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/util.py
Show First 20 Lines • Show All 414 Lines • ▼ Show 20 Lines | |||||
def set_node_times(nodes, t): | def set_node_times(nodes, t): | ||||
for node in nodes: | for node in nodes: | ||||
node.setmocktime(t) | node.setmocktime(t) | ||||
def disconnect_nodes(from_node, to_node): | def disconnect_nodes(from_node, to_node): | ||||
for peer_id in [peer['id'] for peer in from_node.getpeerinfo( | def get_peer_ids(): | ||||
) if to_node.name in peer['subver']]: | result = [] | ||||
for peer in from_node.getpeerinfo(): | |||||
if to_node.name in peer['subver']: | |||||
result.append(peer['id']) | |||||
return result | |||||
peer_ids = get_peer_ids() | |||||
if not peer_ids: | |||||
logger.warning( | |||||
f"disconnect_nodes: {from_node.index} and {to_node.index} were not connected") | |||||
return | |||||
for peer_id in peer_ids: | |||||
try: | try: | ||||
from_node.disconnectnode(nodeid=peer_id) | from_node.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. | ||||
# This avoids a race condition if we're mass-disconnecting peers. | # This avoids a race condition if we're mass-disconnecting peers. | ||||
if e.error['code'] != -29: # RPC_CLIENT_NODE_NOT_CONNECTED | if e.error['code'] != -29: # RPC_CLIENT_NODE_NOT_CONNECTED | ||||
raise | raise | ||||
# wait to disconnect | # wait to disconnect | ||||
wait_until(lambda: [peer['id'] for peer in from_node.getpeerinfo( | wait_until(lambda: not get_peer_ids(), timeout=5) | ||||
) if to_node.name in peer['subver']] == [], timeout=5) | |||||
def connect_nodes(from_node, to_node): | def connect_nodes(from_node, to_node): | ||||
host = to_node.host | host = to_node.host | ||||
if host is None: | if host is None: | ||||
host = '127.0.0.1' | host = '127.0.0.1' | ||||
ip_port = host + ':' + str(to_node.p2p_port) | ip_port = host + ':' + str(to_node.p2p_port) | ||||
from_node.addnode(ip_port, "onetry") | from_node.addnode(ip_port, "onetry") | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |