Skip to content

test(gossip): cover peertable eviction boundary conditions - #363

Merged
thiras merged 2 commits into
mainfrom
test/peer-table-boundaries
Apr 30, 2026
Merged

thiras merged 2 commits into
mainfrom
test/peer-table-boundaries

Conversation

@thiras

@thiras thiras commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds five unit tests to PeerTable in crates/gossip/src/peer_table.rs covering boundary conditions in evict_expired that the existing tests didn't exercise.

New tests:

  • evict_at_exact_cutoff_keeps_entry — entry whose last_seen_us equals 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 the now_us.saturating_sub(ttl_us) underflow path.
  • refresh_at_boundary_keeps_entry — refresh-at-boundary race the issue mentions; refreshed last_seen keeps 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 -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo nextest run -p decdn-gossip (27/27 pass; 9/9 in peer_table::tests)

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]>
Copilot AI review requested due to automatic review settings April 30, 2026 20:08

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/gossip/src/peer_table.rs Resolved
Comment thread crates/gossip/src/peer_table.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_us and extends the eviction window.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/gossip/src/peer_table.rs Resolved
Comment thread crates/gossip/src/peer_table.rs Resolved
Comment thread crates/gossip/src/peer_table.rs Resolved
Comment thread crates/gossip/src/peer_table.rs Resolved
Comment thread crates/gossip/src/peer_table.rs Resolved
@thiras
thiras merged commit b916c7e into main Apr 30, 2026
9 checks passed
@thiras
thiras deleted the test/peer-table-boundaries branch April 30, 2026 20:42
thiras added a commit that referenced this pull request Apr 30, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants