Skip to content

Replace rand() with fixed-seed RNG to make tests deterministic#344

Open
alienx5499 wants to merge 1 commit intolibp2p:masterfrom
alienx5499:test/deterministic-rng
Open

Replace rand() with fixed-seed RNG to make tests deterministic#344
alienx5499 wants to merge 1 commit intolibp2p:masterfrom
alienx5499:test/deterministic-rng

Conversation

@alienx5499
Copy link
Contributor

@alienx5499 alienx5499 commented Mar 8, 2026

Summary

Replaces unseeded rand() in tests with a shared fixed-seed RNG to make test runs deterministic and reproducible, preventing flaky CI failures.

Why

Unseeded randomness causes flaky tests and non-reproducible CI failures.

What changed

  • Added testutil::randomBytes() and getTestRng() in test/testutil/libp2p/random.hpp.
  • Replaced rand() usage in:
    • test/testutil/libp2p/peer.cpp
    • test/libp2p/transport/tcp/tcp_integration_test.cpp
    • test/libp2p/crypto/marshaller_test.cpp
    • test/libp2p/protocol/kademlia/peer_routing_table_test.cpp

Impact

  • No functional changes.
  • Improves CI stability and debugging reliability.

Note

The RNG is shared (static); test execution order affects the byte sequence. Determinism is per run, not per test. See comment in random.hpp.

@alienx5499 alienx5499 force-pushed the test/deterministic-rng branch 2 times, most recently from 128c11d to ef3b0a9 Compare March 8, 2026 07:22
@alienx5499 alienx5499 force-pushed the test/deterministic-rng branch from ef3b0a9 to 6eac084 Compare March 8, 2026 07:56
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