Skip to content

Commit

Permalink
test: Add possibility to skip awaiting for the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Nov 11, 2024
1 parent 5374229 commit 6fe4635
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions test/functional/p2p_time_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from test_framework.util import (
assert_equal,
set_node_times,
wait_until,
)


Expand All @@ -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]
Expand Down Expand Up @@ -96,9 +97,10 @@ 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)
# Don't wait for a connection that will never be established.
self.connect_nodes_bi(0, 5, False)
ni = self.nodes[0].getnetworkinfo()
assert_equal(ni['connections'], 10)
wait_until(lambda: ni['connections'] == 10)
assert_equal(ni['timeoffset'], 15)
self.log.info("Not connected.")
self.log.info("Node-0 nTimeOffset: +%d seconds" % ni['timeoffset'])
Expand Down
5 changes: 4 additions & 1 deletion test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 6fe4635

Please sign in to comment.