diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2018-02-26 14:04:41 -0800 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2018-03-15 23:43:53 -0700 |
commit | 81b0822772169cb697b5994f49398e619d61a12d (patch) | |
tree | 5fa33497ba61f9ab4f14be747aed72225149966d /test/functional/test_framework/util.py | |
parent | 7be9a9a570c1140048f8781ced1111e1d930e517 (diff) | |
download | bitcoin-81b0822772169cb697b5994f49398e619d61a12d.tar.xz |
test: Use wait_until in tests where time was used for polling
Diffstat (limited to 'test/functional/test_framework/util.py')
-rw-r--r-- | test/functional/test_framework/util.py | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 7be695550b..68ac97d755 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -340,20 +340,15 @@ 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']]: from_connection.disconnectnode(nodeid=peer_id) - for _ in range(50): - if [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == []: - break - time.sleep(0.1) - else: - raise AssertionError("timed out waiting for disconnect") + # wait to disconnect + wait_until(lambda: [peer['id'] for peer in from_connection.getpeerinfo() if "testnode%d" % node_num in peer['subver']] == [], timeout=5) def connect_nodes(from_connection, node_num): ip_port = "127.0.0.1:" + str(p2p_port(node_num)) from_connection.addnode(ip_port, "onetry") # poll until version handshake complete to avoid race conditions # with transaction relaying - while any(peer['version'] == 0 for peer in from_connection.getpeerinfo()): - time.sleep(0.1) + wait_until(lambda: all(peer['version'] != 0 for peer in from_connection.getpeerinfo())) def connect_nodes_bi(nodes, a, b): connect_nodes(nodes[a], b) |