Repository navigation
test: size in-test polling deadlines for a loaded CI runner - #1852
Conversation
Two CI failures in the same ten-minute window were timing, not defects: cancelled_commit_never_exposes_the_empty_cache_slot hit its 10 s deadline on PR #1844 (it normally runs in 0.05 s and was green on re-run), and a time-travel test reached nextest's hard kill on main. An in-test deadline should bound a broken path, while the harness bounds hangs: nextest runs slow-timeout = 120s with terminate-after = 3, killing a hung test at 360 s. A 1-10 s in-test deadline is 36-360x less patient than the supervisor behind it, so a stalled runner reads as a failed assertion rather than a slow pass. These deadlines only elapse on failure, so raising them costs nothing on a green run. Covers both idioms present in the suite — an Instant deadline polled in a loop, and tokio::time::timeout around a future — plus the two reqwest connect_timeouts in the raft cluster harness. The cluster client's 10 s request timeout stays as it is, because the SSE test documents a dependency on that read timeout being short. Also widens the elapsed bound in propose_connect_timeout_is_retryable, which measured 5.212 s against a 7 s bound on CI. Ten seconds still proves the 5 s connect budget rather than the 15 s request timeout ended the wait, with room for a loaded runner.
aaj3f
left a comment
There was a problem hiding this comment.
✅ Approve with nits.
This is a really clean piece of flake work, @bplatz — and the framing in the body is the part I'd want other people to copy: an in-test deadline should bound a broken path while the harness bounds hangs, and once you say it that way the 36–360× gap against nextest's 120s × 3 supervisor makes every one of these budgets obviously wrong. I checked .config/nextest.toml and the arithmetic holds, and all eight resized deadlines only elapse on a failing run, so none of this costs anything green. What earned the most trust, though, is that you flagged the one assertion where widening genuinely costs detection power instead of letting it slide — I mutated it, and the caveat is accurate to the second: removing .connect_timeout(...) at forward.rs:1178 passes at the new 10 s bound and fails at the old 7 s bound with 7.917914916s. My two notes are both optional: raft_multi_node.rs:173's connect budget is now exactly equal to the request timeout on the line below it, so it no longer expresses a distinct budget; and I wonder whether a cfg(target_os = "macos") split is worth it to keep local mutation detection on a Mac, though I can argue myself out of that one.
Adherence to repo commitments:
- Patterns/abstractions: ✔ Covers both deadline idioms already in the suite (polled
Instant,tokio::time::timeout) rather than introducing a third; no new helper where none was needed. - Performance (speed first, memory second): ✔ Test-only, no shipping path touched, and every widened deadline elapses only on failure — no green-run cost and no regression risk.
- Testing: ✔
propose_suite 4/4 green at 5.22 s; the raft-gated targets are declared (grp_raft) and bothfluree-db-apiandfluree-db-servercarry aharness_coverage.rs, so nothing here compiles to a silently-empty binary under CI's--all-features. - Conventions: ✔ Multi-line body that reasons from the mechanism,
cargo fmt --all --checkclean, all CI jobs green, and the two deliberate exclusions are named with the line that justifies them.
Verified locally at branch HEAD 6290dedb7: cargo test -p fluree-raft-core --all-features --lib -- propose_ → 4 passed (5.22 s); mutation of forward.rs:1178 passes at 10 s / fails at 7 s with 7.917914916s, restored byte-identical; cargo fmt --all -- --check clean; gh pr checks 1852 all green.
Approving so you can merge whenever you're ready — the raft_multi_node.rs:173 one is the only note I'd actually like to see land with it.
|
|
||
| let client = reqwest::Client::builder() | ||
| .connect_timeout(Duration::from_secs(2)) | ||
| .connect_timeout(Duration::from_secs(10)) |
There was a problem hiding this comment.
Optional. This is more of a question than a suggestion. Raising connect_timeout to 10 s puts it exactly level with the .timeout(Duration::from_secs(10)) on the next line, and since both clocks start together on a fresh connection, the connect budget can no longer be the binding constraint — whichever timer wins is a coin flip, and the error kind for an unreachable node becomes nondeterministic between a connect error and a request timeout.
Nothing in the suite asserts on that classification today, so this is genuinely cosmetic in effect — but .connect_timeout(10) has stopped expressing a budget distinct from the one on the line below it. If the intent is "give a connect the same patience as a whole request," .timeout(10) already says that and the line could go; if the intent is "fail a dead node faster than a slow one," the value wants to be under 10 — 5 s absorbs the loaded runner you're aiming at while keeping the two budgets meaningfully different.
| .connect_timeout(Duration::from_secs(10)) | |
| .connect_timeout(Duration::from_secs(5)) |
I know this is pedantic, and it's minor and non-blocking — but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
There was a problem hiding this comment.
Agreed — changed to 5 s in 012a290, so the connect budget is distinct from the 10 s request timeout again. Full raft_multi_node module green locally.
| // margin absorbs a loaded runner while staying under the request cap. | ||
| assert!( | ||
| elapsed < RELAY_CONNECT_TIMEOUT + Duration::from_secs(2), | ||
| elapsed < RELAY_CONNECT_TIMEOUT * 2, |
There was a problem hiding this comment.
Optional — and thank you for flagging this yourself. Claude re-ran the mutation and your caveat is exactly right, to the second: with .connect_timeout(RELAY_CONNECT_TIMEOUT) removed at :1178, the test passes at the new 10 s bound (8.05 s), and fails at the old 7 s bound with connect budget did not bound the wait: 7.917914916s. So the macOS loss of detection is real and measured, not hypothetical.
For what it's worth I also chased the Linux half you marked as reasoned-not-measured, and I think the reasoning holds. With the accept queue full and tcp_abort_on_overflow=0, Linux drops the SYN and retransmits under tcp_syn_retries=6 — on the order of two minutes, well past the 15 s request cap this test passes in as RELAY_CONNECT_TIMEOUT * 3. That ends the request at the cap, relay_propose's classification at :1193-1198 only returns Relay when e.is_connect(), so the mutated run lands in Unknown and the matches!(result, Err(ProposeError::Relay(_))) assert at :698 — which runs first — catches it. CI keeps the net.
So the only thing actually lost is local detection on a Mac, and I wonder if that's cheap to keep. A cfg split would preserve it without touching CI's headroom:
#[cfg(target_os = "macos")]
let bound = RELAY_CONNECT_TIMEOUT + Duration::from_secs(2);
#[cfg(not(target_os = "macos"))]
let bound = RELAY_CONNECT_TIMEOUT * 2;
assert!(bound > elapsed, "connect budget did not bound the wait: {elapsed:?}");I'm genuinely torn on it, though — the green-path measurement is 5.22 s, so a 7 s bound on a loaded Mac is the same tightness you're trying to escape, just relocated. Happy to defer to you entirely; if you'd rather keep the single bound, the caveat paragraph in the body is doing the right job of recording why.
There was a problem hiding this comment.
Keeping the single bound — as you noted, 7 s on a loaded Mac reintroduces the tightness this PR removes, and the Linux classification assert keeps the net in CI. Thanks for measuring the Linux side.
|
|
||
| // Poll the cached handle's snapshot.t (the *indexed* t). | ||
| let deadline = Instant::now() + Duration::from_secs(2); | ||
| // Poll the cached handle's snapshot.t (the *indexed* t). The deadline |
There was a problem hiding this comment.
Praise. "The deadline bounds a broken path, not a loaded runner — nextest hard-kills a true hang at 360s, so a short budget here only buys flakes." That comment is the whole argument in two lines, and it's on the highest-traffic deadline in the suite (grp_misc, grp_query and others all reach it), which is exactly where the next person needs to read it. Worth keeping verbatim.
| // before we insert. | ||
| let sse_client = reqwest::Client::builder() | ||
| .connect_timeout(Duration::from_secs(2)) | ||
| .connect_timeout(Duration::from_secs(10)) |
There was a problem hiding this comment.
Praise. Leaving the sse_client without a .timeout() and leaving cluster.client's request cap alone, because :865 documents the coupling, is the right instinct — it would have been easy to sweep both to 60 s and quietly invalidate the comment that explains why the SSE test needs its own client at all.
… timeout At 10s the connect timeout matched the 10s request timeout on the same client, so it could never be the binding limit and an unreachable node surfaced as either error kind. 5s still absorbs a loaded runner.
Problem
Two CI failures inside the same ten-minute window last night were timing, not defects:
it_cached_handle_cow_cancel::cancelled_commit_never_exposes_the_empty_cache_slotfailed at its 10 s in-test deadline on fix(indexer): report cancelled join tasks as cancelled, not panicked #1844. It normally runs in 0.047–0.051 s, and the same code was green on re-run.it_branch_time_travel::merge_time_travel_survives_reload_from_commitsreached nextest's 360 s hard kill on main, turning the default branch red. It normally runs in ~0.1 s.Change
An in-test deadline should bound a broken path; the harness already bounds hangs.
.config/nextest.tomlrunsslow-timeout = 120swithterminate-after = 3, so a hung test is killed and reported at 360 s. A 1–10 s in-test deadline is 36–360× less patient than the supervisor behind it, so a stalled runner reads as a failed assertion instead of a slow pass.support/mod.rswait_for_index_applicationtto landit_cached_handle_cow_cancel.rsawait_commit_in_flightit_cached_handle_cow_cancel.rswait_for_ttraft_multi_node.rsSSE pollns-recordevent on the streamit_merge.rsit_merge.rsit_embedded_node.rsraft_multi_node.rsraft_multi_node.rsThese deadlines only elapse on failure, so no test gets slower on a green run, and a genuinely broken path still fails within 60 s — well inside the 360 s kill.
Two things deliberately left alone:
raft_multi_node.rs:865documents that the SSE test uses a separate client precisely because that read timeout is short; raising it would invalidate the comment and the coupling it describes.it_embedded_node.rs's bound is an upper bound by design — it proves a 20 ms ceiling fires before a 10 s probe — so it went to 3 s rather than 60 s, keeping it well under the probe it must beat.Also widened the elapsed bound in
propose_connect_timeout_is_retryablefromRELAY_CONNECT_TIMEOUT + 2stoRELAY_CONNECT_TIMEOUT * 2(7 s → 10 s). It measured 5.212 s on CI, leaving 1.79 s of margin against the same starvation. Ten seconds still proves the 5 s connect budget — not the 15 s request timeout — ended the wait.Caveat on that widened bound
With a 10 s bound, reverting
.connect_timeout(...)no longer fails the test on macOS, where the OS abandons a loopback SYN at ~7.8 s, inside the new bound. On Linux the connect hangs well past the 15 s request timeout, so the classification assertion (RelayvsUnknown) catches the mutation — and Linux is where CI runs. That macOS elapsed signal was always an accident of OS SYN behaviour rather than a designed guarantee. Verified on macOS; the Linux behaviour is reasoned from SYN-retransmit timing, not measured locally.Not addressed here, deliberately
merge_time_travel_survives_reload_from_commitsis untouched. It does not fail on an in-test deadline — it reaches the supervisor's hard kill, a ~3,600× outlier that indicates a hang under contention rather than a tight budget. Tuning anything there would hide it.Follow-up: #1851
Validation
Both raft-gated targets need
--features raft; without it they compile to zero tests and a filtered run reports success having executed nothing. CI reaches them viacargo nextest run --workspace --all-features.cargo fmt --all -- --check— clean.cargo clippy -p fluree-raft-core --all-features --all-targets --no-deps -- -D warnings— clean.cargo test -p fluree-raft-core --all-features --lib -- propose_— 4 passed, includingpropose_connect_timeout_is_retryableat 5.21 s against the new 10 s bound.cargo test -p fluree-db-api --test grp_transact— 204 passed (bothit_cached_handle_cow_canceldeadlines).cargo test -p fluree-db-api --test grp_ledger— 186 passed (it_merge, andit_branch_time_travelitself).cargo test -p fluree-db-api --test grp_misc— 295 passed;--test grp_query— 468 passed. Both exercise the changedwait_for_index_application.cargo test -p fluree-db-server --features raft --test grp_raft -- raft_multi_node— 12 passed, 1 ignored (timing_sequential_inserts_through_leader,#[ignore]on main).cargo test -p fluree-db-consensus --features raft --test it_embedded_node— 6 passed.