Repository navigation
test(gossip): cover peertable eviction boundary conditions - #363
Conversation
Adds five unit tests to PeerTable covering eviction-cutoff edge cases: exact-cutoff retention, one-microsecond-past-cutoff removal, saturating_sub underflow, refresh-at-boundary retention, and refresh resetting the eviction clock. Closes #307 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces several unit tests to the PeerTable module to verify eviction logic, including edge cases like exact cutoff times, microsecond differences, and saturating subtraction underflows. It also tests the refresh mechanism's impact on the eviction clock. Feedback suggests improving test robustness by replacing .ok() with explicit assertions on the InsertOutcome using .unwrap() to ensure setup steps succeed as expected.
There was a problem hiding this comment.
Pull request overview
Adds targeted unit tests for PeerTable::evict_expired in decdn-gossip, focusing on cutoff boundary conditions and the saturating_sub underflow case described in #307.
Changes:
- Add tests for eviction behavior at the exact cutoff and 1µs past the cutoff.
- Add a test covering the
now_us.saturating_sub(ttl_us)underflow path. - Add refresh + eviction interaction tests ensuring refresh updates
last_seen_usand extends the eviction window.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Resolves conflicts with PRs #363/#364/#365/#366 that landed on main while this branch was in review. Conflict resolution: - crates/node/Cargo.toml: keep both new dev-deps (nix from this branch for SIGHUP integration tests, wiremock from #366 for the rpc-watchdog test). - crates/node/src/runtime/mod.rs: union the test-module clippy allows ([unwrap_used, expect_used, panic, indexing_slicing]); keep both new test bodies (rpc_watchdog_tracks_endpoint_transitions from #366 plus shutdown_streams_recv_resolves_on_sigterm from this branch). - Test fixtures across config/mod.rs, runtime/reload.rs, and tests/sighup_signal.rs gained the rpc_watchdog_interval_sec field (Option::None for FileConfig literals; literal 30u64 for ResolvedBlockchain). Verified post-merge: cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo nextest run -p decdn-node (179/179), RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps --document-private-items, all clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Adds five unit tests to
PeerTableincrates/gossip/src/peer_table.rscovering boundary conditions inevict_expiredthat the existing tests didn't exercise.New tests:
evict_at_exact_cutoff_keeps_entry— entry whoselast_seen_usequals the cutoff stays (>=semantics).evict_one_microsecond_past_cutoff_removes_entry— one µs past the cutoff is removed.saturating_sub_underflow_keeps_all_entries— guards thenow_us.saturating_sub(ttl_us)underflow path.refresh_at_boundary_keeps_entry— refresh-at-boundary race the issue mentions; refreshedlast_seenkeeps the entry alive.refresh_resets_eviction_clock— refreshing extends the entry past what would otherwise be its eviction time.Closes #307
Test plan
cargo fmt -- --checkcargo clippy --workspace --all-targets -- -D warningscargo nextest run -p decdn-gossip(27/27 pass; 9/9 inpeer_table::tests)