History: resume the saved tracker at start; first build observations draw at once

The polling task never loaded the tracker the last run saved, so every
restart began again from a baseline and dropped what had not yet reached a
row. The empty bootstrap drawn at the first poll also started the one-minute
wait for the first real observations.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-28 12:34:30 -07:00
1 parent bcc178330b
commit c56aaefa72
3 files changed
+184 -16

No files matched your search

+170 -15
View File
@@ -576,9 +576,10 @@ fn the_bootstrap_is_not_redrawn_on_every_poll_of_a_build_in_flight() {
task.poll(&app, NOW);
assert_eq!(rust_builds(&app), 0, "nothing seen yet");
// A build adds one Rust build between every pair of polls. Each is stored at once, but the
// histogram (and with it the bootstrap) waits for the one-minute beat.
for step in 1..6u64 {
// A build adds one Rust build between every pair of polls. Each is stored at once. The first
// is drawn at the next poll (the empty draw before it started no wait); the rest wait for
// the one-minute beat that began with that draw.
for step in 1..7u64 {
fake.answers(&with_more_rust_builds(step));
task.poll(&app, NOW + (step as i64) * 10);
assert_eq!(
@@ -588,23 +589,23 @@ fn the_bootstrap_is_not_redrawn_on_every_poll_of_a_build_in_flight() {
);
assert_eq!(
rust_builds(&app),
0,
"but the bootstrap drawn at the first poll stands (step {step})"
1,
"the first draw stands for the minute (step {step})"
);
}
fake.answers(&with_more_rust_builds(6));
task.poll(&app, NOW + 60);
assert_eq!(
rust_builds(&app),
6,
"a minute after the last draw, everything seen so far is drawn in"
);
fake.answers(&with_more_rust_builds(7));
task.poll(&app, NOW + 70);
assert_eq!(
rust_builds(&app),
6,
7,
"a minute after the last draw, everything seen so far is drawn in"
);
fake.answers(&with_more_rust_builds(8));
task.poll(&app, NOW + 80);
assert_eq!(
rust_builds(&app),
7,
"and it stands again until the next beat"
);
}
@@ -647,7 +648,10 @@ fn a_full_history_costs_few_rows_on_the_second_poll() {
"the first reading is the baseline"
);
let observations = task.history.build_obs_stamp().unwrap().0;
assert_eq!(observations, 4_319, "one for every tenth minute after the baseline");
assert_eq!(
observations, 4_319,
"one for every tenth minute after the baseline"
);
task.poll(&app, NOW);
let first = app.lock().views_rows;
@@ -662,3 +666,154 @@ fn a_full_history_costs_few_rows_on_the_second_poll() {
let v = app.view(Range::Day);
assert_eq!(v.buckets.len(), 120);
}
/// What sccache prints after `k` more rounds of work: every round adds 3 requests, 2 hits and
/// 1 Rust miss that took 5 s to compile.
fn after_rounds(k: u64) -> String {
let mut v: serde_json::Value = serde_json::from_str(LIVE).unwrap();
let s = &mut v["stats"];
let add = |s: &mut serde_json::Value, key: &str, n: u64| {
s[key] = (s[key].as_u64().unwrap() + n).into();
};
add(s, "compile_requests", 3 * k);
add(s, "requests_executed", k);
add(s, "cache_writes", k);
add(s, "compilations", k);
s["cache_hits"]["counts"]["Rust"] = (229 + 2 * k).into();
s["cache_misses"]["counts"]["Rust"] = (3256 + k).into();
let secs = 25343 + 5 * k;
s["compiler_write_duration"]["secs"] = secs.into();
v.to_string()
}
/// Polls once a `step` seconds from `from` to `to`, the counters rising a round each time.
fn run_polls(
fake: &Fake,
app: &App,
task: &mut Task,
rounds: &mut u64,
span: (i64, i64),
step: i64,
) {
let mut t = span.0;
while t <= span.1 {
fake.answers(&after_rounds(*rounds));
task.poll(app, t);
*rounds += 1;
t += step;
}
}
#[test]
fn a_restart_loses_nothing_and_counts_nothing_twice() {
let fake = Fake::new();
let mut rounds = 0;
let app = App::with_probe(fake.config(), fake.probe());
let mut task = Task::open(&fake.history, NOW).unwrap();
// Five minutes of polls, every ten seconds, with work in each; the last 30 s after a row.
run_polls(&fake, &app, &mut task, &mut rounds, (NOW, NOW + 330), 10);
let before = app.view(Range::Day);
assert!(before.totals.requests > 0, "{:?}", before.totals);
assert!(
task.history.row_count().unwrap() >= 4,
"a row a minute on disk while it runs, not at the end: {}",
task.history.row_count().unwrap()
);
drop(task);
drop(app);
// The restart: a new process opens the same file and polls once, ten seconds later, with
// the same counters sccache had (no work in between).
let app = App::with_probe(fake.config(), fake.probe());
let mut task = Task::open(&fake.history, NOW + 340).unwrap();
rounds -= 1;
run_polls(
&fake,
&app,
&mut task,
&mut rounds,
(NOW + 340, NOW + 340),
10,
);
let after = app.view(Range::Day);
assert_eq!(
(after.totals, after.previous),
(before.totals, before.previous),
"a view's totals are the same just before and just after a restart"
);
}
#[test]
fn a_restart_counts_the_work_done_while_it_was_down() {
let fake = Fake::new();
let mut rounds = 0;
let app = App::with_probe(fake.config(), fake.probe());
let mut task = Task::open(&fake.history, NOW).unwrap();
run_polls(&fake, &app, &mut task, &mut rounds, (NOW, NOW + 200), 10);
let before = app.view(Range::Day).totals.requests;
drop(task);
drop(app);
// sccache went on working for 4 rounds while sccache-dash was stopped.
rounds += 3;
let app = App::with_probe(fake.config(), fake.probe());
let mut task = Task::open(&fake.history, NOW + 260).unwrap();
run_polls(
&fake,
&app,
&mut task,
&mut rounds,
(NOW + 260, NOW + 260),
10,
);
assert_eq!(
app.view(Range::Day).totals.requests,
before + 4 * 3,
"the difference since the last poll before the stop is counted, once"
);
}
#[test]
fn build_times_show_within_a_minute_of_the_observations() {
let fake = Fake::new();
let mut rounds = 0;
let app = App::with_probe(fake.config(), fake.probe());
let mut task = Task::open(&fake.history, NOW).unwrap();
// The first poll draws the (empty) bootstrap; the observations come after it.
run_polls(&fake, &app, &mut task, &mut rounds, (NOW, NOW + 600), 10);
let shown = |t: &Task| t.history.build_obs_stamp().unwrap().0;
assert!(shown(&task) >= 50, "observations were recorded");
let times = app.view(Range::Day).build_times;
assert_eq!(times.len(), 1, "Rust has a histogram after ten minutes");
// Stop polling for work: after one more poll a minute on, the newest are in too.
let seen = times[0].compiles;
run_polls(
&fake,
&app,
&mut task,
&mut rounds,
(NOW + 610, NOW + 680),
10,
);
let now = app.view(Range::Day).build_times[0].compiles;
assert!(now > seen, "the histogram keeps up: {seen} then {now}");
}
#[test]
fn the_first_observations_show_at_the_next_poll_not_a_minute_later() {
let fake = Fake::new();
let mut rounds = 0;
let app = App::with_probe(fake.config(), fake.probe());
let mut task = Task::open(&fake.history, NOW).unwrap();
// The first poll draws nothing: there is nothing to draw, and that must not start the
// minute's wait for the first real observations.
run_polls(&fake, &app, &mut task, &mut rounds, (NOW, NOW + 30), 10);
assert!(task.history.build_obs_stamp().unwrap().0 >= 3);
assert_eq!(
app.view(Range::Day).build_times.len(),
1,
"seconds after the first observation, not a minute"
);
}