pytest: fix flake in test_gossip_store_compact_while_extending and test_gossmap_lost_node
What changed, and why it matters
This commit fixes two flaky automated tests in the Core Lightning project's test suite. The tests were occasionally failing because they assumed all network node announcements had been received, but the helper function they used only waited for channel announcements. The fix adds an explicit wait for node announcements before capturing the list of nodes. There is no change to production code and no security relevance.
No security action needed. This is a test reliability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In tests/test_gossip.py, two test functions (test_gossip_store_compact_while_extending and test_gossmap_lost_node) now call wait_for(lambda: all([‘alias’ in n for n in l1.rpc.listnodes()[‘nodes’]])) before recording pre_nodes. This ensures node_announcements have propagated, preventing race-condition assertion failures where post_nodes differed from pre_nodes due to missing alias fields. The change is purely test-hardening.
Changed components
tests/test_gossip.pyInspect captured patch +4 / −0
diff --git a/tests/test_gossip.py b/tests/test_gossip.py
index e0b1ed9b..30f94174 100644
--- a/tests/test_gossip.py
+++ b/tests/test_gossip.py
@@ -1691,6 +1691,8 @@ def test_gossip_store_compact_while_extending(node_factory, bitcoind, executor):
wait_for(lambda: sorted([c['fee_per_millionth'] for c in l1.rpc.listchannels(scid12)['channels']]) == [10, 1004])
pre_channels = l1.rpc.listchannels()
+ # Make sure all node_announcements have been seen.
+ wait_for(lambda: all(['alias' in n for n in l1.rpc.listnodes()['nodes']]))
pre_nodes = sorted(l1.rpc.listnodes()['nodes'], key=lambda n: n['nodeid'])
# Compaction "continues".
@@ -2493,6 +2495,8 @@ def test_gossmap_lost_node(node_factory, bitcoind):
assert l1.rpc.listchannels(scid23) == {'channels': []}
pre_channels = l1.rpc.listchannels()
+ # Make sure all node_announcements have been seen.
+ wait_for(lambda: all(['alias' in n for n in l1.rpc.listnodes()['nodes']]))
pre_nodes = sorted(l1.rpc.listnodes()['nodes'], key=lambda n: n['nodeid'])
l1.restart()
post_channels = l1.rpc.listchannels()
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.