Skip to content

test(kad): use virtual time to resolve flaky bootstrap test#6361

Open
0xsamalt wants to merge 5 commits intolibp2p:masterfrom
0xsamalt:fix-flaky-bootstrap-test
Open

test(kad): use virtual time to resolve flaky bootstrap test#6361
0xsamalt wants to merge 5 commits intolibp2p:masterfrom
0xsamalt:fix-flaky-bootstrap-test

Conversation

@0xsamalt
Copy link
Copy Markdown

Description

This PR fixes intermittent CPU-lag flakiness in Kademlia's bootstrap.rs test suite.

The tests previously measured real-world timeouts using futures_timer::Delay and web_time::Instant, causing them to fail when CI servers inevitably overshot expectations.

By leveraging Tokio's test-util feature and explicitly wrapping our mocks for the tests, #[tokio::test(start_paused = true)] ensures the elapsed test time is completely deterministic and decoupled from wall-clock performance. Tests run instantly and pass 100/100 times in local looping.

cc @jxs @elenaf9

Notes & open questions

  • This is purely an internal test infrastructure fix. Production paths are untouched because futures_timer::Delay is preserved under #[cfg(not(test))].
  • Because this does not affect any public API or library behavior, a changelog entry was intentionally omitted.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (N/A - Test fix)
  • I have added tests that prove my fix is effective or that my feature works (Modified existing flaky tests)
  • A changelog entry has been made in the appropriate crates (N/A - Internal testing change only)

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 31, 2026

This pull request has merge conflicts. Could you please resolve them @0xsamalt? 🙏

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.

1 participant