Skip to content

test(kad_dht): de-flake dht_pair fixture with a bounded poll (#1423) - #1424

Open
yashksaini-coder wants to merge 3 commits into
libp2p:mainfrom
yashksaini-coder:fix/deflake-dht-pair-fixture-1423
Open

test(kad_dht): de-flake dht_pair fixture with a bounded poll (#1423)#1424
yashksaini-coder wants to merge 3 commits into
libp2p:mainfrom
yashksaini-coder:fix/deflake-dht-pair-fixture-1423

Conversation

@yashksaini-coder

Copy link
Copy Markdown
Contributor

What

The dht_pair fixture in tests/core/kad_dht/test_kad_dht.py intermittently failed CI during setup with:

AssertionError: Node A should know about Node B

It waited a fixed trio.sleep(0.1) and then hard-asserted peer_in_table in both directions.

Why it raced

The mutual routing-table entries aren't populated by the find_peer calls (those short-circuit on the peerstore without writing to the routing table). They're populated by the background refresh manager — a time-driven random walk that opens mutual FIND_NODE streams and adds each peer via handle_stream. Under CI load that takes longer than the fixed 0.1s, so the assertion fired before discovery converged.

Fix

Poll peer_in_table (both directions) until it holds, bounded by trio.fail_after(10) so a peer that genuinely never lands still fails loud with TooSlowError instead of hanging or passing. Same pattern as the already-merged de-flakes in #1401 / #1408.

The fixed sleep is removed; the find_peer calls stay as a best-effort nudge.

Impact

This fixture backs ~5 tests. The same flake has tripped up two unrelated PRs recently (#1395, #1409) purely on this fixture — this unblocks both once merged.

Locally: tests/core/kad_dht/test_kad_dht.py passes 9/9, stable across repeated runs.

Closes #1423.

yashksaini-coder and others added 3 commits August 4, 2026 11:50
…1423)

The dht_pair fixture waited a fixed trio.sleep(0.1) and then hard-asserted
peer_in_table in both directions. The routing tables are populated by the
background refresh manager (time-driven mutual FIND_NODE), so under CI load
0.1s wasn't enough and setup failed with "Node A should know about Node B".

Poll until both directions land, bounded by trio.fail_after(10) so a peer
that genuinely never appears still fails loud (TooSlowError). Same idiom as
the libp2p#1401 / libp2p#1408 de-flakes.

Closes libp2p#1423.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky: dht_pair fixture races on routing-table population ("Node A should know about Node B")

2 participants