pytest: make test_connect_ratelimit more robust
What changed, and why it matters
This commit only changes a test file to make an existing test more reliable. Instead of pausing the whole lightning node process during a test, it now pauses only the 'connectd' sub-process. There is no change to production code and no security fix or vulnerability.
No security action needed; treat as normal test reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/test_connection.py::test_connect_ratelimit. Previously the test sent SIGSTOP to each node’s main daemon PID, but that did not reliably stop connectd in time, causing flaky test behavior. The patch extracts each node’s connectd PID from the log line ‘connectd: pid
Changed components
tests/test_connection.pyInspect captured patch +12 / −6
diff --git a/tests/test_connection.py b/tests/test_connection.py
index 1d3ea7d1..20fa6259 100644
--- a/tests/test_connection.py
+++ b/tests/test_connection.py
@@ -4496,9 +4496,15 @@ def test_connect_ratelimit(node_factory, bitcoind):
assert not l1.daemon.is_in_log('Unblocking for')
l1.stop()
- # Suspend the others, to make sure they cannot respond too fast.
+
+ # Suspend the others' connectd, to make sure they cannot respond too fast.
+ connectd_pids = []
for n in nodes:
- os.kill(n.daemon.proc.pid, signal.SIGSTOP)
+ log = n.daemon.is_in_log(' connectd: pid .*, msgfd')
+ m = re.search(r'connectd: pid (\d*),', log)
+ pid = int(m.groups()[0])
+ connectd_pids.append(pid)
+ os.kill(pid, signal.SIGSTOP)
try:
l1.start()
@@ -4509,13 +4515,13 @@ def test_connect_ratelimit(node_factory, bitcoind):
* (len(nodes) - 1))
except Exception as err:
# Resume, so pytest doesn't hang!
- for n in nodes:
- os.kill(n.daemon.proc.pid, signal.SIGCONT)
+ for p in connectd_pids:
+ os.kill(p, signal.SIGCONT)
raise err
# Resume them
- for n in nodes:
- os.kill(n.daemon.proc.pid, signal.SIGCONT)
+ for p in connectd_pids:
+ os.kill(p, signal.SIGCONT)
# And now they're all connected
wait_for(lambda: [p['connected'] for p in l1.rpc.listpeers()['peers']] == [True] * len(nodes))
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.