Skip to content

test: calibrate the watchdog deadline and pin shutdown's teardown report - #1869

Merged
thiras merged 5 commits into
mainfrom
fix/watchdog-calibration-and-teardown-report
Aug 29, 2026
Merged

thiras merged 5 commits into
mainfrom
fix/watchdog-calibration-and-teardown-report

Conversation

@thiras

@thiras thiras commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #1840.

Rust-side hygiene + a teardown contract, covering all four of that issue's sub-items. Three independent changes on main's test/impl surface; wire-breaking shapes are untouched.

1. Load-flaky watchdog test (crates/client-pull)

wedged_source_is_ended_by_the_watchdog_and_its_tail_reassigned used a fixed 600 ms unit_deadline, which is load-flaky: a contended runner can move a checkpoint slower than that, so the healthy lane gets falsely reassigned.

calibrated_wedge_budget() times one ClientRangedStore::INGEST_CHECKPOINT_BYTES checkpoint through a fresh lane first, then sizes the deadline a factor (10×) above it — floored for fast machines, capped at 5 s. Both of the test's deadlines come from that one measurement: the outer bound is 4 × unit_deadline + 15 s, because a fixed bound against a scaled deadline only relocates the flake (the watchdog needs up to two windows to trip, and the surviving lane then refetches the wedged tail).

  • A calibration that trips its own watchdog — the pathologically slow machine this exists for — takes the ceiling rather than failing the test under a lane-fault message about the scheduler under test.
  • A capped safety factor prints the measured/wanted/capped triple, so a flake is diagnosable.
  • CHECKPOINT is derived from INGEST_CHECKPOINT_BYTES (now pub(crate)) instead of duplicating 4 * 1024 * 1024.

2. Teardown deadline → drain cap, and a ShutdownReport

  • ABANDON_DRAIN_CAP is exposed as a #[doc(hidden)] pub use; the abandon_drain module stays private, so the one constant the test needs is the only thing on the surface.
  • SHUTDOWN_TIMEOUT's docstring calls the 1.5× margin over the drain cap "the sole derivation of the number", so the compile-time assertion pins that ratio — in nanoseconds, since as_secs() truncates.
  • support::shutdown returns anyhow::Result<ShutdownReport>, carrying reaped/closed against the totals it was handed so is_clean() replaces a hardcoded endpoint count in the assertions. Existing callers use .await? and need no change (one direct-return caller updated).
  • shutdown_within(deadline, …) lets the helpers' own suite choose a deadline it can sit through; every other caller still gets SHUTDOWN_TIMEOUT.

The close tests run on the real clock, and that is load-bearing. A paused clock auto-advances past a deadline the instant the runtime idles, which manufactures a breach whatever the endpoint is doing — a paused close test passes with the stall removed, and with no connection at all. So:

  • shutdown_reports_a_stalled_close dials a real peer and strands the connection's driver on a dropped runtime, then asserts the breach (~2 s wall clock).
  • shutdown_reports_a_live_close_as_clean is its control: same endpoint, peer and deadline, driver left running, closes in ~0.08 s.

Flipping ConnDriver::Stranded → Live fails the breach test (ShutdownReport { closed: 1, of_endpoints: 1 }). That mutation is what makes the pair coverage of #1675 rather than of tokio's virtual clock.

The other half of the breach line is pinned too. shutdown_reports_a_task_that_outlives_its_abort covers reaped short of N — the reading that names this fixture's own defect rather than #1675. An abort only drops a task's future at its next poll, so a task that never yields never takes it; spawn_blocking parks one on a blocking-pool thread rather than wedging a runtime worker, and a start signal is awaited first to rule out the cancellation path. Swapping it for an abortable tokio::spawn(pending()) fails with ShutdownReport { reaped: 1, of_tasks: 1 }.

3. dht_integration.rs hygiene

Removed changelog voice from the header and renamed find_providers_negative_cache_expires_after_ttl to find_providers_stops_suppressing_once_the_negative_entry_expires.

Known gaps

  • ShutdownReport is not #[must_use]: it would fire at all 253 shutdown(…).await?; sites under -D warnings, and the fix at each is a let _ = that suppresses the lint it adds. A shutdown_expecting_clean() wrapper for the suites that care is the cheaper ratchet.

Verification

  • cargo nextest run --workspace — 3030/3030 pass
  • Teardown suite and wedge test also pass under saturating CPU load
  • cargo clippy --workspace --all-targets clean, cargo fmt --all -- --check clean, RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps clean

thiras added 3 commits August 29, 2026 23:35
…checkpoint cost

A fixed 600ms unit deadline is load-flaky: a contended runner can move 4MiB
slower than it, falsely reassigning the healthy lane. Time one checkpoint
through a fresh lane first, then rest the deadline a factor above it,
floored for fast machines and capped well under the 20s outer bound.
…n a ShutdownReport

Pin SHUTDOWN_TIMEOUT > ABANDON_DRAIN_CAP at compile time (mirroring the
CONVERGENCE_ROUND_TIMEOUT pattern) so a ceilinged drain can never consume
the whole budget. Have support::shutdown return a ShutdownReport carrying
the reaped/closed counts so a caller can assert on a breach rather than
only see the warning line, and pin both behaviors under start_paused: the
clean counts, and a stalled close (endpoint whose close() blocks on a
never-draining connection) that still yields Ok with closed < M.
The module header's 'introduced in PR #673' is changelog voice; state the
present capability. Rename find_providers_negative_cache_expires_after_ttl
to say what it asserts: the lookup stops suppressing once the negative
entry expires.
Copilot AI lite review requested due to automatic review settings August 29, 2026 20:40

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

This PR improves test reliability and teardown observability across decdn-client-pull and decdn-node, addressing flakiness and making teardown deadline breaches assertable rather than only logged.

Changes:

  • Calibrate the client-pull watchdog unit_deadline at runtime in the flaky scheduler test to reduce load sensitivity.
  • Add a compile-time invariant pin (SHUTDOWN_TIMEOUT > ABANDON_DRAIN_CAP) and return a ShutdownReport from support::shutdown so breach counts can be asserted in tests.
  • Clean up dht_integration.rs header wording (remove changelog voice) and rename a negative-cache test for accuracy.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/client-pull/src/scheduler.rs Adds calibrated_unit_deadline() and uses it in the watchdog reassignment test to reduce load flakiness.
crates/node/tests/support/mod.rs Adds compile-time teardown/drain cap ordering assertion and changes shutdown to return ShutdownReport.
crates/node/tests/support_teardown.rs Adds tests asserting clean shutdown counts and a stalled-close breach scenario under start_paused.
crates/node/tests/node_origin_pull.rs Updates a direct-return caller to account for shutdown() now returning a report.
crates/node/tests/dht_integration.rs Removes changelog voice from module header and renames a test to match behavior.
crates/node/src/node_origin/mod.rs Exposes abandon_drain module to allow integration tests to name the drain cap.
crates/node/src/node_origin/abandon_drain.rs Makes ABANDON_DRAIN_CAP public so integration tests can assert teardown invariants.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/tests/support_teardown.rs Resolved
@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.08% (was 82.07%, ▲ +0.01%) — 68127/83002 lines

File Coverage Lines Δ
crates/client-pull/src/ranged_store.rs 91.04% 1037/1139 ● 0.00%
crates/client-pull/src/scheduler.rs 92.66% 1325/1430 ▼ 0.08%
crates/node/src/node_origin/abandon_drain.rs 94.53% 121/128 ● 0.00%
crates/node/src/node_origin/mod.rs 92.86% 963/1037 ● 0.00%
History
Commit Total Δ vs base
aa48f14 82.07% ▲ +0.01%
2db1b3e (HEAD) 82.08% ▲ +0.01%

thiras and others added 2 commits August 30, 2026 00:30
…wedge budget

The close-path teardown test ran on a paused clock with its endpoint driver on
another thread. A paused clock auto-advances past the deadline the moment the
runtime idles, so the breach was manufactured by the clock rather than by the
stranded connection: the test passed with the whole strand apparatus removed,
and with no connection at all.

Run the close paths on the real clock under a caller-chosen deadline, and pair
the breach test with a control that dials the same peer and leaves the driver
running. Flipping the strand off now fails the breach test, which is what makes
it coverage of #1675 rather than of tokio's virtual clock.

ShutdownReport carries its own denominators so is_clean() replaces a hardcoded
endpoint total in the assertion, and the const assert pins the 1.5x margin its
prose calls the sole derivation of SHUTDOWN_TIMEOUT, in nanoseconds.

The wedge test's outer bound now rides on the same measurement as its unit
deadline — a fixed bound against a scaled deadline only relocates the flake —
the calibration takes the ceiling instead of failing the test under a lane-fault
message when it trips its own watchdog, and it says so on stderr when the
safety factor is capped. Its comment named a 20 s wedge; the wedge is 120 s.

ABANDON_DRAIN_CAP is a doc-hidden re-export rather than a public module, so the
one constant the test needs is the only thing exposed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EdRw9i5zQDZEmQQnr94LJ5
A stalled close pinned only the `closed` counter. The docstring claims both
readings, and `reaped` short of N is the diagnosis that names this fixture's own
defect rather than the stranded driver #1675 tracks.

An abort only drops a task's future at its next poll, so a task that never
yields never takes it. `spawn_blocking` parks one honestly, on a blocking-pool
thread rather than a runtime worker, and waiting on a start signal first rules
out the cancellation path that would reap cleanly instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EdRw9i5zQDZEmQQnr94LJ5
@thiras
thiras merged commit 8d8c424 into main Aug 29, 2026
48 of 50 checks passed
@thiras
thiras deleted the fix/watchdog-calibration-and-teardown-report branch August 29, 2026 22:02
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.

Follow-ups from the #1832 review: a client-pull scheduler flake, an unpinnable teardown invariant, and two test-hygiene items

2 participants