diff --git a/test/functional/p2p_time_offset.py b/test/functional/p2p_time_offset.py index 2ace694ec7e48..98ff17d91d97d 100755 --- a/test/functional/p2p_time_offset.py +++ b/test/functional/p2p_time_offset.py @@ -9,6 +9,7 @@ from test_framework.util import ( assert_equal, set_node_times, + wait_until, ) @@ -22,9 +23,9 @@ def setup_network(self): # don't connect nodes yet self.setup_nodes() - def connect_nodes_bi(self, a, b): - self.connect_nodes(a, b) - self.connect_nodes(b, a) + def connect_nodes_bi(self, a, b, wait_for_connect = True): + self.connect_nodes(a, b, wait_for_connect) + self.connect_nodes(b, a, wait_for_connect) def check_connected_nodes(self): ni = [node.getnetworkinfo() for node in self.connected_nodes] @@ -96,9 +97,9 @@ def run_test(self): # try to connect node 5 and check that it can't self.log.info("Trying to connect with node-5 (+30 s)...") - self.connect_nodes_bi(0, 5) - ni = self.nodes[0].getnetworkinfo() - assert_equal(ni['connections'], 10) + # Don't wait for a connection that will never be established. + self.connect_nodes_bi(0, 5, False) + wait_until(lambda: self.nodes[0].getnetworkinfo()['connections'] == 10) assert_equal(ni['timeoffset'], 15) self.log.info("Not connected.") self.log.info("Node-0 nTimeOffset: +%d seconds" % ni['timeoffset']) diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index dc812f174e1c5..e737d80c982b3 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -340,12 +340,15 @@ def restart_node(self, i, extra_args=None): def wait_for_node_exit(self, i, timeout): self.nodes[i].process.wait(timeout) - def connect_nodes(self, a, b): + def connect_nodes(self, a, b, wait_for_connect = True): from_connection = self.nodes[a] to_connection = self.nodes[b] ip_port = "127.0.0.1:" + str(p2p_port(b)) from_connection.addnode(ip_port, "onetry") + if not wait_for_connect: + return + # Use subversion as peer id. Test nodes have their node number appended to the user agent string from_connection_subver = from_connection.getnetworkinfo()['subversion'] to_connection_subver = to_connection.getnetworkinfo()['subversion']