Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions lci-maps/src/probe_map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}
Expand Down
17 changes: 14 additions & 3 deletions tests/cases/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, BTreeSet<String>>;
type Edges = BTreeMap<String, BTreeSet<(String, String)>>;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading