Skip to content

Commit 5f8c06e

Browse files
committed
test: Add possibility to skip awaiting for the connection
1 parent 5374229 commit 5f8c06e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

test/functional/p2p_time_offset.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from test_framework.util import (
1010
assert_equal,
1111
set_node_times,
12+
wait_until,
1213
)
1314

1415

@@ -22,9 +23,9 @@ def setup_network(self):
2223
# don't connect nodes yet
2324
self.setup_nodes()
2425

25-
def connect_nodes_bi(self, a, b):
26-
self.connect_nodes(a, b)
27-
self.connect_nodes(b, a)
26+
def connect_nodes_bi(self, a, b, wait_for_connect = True):
27+
self.connect_nodes(a, b, wait_for_connect)
28+
self.connect_nodes(b, a, wait_for_connect)
2829

2930
def check_connected_nodes(self):
3031
ni = [node.getnetworkinfo() for node in self.connected_nodes]
@@ -96,9 +97,9 @@ def run_test(self):
9697

9798
# try to connect node 5 and check that it can't
9899
self.log.info("Trying to connect with node-5 (+30 s)...")
99-
self.connect_nodes_bi(0, 5)
100-
ni = self.nodes[0].getnetworkinfo()
101-
assert_equal(ni['connections'], 10)
100+
# Don't wait for a connection that will never be established.
101+
self.connect_nodes_bi(0, 5, False)
102+
wait_until(lambda: self.nodes[0].getnetworkinfo()['connections'] == 10)
102103
assert_equal(ni['timeoffset'], 15)
103104
self.log.info("Not connected.")
104105
self.log.info("Node-0 nTimeOffset: +%d seconds" % ni['timeoffset'])

test/functional/test_framework/test_framework.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,15 @@ def restart_node(self, i, extra_args=None):
340340
def wait_for_node_exit(self, i, timeout):
341341
self.nodes[i].process.wait(timeout)
342342

343-
def connect_nodes(self, a, b):
343+
def connect_nodes(self, a, b, wait_for_connect = True):
344344
from_connection = self.nodes[a]
345345
to_connection = self.nodes[b]
346346
ip_port = "127.0.0.1:" + str(p2p_port(b))
347347
from_connection.addnode(ip_port, "onetry")
348348

349+
if not wait_for_connect:
350+
return
351+
349352
# Use subversion as peer id. Test nodes have their node number appended to the user agent string
350353
from_connection_subver = from_connection.getnetworkinfo()['subversion']
351354
to_connection_subver = to_connection.getnetworkinfo()['subversion']

0 commit comments

Comments
 (0)