pytest: fix flakes in test_onchain_reestablish_reply and test_reestablish_closed_channels
What changed, and why it matters
This change only adjusts two automated test cases to prevent them from randomly failing in the project's own test suite. It does not change the actual Core Lightning software that users run, and it does not fix or introduce any security issue in production code.
No security action needed. Treat as a normal test-flakiness fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds mock_rpc('getblockhash', None) calls at the end of two pytest integration tests (test_onchain_reestablish_reply and test_reestablish_closed_channels). During slow test runs, the embedded bitcoind mock was returning invalid/null responses for getblockhash, causing the lightningd under test to hit its 60-second bitcoin retry timeout and abort, producing flaky CI failures. The patch stops the mocked RPC after the test’s meaningful assertions are complete, preventing the unrelated bitcoind-mock noise from triggering a fatal shutdown during teardown. No production code is modified.
Changed components
tests/test_closing.pyInspect captured patch +8 / −0
diff --git a/tests/test_closing.py b/tests/test_closing.py
index beb7542d..5c4a17ac 100644
--- a/tests/test_closing.py
+++ b/tests/test_closing.py
@@ -4308,6 +4308,10 @@ def test_onchain_reestablish_reply(node_factory, bitcoind, executor):
l3.daemon.wait_for_log("peer_in WIRE_ERROR")
wait_for(lambda: only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'AWAITING_UNILATERAL')
+ # If we're slow enough, l3 can get upset with the invalid
+ # responses from bitcoind, so stop that now.
+ l3.daemon.rpcproxy.mock_rpc('getblockhash', None)
+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd anchors not supportd')
def test_onchain_slow_anchor(node_factory, bitcoind):
@@ -4395,6 +4399,10 @@ def test_reestablish_closed_channels(node_factory, bitcoind):
# Make sure l2 was happy with the reestablish message.
assert not l2.daemon.is_in_log('bad reestablish')
+ # If we're slow enough, l2 can get upset with the invalid
+ # responses from bitcoind, so stop that now.
+ l2.daemon.rpcproxy.mock_rpc('getblockhash', None)
+
@unittest.skipIf(TEST_NETWORK != 'regtest', "elementsd doesn't use p2tr anyway")
def test_onchain_close_no_p2tr(node_factory, bitcoind):
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.