diff options
author | Danny Lee <robot-visions@protonmail.com> | 2020-05-05 10:15:35 -0700 |
---|---|---|
committer | Elliott Jin <robot-visions@protonmail.com> | 2020-05-07 10:32:01 -0700 |
commit | a9bd1f9adf869a95f70b3a40615a2f8e8e52db1d (patch) | |
tree | 9fb3fa656b6077f94f3509c99aeff060e3278849 | |
parent | f54753293fe7355e4280944d766f22054b560ba1 (diff) | |
download | bitcoin-a9bd1f9adf869a95f70b3a40615a2f8e8e52db1d.tar.xz |
test: warn if nodes not connected before disconnect_nodes
-rw-r--r-- | test/functional/test_framework/util.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 20ab9ee464..6cfb22befe 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -381,7 +381,21 @@ def set_node_times(nodes, t): node.setmocktime(t) def disconnect_nodes(from_connection, node_num): - for peer_id in [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']]: + def get_peer_ids(): + 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() + if not peer_ids: + logger.warning("disconnect_nodes: {} and {} were not connected".format( + from_connection.index, + node_num + )) + return + for peer_id in peer_ids: try: from_connection.disconnectnode(nodeid=peer_id) except JSONRPCException as e: @@ -392,7 +406,7 @@ def disconnect_nodes(from_connection, node_num): raise # wait to disconnect - wait_until(lambda: [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == [], timeout=5) + wait_until(lambda: not get_peer_ids(), timeout=5) def connect_nodes(from_connection, node_num): ip_port = "127.0.0.1:" + str(p2p_port(node_num)) |