Verified Commit 01b59c55 authored by Philippe B.'s avatar Philippe B. 🏂 Committed by Romain

Tests/python: check node connectivity (improvements)

When running a node with ``, it may take some time before
the node is accepting RPC connections.

Currenty, an arbitrary sleeping time is enforced in `sandbox.add_node`
and in the tests that restart nodes. This may fail non-deterministically
on some setups.

This patch and the one before that add a new method to the client that
polls a node using some RPC. `time.sleep` are replaced by a call to
this method.

This should make tests more robust and less dependent on the execution
parent b9b66e94
Pipeline #104581386 passed with stages
in 30 minutes and 53 seconds
......@@ -660,13 +660,25 @@ class Client:
'signatures'] + signatures
def check_node_listening(self):
timeout = 0.5
attempts = 5
def check_node_listening(self,
timeout: float = 0.5,
attempts: int = 10) -> bool:
""" Checks whether the node is reponsive, by polling it
using the `version` rpc.
timeout (float): time (sec) to wait between retries
attempts (int): maximal number of attempts
True iff the node is running, and successfully answered the
`version` rpc.
for _ in range(attempts):
# any shell RPC will do, this one is light-weight
self.rpc('get', '/network/version')
return True
except Exception: # pylint: disable=broad-except
return False
from typing import Dict, List, Tuple
import time
import subprocess
import os
import tempfile
......@@ -116,7 +115,6 @@ class Node:
self._process = subprocess.Popen(self._node_run, stdout=stdout,
stderr=stderr, env=self._new_env)
time.sleep(0.1) # make sure node is launched when we access it later
self._run_called_before = True
def init_config(self):
......@@ -197,10 +197,9 @@ class Sandbox:
if not client.check_node_listening():
assert node.poll() is None, '# Node {node_id} failed at startup'
assert False, f"# Node {node_id} isn't listening to RPC"
# make sure node didn't fail at startup
assert node.poll() is None, 'Seems node failed at startup'
assert False, f"# Node {node_id} isn't responding to RPC"
# don't wait for confirmation['-w', 'none', 'config', 'update'])
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment