From 33144c58d403d790f81d0e3cd6c32a99c8cc90c1 Mon Sep 17 00:00:00 2001 From: Kadir Mert Okumus Date: Thu, 22 Oct 2026 15:23:54 +0300 Subject: [PATCH] Keep the freshness walks and the probe gate test steady under load (N115) The freshness cases lift the deadline of their own walks to ten minutes (on the limits passed to the call; the config keeps the 60 s `validate` accepts), so a loaded machine cannot cut a map into an empty answer. A map that still runs out of time fails `assert_no_timeout`. `cargo_gets_only_the_budget_the_gate_wait_left` waits on the gate's sleep counter and asserts cargo's timeout against the measured hold, with no wall-clock margin. Mutating `left.min(..)` to `timeout.min(..)` makes it fail. Co-Authored-By: Claude Opus 5.5 --- lci-maps/src/probe_map/tests.rs | 34 ++++++++++++++++++++------------- tests/cases/freshness.rs | 17 ++++++++++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/lci-maps/src/probe_map/tests.rs b/lci-maps/src/probe_map/tests.rs index 197c819d..72535ea0 100644 --- a/lci-maps/src/probe_map/tests.rs +++ b/lci-maps/src/probe_map/tests.rs @@ -621,33 +621,41 @@ fn cargo_gets_only_the_budget_the_gate_wait_left() { )); let helper = node_named(&map.inner.scip, "helper"); - // Another probe holds the gate for the first 2 s of this one's budget. The - // hold starts only once the probe thread runs, and the 1 s margin covers a - // loaded machine delaying the probe between that signal and its deadline. - let budget = Duration::from_millis(5000); + // Another probe holds the gate while this one waits. The budget is well + // under the cargo cap (30 s), so the cap cannot be what limits cargo, and + // well above the hold, so a loaded machine delaying the probe cannot spend + // it all (no wall-clock margin is assumed). + let budget = Duration::from_secs(20); let held = map .inner .gate .acquire(Instant::now() + WAIT) .expect("the gate is free"); - let (started, running) = std::sync::mpsc::channel(); let probe = { let (map, helper) = (map.clone(), helper.clone()); - std::thread::spawn(move || { - started.send(()).unwrap(); - map.edges_blocking(&helper, budget) - }) + std::thread::spawn(move || map.edges_blocking(&helper, budget)) }; - running.recv().unwrap(); - std::thread::sleep(Duration::from_millis(2000)); + // The sleep counter moves after the probe took its deadline, so the + // instant seen here is never before the start of the probe's budget. + let give_up = Instant::now() + WAIT; + while map.inner.gate.sleeps.load(Ordering::SeqCst) == 0 { + assert!(Instant::now() < give_up, "the probe never waited"); + std::thread::yield_now(); + } + let waiting_since = Instant::now(); + std::thread::sleep(Duration::from_millis(1000)); + let released = Instant::now(); drop(held); probe.join().unwrap(); + // The probe waited at least from `waiting_since` to `released`, however + // late it ran after that: cargo has at most the rest of the budget. + let held_for = released - waiting_since; let timeouts = lock(&timed.timeouts).clone(); assert_eq!(timeouts.len(), 1, "the probe should have run cargo once"); assert!( - timeouts[0] < Duration::from_millis(4000), - "cargo was given {:?} of a {budget:?} budget after it waited about 2 s for the gate", + timeouts[0] <= budget - held_for, + "cargo was given {:?} of a {budget:?} budget after the probe waited at least {held_for:?} for the gate", timeouts[0] ); } diff --git a/tests/cases/freshness.rs b/tests/cases/freshness.rs index 4231704b..a57a9e0e 100644 --- a/tests/cases/freshness.rs +++ b/tests/cases/freshness.rs @@ -361,6 +361,10 @@ fn git(root: &Path, args: &[&str]) { // ---- what a call showed ---------------------------------------------------- +/// The deadline of every walk of these cases: ten minutes, far above what a +/// loaded machine needs, so only a map that hangs reaches it. +const WALK_DEADLINE_MS: u64 = 600_000; + type Reached = BTreeMap>; type Edges = BTreeMap>; @@ -584,8 +588,8 @@ impl World { config.traverse.enabled = true; // The exact cards would otherwise start the walk from the probes. config.traverse.exact_seeds = false; - // The deadline only bounds a call: a language server that starts slowly - // on a loaded machine must not turn `lsp.live` into an empty answer. + // The most `validate` accepts; `World::run` lifts the deadline of the + // walks themselves to `WALK_DEADLINE_MS`. config.traverse.deadline_ms = 60_000; // The version probe of `lsp.live` is bounded by this (5 s failed under load). config.readiness_timeout_seconds = LOADED_BUDGET_SECONDS; @@ -740,12 +744,19 @@ impl World { } async fn run(&self, call: &Call<'_>) -> traverse::Report { + // A walk's deadline only bounds a call, and these cases check + // freshness, not speed: a loaded machine (ripgrep expansions of 10 s + // were seen) must not cut a map and turn it into an empty answer. A map that still runs out of time fails + // `assert_no_timeout` below. The lift is on the limits passed to the + // call; the config keeps the value `validate` accepts. + let mut limits = self.app.config.traverse.clone(); + limits.deadline_ms = WALK_DEADLINE_MS; let mut profile = self.app.config.run_profile.clone(); profile.traverse.map_freshness = self.labels; profile.freshness.verify_on_read = self.verify; profile.lsp.places = self.places; let report = traverse::run( - &self.app.config.traverse, + &limits, &profile, &Dirs::under(&self.app.config.data_dir), call,