test(pubsub): de-flake test_gossip_gate_filters_peers (#1401) - #1402
Open
yashksaini-coder wants to merge 2 commits into
Open
test(pubsub): de-flake test_gossip_gate_filters_peers (#1401)#1402yashksaini-coder wants to merge 2 commits into
yashksaini-coder wants to merge 2 commits into
Conversation
The test subscribed all peers to a topic then waited a fixed trio.sleep(0.2) before calling _get_peers_to_send. That helper skips a topic until it appears in pubsub.peer_topics, which is only populated on receipt of a SUBSCRIBE RPC. On slow CI (seen on windows 3.12) 0.2s was insufficient, so the topic key was absent, the loop continued, and peers_to_send came back empty -> 'assert peer1_id in peers_to_send' failed. Replace the fixed sleep with the event-based Pubsub.wait_for_subscription helper (whose docstring recommends exactly this). All mesh/score state in this test is set manually, so subscription propagation is the only timing dependency; the fix is deterministic and non-hanging (5s timeout). Scope limited to this test: sibling tests share the pattern but some depend on heartbeat-driven mesh formation where a subscription-only wait would under-wait. Closes libp2p#1401.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1401.
test_gossip_gate_filters_peersfails intermittently on CI (seen onwindows (3.12, core); green on all Linux runners and Windows 3.11/3.13):Root cause
The test subscribes all peers, then waits a fixed
await trio.sleep(0.2)before callinggsub0._get_peers_to_send(...). That helper skips a topic until it appears inpubsub.peer_topics:peer_topics[topic]is only populated when the node receives a SUBSCRIBE RPC (handle_subscription). On a slow runner the subscription hasn't propagated togsub0within 0.2s → topic key absent →continue→send_toempty →peers_to_send == []. A fixed-sleep race, not a logic bug (all mesh/score state in this test is set manually).Fix
Replace the fixed sleep with the existing event-based helper
Pubsub.wait_for_subscription(peer_id, topic)— whose own docstring says "Use this instead of arbitrary trio.sleep() calls to avoid race conditions." Deterministic and non-hanging (5s timeout, returns instantly once the subscription is registered).Scope
Intentionally limited to this one test. Sibling tests in the file share the fixed-sleep pattern, but at least one (
test_publish_gate_blocks_low_scoring_peers) depends on heartbeat-driven mesh formation, where a subscription-only wait would under-wait and introduce a different flake. A broader de-flake needs per-test analysis and is out of scope here.Test plan
test_gossip_gate_filters_peersrun 5× locally → stable passtest_gossipsub_v1_1_score_gates.py→ 11 passed, no regressionruff check/ruff format --checkcleannewsfragments/1401.internal.rstadded