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 819b87a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions test/functional/p2p_time_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,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,7 +96,8 @@ 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)
assert_equal(ni['timeoffset'], 15)
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,7 +340,7 @@ 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))
Expand All @@ -350,6 +350,9 @@ def connect_nodes(self, a, b):
from_connection_subver = from_connection.getnetworkinfo()['subversion']
to_connection_subver = to_connection.getnetworkinfo()['subversion']

if not wait_for_connect:
return

def find_conn(node, peer_subversion, inbound):
return next(filter(lambda peer: peer['subver'] == peer_subversion and peer['inbound'] == inbound, node.getpeerinfo()), None)

Expand Down

0 comments on commit 819b87a

Please sign in to comment.