Skip to content

test(node): integration tests for DHT FindValue lookup (closes #711) - #719

Merged
thiras merged 1 commit into
mainfrom
test/dht-integration-711
May 29, 2026
Merged

thiras merged 1 commit into
mainfrom
test/dht-integration-711

Conversation

@thiras

@thiras thiras commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #711 — adds integration coverage for the iterative FindValue lookup path introduced in PR #673 (ADR 022 §FIND_VALUE Flow, §Routing Table, §Lookup integrity). New file crates/node/tests/dht_integration.rs plus one production test seam.

The issue's auto-triage framing assumed Kademlia mechanics this codebase doesn't have; the tests were written against the actual behaviour, and the module doc is explicit about each adaptation:

  • The routing table is LRU-on-overflow with 256 fixed buckets, not split-on-overflow — so "k-bucket split" maps onto bucket-overflow eviction.
  • find_providers never mutates the routing table or marks peers stale on failure; there is no stale-pruning mechanism to test.
  • The negative cache is Instant-anchored, so tokio::time::pause/advance (which the issue suggested) has no effect — hence the injected short-TTL seam.

Tests added

Test Behaviour pinned
bucket_overflow_evicts_lru_and_departed_node_is_removed One bucket filled past K_BUCKET_SIZE → LRU eviction; remove() of a surviving entry on node departure
find_providers_converges_after_peer_departs Lookup still converges to the surviving provider after a peer is removed
find_providers_tolerates_unreachable_peer A peer whose handler is dropped mid-lookup — and which is the closest candidate to the target — doesn't wedge the pass; the live, farther provider still surfaces. Wall-clock guard against a hang regression
find_providers_converges_via_closer_nodes_second_round Genuine two-round lookup: holder reachable only via a seed's closer_nodes referral — first E2E coverage of the iterative observed_closer loop
find_providers_negative_cache_expires_after_ttl Provider suppressed while the entry is live, then un-suppressed after TTL on the same cache instance — expiry doesn't poison future lookups

Production change

NegativeProbeCache::with_capacity_and_ttl promoted from private to a documented pub test/tuning seam (production still uses new() with the ADR 001 1024-entry / 5-minute defaults). Required because the cache is Instant-anchored and #[cfg(test)] constructors aren't visible to the tests/ crate.

Review

Ran a multi-agent PR review (code / tests / comments) before opening; acted on all critical and important findings — strengthened the unreachable-peer test from a partly-vacuous assertion, added the missing multi-round E2E test, and corrected two doc inaccuracies.

Verification

  • cargo fmt --check, cargo clippy -p decdn-node --tests — clean
  • cargo nextest run -p decdn-node --test dht_integration — 5/5 pass, stable across repeated runs
  • Surrounding suite (dht_lookup, dht_loopback, dht_bootstrap, negative_cache unit tests) — unaffected, all pass

🤖 Generated with Claude Code

Adds `crates/node/tests/dht_integration.rs` covering the iterative
FindValue lookup path from PR #673, the behaviours that only manifest
once the routing table and negative cache interact with a live lookup:

- bucket-overflow LRU eviction + node departure (`remove`) — the
  routing table is LRU-on-overflow, not split-on-overflow Kademlia, so
  issue #711's "k-bucket split" maps onto eviction behaviour;
- convergence after a peer departs the routing table;
- an unreachable peer mid-lookup (handler dropped) does not wedge the
  pass — pinned with the dead peer as the *closest* candidate so the
  live, farther provider still surfacing is non-trivial, plus a
  wall-clock guard against a hang regression;
- genuine two-round convergence via a `closer_nodes` referral, the
  first end-to-end coverage of the iterative `observed_closer` loop;
- negative-cache TTL expiry un-suppresses a provider on the same cache
  instance, proving a stale entry does not poison future lookups.

Promotes `NegativeProbeCache::with_capacity_and_ttl` to a documented
`pub` test/tuning seam: the cache is `Instant`-anchored, so `tokio::time`
cannot drive it and a short injected TTL is the only deterministic way
to exercise expiry from an integration test. Production still uses
`new()` with the ADR 001 defaults.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 29, 2026 23:02
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions

github-actions Bot commented May 29, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 89.27% (was 89.25%, ▲ +0.02%) — 21608/24204 lines

File Coverage Lines Δ
crates/node/src/dht/negative_cache.rs 95.42% 125/131 ● 0.00%
History
Commit Total Δ vs base
3756174 (HEAD) 89.27% ▲ +0.02%

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 integration test coverage for the iterative FindValue DHT lookup path (PR #673), exercising routing-table LRU eviction + node departure, multi-round convergence via closer_nodes, tolerance of unreachable peers, and negative-cache TTL expiry. To enable deterministic short-TTL expiry tests (the cache is Instant-anchored, so tokio::time cannot drive it), NegativeProbeCache::with_capacity_and_ttl is promoted to a documented pub test/tuning seam.

Changes:

  • New crates/node/tests/dht_integration.rs with 5 integration tests covering bucket overflow + departure, convergence after departure, unreachable closest peer, two-round closer_nodes referral, and negative-cache TTL expiry.
  • Promote NegativeProbeCache::with_capacity_and_ttl from private to pub with documentation as a test/tuning seam.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/node/tests/dht_integration.rs New integration tests covering multi-round, unreachable, departure, and TTL-expiry behaviors of find_providers.
crates/node/src/dht/negative_cache.rs Make with_capacity_and_ttl public with rationale doc so integration tests can inject short TTLs.

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

@thiras thiras changed the title test(node): DHT FindValue lookup integration tests (closes #711) test(node): integration tests for DHT FindValue lookup (closes #711) May 29, 2026
@thiras
thiras merged commit 32a7d95 into main May 29, 2026
37 of 39 checks passed
@thiras
thiras deleted the test/dht-integration-711 branch May 29, 2026 23:14
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.

tests: no integration test for DHT iterative FindValue lookup covering k-bucket split, stale-node pruning, and negative probe cache expiry

2 participants