Repository navigation
test(node): de-flake the DHT integration suite and unpin two teardown budgets (#1830) - #1832
Merged
Merged
Conversation
Coverage reportTotal: 82.01% (was 82.00%, ▲ +0.01%) — 68155/83101 lines
History
|
… budgets (#1830) Three of #1830's seven claims survive verification against main. The rest describe defects that #691, #1594/#1595 and #1779 already closed; the issue read historical rationale in comments as live defects, so those comments go too. `find_providers_negative_cache_expires_after_ttl` raced its own fixture: the injected 750ms TTL had to outlive a live loopback QUIC lookup before the suppression assertion read it, or the entry expired early and the provider was never suppressed. `tokio::time::pause` is unavailable there — the test is multi_thread over real QUIC, and the cache is anchored on `std::time::Instant` either way. Suppression now runs under the production TTL, which nothing in the test can outlive, and expiry is forced on the one key under test by re-recording it with a `Duration::ZERO` TTL: entries hold an absolute expiry, `shift_insert` updates an existing key in place, and `contains_active` reads `expiry <= now` as elapsed. That drops the 1100ms sleep with it — the test goes from 1.40s to 0.35s. Wall-clock TTL passage stays covered by the `negative_cache` unit tests and by `node_origin_pull`'s refusal suite. One 3s `round_timeout` served both the scenario where a round must time out and the two where a reachable peer must answer within it, making convergence an assertion about loopback latency under llvm-cov. Split into a convergence budget sitting just above `DHT_CLIENT_TIMEOUT` — so the per-RPC cap stays the binding constraint — and the short budget named only where a timeout is the point. The unreachable scenario's hang guard was 12s, exactly `MAX_LOOKUP_ROUNDS × 3s`: a guard on the implementation's own worst case, not headroom over it. It measures 6.4s (two rounds, not the one its comment claimed) and now has a guard that clears the ceiling. The file also tore endpoints down by hand — one unbounded `close().await` and a fire-and-forget spawn that let the test return mid-close — which is the hazard `support::shutdown` documents. It now routes through that helper, so a stalled close is bounded and named instead of parking until the nextest backstop, and a handler panic in the accept loop reaches the test that spawned it rather than being discarded by the abort. Last, `SHUTDOWN_TIMEOUT` equalled `ABANDON_DRAIN_CAP`, so one ceilinged abandon drain could consume the whole teardown budget before the first close was attempted and report `0/M endpoints closed` for a run in which nothing was wedged — a false stranded-driver reading on the channel that keeps #1675 visible. It now clears the drain cap. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`interval_flush_persists_progress_before_completion` asserted a flush count that only held if the runner cooperated. The work future sleeps 130ms on the real clock against a 20ms flush interval, and `drive_with_interval_flush` selects `biased` with completion first — so a runtime descheduled past the work's deadline finds it already elapsed and returns, having flushed as few as once. CI hit exactly that: `got 1`. `start_paused` removes the wall clock. The interval's deadlines become the only thing that can advance time, so the count is arithmetic: the immediate first tick is consumed before the loop, leaving 20..=120ms inside the work's 130ms. Six, every time — which lets the assertion tighten from `> 1` to an exact count, and that also pins the single-writer property the test claims to check, since a work future that flushed too would push it over six. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
yigitdot
force-pushed
the
fix/1830-deflake-dht-and-teardown
branch
from
August 26, 2026 09:32
da85893 to
f7487e8
Compare
Six findings from the review of #1832. Two are behavioral; four correct prose that asserted things the code does not do. `TestServer::shutdown` now verifies its postcondition. `support::shutdown` warns rather than fails on a deadline breach, because the stranded-driver half of that breach is the known-open #1675. For teardown that is right. At the one call site in `find_providers_tolerates_unreachable_peer` it is not teardown but the scenario's PRECONDITION: on a breach the dead peer stays up and the test passes having exercised nothing. `Endpoint::is_closed` keeps that failure loud. `CONVERGENCE_ROUND_TIMEOUT > DHT_CLIENT_TIMEOUT` moves from prose into a `const _: () = assert!`. The ordering is the constant's whole purpose — a `DHT_CLIENT_TIMEOUT` raised past it silently restores the round drain pre-empting a peer the RPC layer still wants, with both convergence scenarios back to measuring loopback latency and still green. Same shape as `node_origin`'s `REFUSAL_SUPPRESSION_TTL` ceiling assertion. The unreachable scenario spends ONE round, not two. Measured by varying the constant: at 3s the test costs 6.4s, at 1s it costs 4.3s — a 2s cut buys 2.1s, so one round is in the budget and the remaining ~3.4s is fixture. The routing table holds two peers and `alpha` is 3, so round one queries both and the next pass breaks on an empty batch BEFORE arming a second round. `UNREACHABLE_HANG_GUARD` is unchanged: it is sized against the `MAX_LOOKUP_ROUNDS` ceiling, which is what a hang guard should clear. `with_capacity_and_ttl`'s doc no longer prescribes against three of its own module's unit tests. TTL semantics and cache-wide TTL quantity are both legitimate subjects for the seam; only an entry expired as a PRECONDITION wants the `Duration::ZERO` idiom instead. `SHUTDOWN_TIMEOUT` drops the claim to track `runtime::SHUTDOWN_DEADLINE` — the values coincide but nothing couples them, and that constant is private to another crate. `ABANDON_DRAIN_CAP` is the sole derivation. The mechanism is corrected too: the drain runs on the pull leg's own runtime thread, so the first close IS attempted and blocks inside it. The `driver.rs` test does not pin the single-writer property: its work future is a bare `sleep` holding no `&store`, so it cannot flush and the count cannot detect one that does. The virtual clock also advances to the work's own sleep deadline, not only the interval's. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
thiras
approved these changes
Aug 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1830.
Three of #1830's seven claims survive verification against
main. The rest describe defects that #691, #1594/#1595 and #1779 already closed — the issue read historical rationale left in code comments as live defects, so those comments go too. The full per-claim triage is on the issue.Negative-cache expiry stops being a latency race
find_providers_negative_cache_expires_after_ttlraced its own fixture: the injected 750ms TTL had to outlive a live loopback QUIC lookup before the suppression assertion read it, or the entry expired early and the provider was never suppressed.tokio::time::pauseis unavailable there — the test ismulti_threadover real QUIC, and the cache is anchored onstd::time::Instanteither way, so swapping the clock source would not have helped.Suppression now runs under the production TTL, which nothing in the test can outlive, and expiry is forced on the one key under test by re-recording it with a
Duration::ZEROTTL: entries hold an absolute expiry,shift_insertupdates an existing key in place, andcontains_activereadsexpiry <= nowas elapsed.Duration::ZERO-as-already-expired is the module's own documented idiom (probe_cache.rs), not a new trick. Alen() == 1assertion pins that the re-record lands on the same key, so a future refactor cannot quietly turn this into "an unrelated entry doesn't suppress".The 1100ms sleep goes with it — 1.40s → 0.35s. Wall-clock TTL passage stays covered by the
negative_cacheunit tests andnode_origin_pull's refusal suite; what this test uniquely owns (thatfind_providersconsults the cache on every pass, and the same instance recovers, across a real QUIC round trip) is unchanged.One
round_timeoutwas serving two opposite purposes3s was short so the unreachable-peer scenario fails fast — but it was simultaneously the budget a reachable loopback round had to answer in, for two convergence tests, one of which needs two sequential rounds. Split into a convergence budget sitting just above
DHT_CLIENT_TIMEOUT(so the per-RPC cap stays the binding constraint and the round drain never pre-empts a peer the RPC layer still wants to wait for), and the short budget named explicitly at the one call site where a timeout is the point.The unreachable scenario's hang guard was
Duration::from_secs(12)— exactlyMAX_LOOKUP_ROUNDS (4) × 3s, the implementation's own worst case. That is a guard sitting on the ceiling, not clearing it, so it is raised to 30s.The scenario itself spends one round. Measured by varying the constant: at 3s the test costs 6.4s, at 1s it costs 4.3s — a 2s cut buys 2.1s, so exactly one round is in the budget and the remaining ~3.4s is fixture setup and teardown. The routing table holds two peers and
alphais 3, so round one queries both, and the next pass breaks on an empty batch before arming a second round. The guard is sized against theMAX_LOOKUP_ROUNDSceiling regardless, which is what a hang guard should clear.Teardown is bounded and the two budgets no longer collide
The file tore endpoints down by hand — one unbounded
close().awaitand a fire-and-forget spawn that let the test return mid-close — which is precisely the hazardsupport::shutdowndocuments. It now routes through that helper, so a stalled close is bounded and names its stage instead of parking until the 180s nextest backstop. Side benefit:support::shutdownreturns a panicking server task'sJoinError, so a panic in the accept loop itself now fails the test that spawned it rather than being discarded by.abort(). That does not extend toDhtHandler: this file's loop detaches a task per connection and swallows its result, so a handler panic is still not carried byaccept_task—support::shutdown's own docs call that shape out.The one call site where teardown is not teardown is hardened separately.
dead.shutdown()infind_providers_tolerates_unreachable_peerestablishes the scenario's precondition, andsupport::shutdownwarns rather than fails on a breach (it must — the stranded-driver half is #1675). On a breach the dead peer would stay up and the test would pass having exercised nothing, soTestServer::shutdownnow checksEndpoint::is_closedafter the bounded close.Separately,
SHUTDOWN_TIMEOUT(10s) equalledABANDON_DRAIN_CAP(10s). One ceilinged abandon drain could consume the entire test teardown budget before the firstep.close()was attempted, and the breach line would then report0/M endpoints closedfor a run in which nothing was wedged — a false stranded-driver reading on the one channel that keeps #1675 visible. Raised to clear the drain cap.Measured, not asserted
Three runs — plain, under 12 spinning background loops, and under
cargo llvm-cov nextest— on a 14-core darwin box:bucket_overflow_……converges_after_peer_departs…converges_via_closer_nodes_second_round…negative_cache_expires_after_ttl…tolerates_unreachable_peer(Those figures are the pre-fix baseline. After the change
…negative_cache_expires_after_ttlcosts 0.42s and…tolerates_unreachable_peeris unchanged at ~6.39s.)Worth being precise: the hang-guard mis-sizing is demonstrated; the negative-cache race is latent, not reproduced. Coverage amplification on this box is only ~1.2–1.4×, leaving roughly a 5× margin on the quantity at risk, and I could not make it fail locally. It is still worth taking because CI is a 4-core runner executing the whole workspace under
llvm-cov— a far harsher amplifier — #1673 was attributed to exactly that starvation, and this fix makes the suite faster, so it costs nothing.Deliberately not in this PR
retries— this repo's practice is one issue per flake with a real diagnosis (flaky: probe_rate_limit_returns_rate_limited_close_code races on the application close code (sees 0 instead of 16) #1594, Flaky serve-miss coalescing tests under CI coverage contention (early-eof / peer hang, B3 #1656) #1673, Flaky deadlock: node-origin pull-leg abandon-drain races Endpoint::close(), hangstestjob under CI load (node_origin_pull::a_probe_cache_hit_drops_a_provider_no_longer_admitted) #1718, flaky(ci): node_origin_pull::a_wedged_channel_open_does_not_starve_the_candidate_loop burns the 300s nextest backstop, reddeningteston main (#1718 stopgap does not bound it) #1779, flaky: two_concurrent_pulls_to_one_provider_share_the_channel_ledger fails under coverage instrumentation #1826). Retries would mask that signal.crates/node/tests/dht_lookup.rscarries the identical unbounded fire-and-forget teardown. Same defect, different binary, not implicated here → filed as test(node): dht_lookup.rs tears endpoints down unbounded and fire-and-forget #1831.Review follow-ups
Six findings from the review are closed in
test(node,client-pull): close the #1832 review findings. Two are behavioural — the precondition hardening above, and movingCONVERGENCE_ROUND_TIMEOUT > DHT_CLIENT_TIMEOUTout of prose into aconst _: () = assert!(the same shapenode_originuses to pinREFUSAL_SUPPRESSION_TTL's ceiling). The other four correct comments that asserted things the code does not do: the two-round derivation above,with_capacity_and_ttl's doc prescribing against three of its own module's unit tests,SHUTDOWN_TIMEOUT's claim to track a private constant in another crate, and thedriver.rsclaim to pin single-writer with a work future that holds no&storeand cannot flush.Four out-of-scope items are filed as #1840, including a pre-existing load-flake in
client-pull's scheduler suite that reproduces on cleanmain.Verification
cargo clippy --workspace --all-targets -- -D warnings— cleancargo fmt -- --check— cleancargo doc -p decdn-node --no-deps— cleancargo nextest run -p decdn-node --no-fail-fast— 1038/1038 passing, noSLOWlines, noteardown exceededlinesdht_integrationgreen 20/20 in a repeat loopcargo llvm-cov nextest -p decdn-node --test dht_integration— green🤖 Generated with Claude Code