Skip to content

test: assert the ledger cache invariants as ratios instead of wall-clock budgets - #54

Merged
ndr-ds merged 1 commit into
mainfrom
ndr-ds/gate-wallclock-perf-tests
Aug 10, 2026
Merged

ndr-ds merged 1 commit into
mainfrom
ndr-ds/gate-wallclock-perf-tests

Conversation

@ndr-ds

@ndr-ds ndr-ds commented Aug 10, 2026

Copy link
Copy Markdown

Motivation

Two ledger perf tests asserted wall-clock ceilings (< 200 ms for 9 cached queries, < 500 ms for a 50k-row eviction). A millisecond ceiling can't be calibrated once and stay meaningful:

Change

Both now assert the invariant they were written for, measured against a control on the same machine, so the number is portable:

  • perf_summarize_cached_stays_fast_with_many_rows → perf_summarize_cached_costs_far_less_than_parsing. Times one refresh_cache_from of the same 50k rows as the baseline, then requires 9 cached queries to cost less than half of it. The regression it guards (commit 0d6e2d3a, where every call linear-scanned the CSV) made each of the nine cost a whole parse, so the two can never be confused.
  • perf_eviction_stays_linear_with_many_rows keeps its name and now compares 25k rows against 50k on the same machine: linear doubles, quadratic quadruples, so a 3× ceiling separates them with room for scheduler noise.

seed_cache_with_synthetic_rows becomes write_synthetic_ledger(&Path, n), keeping the 30-day row spread so the day/week/month cutoffs still match distinct subsets. It takes the path rather than returning one because TestPaths deletes its tree on Drop — a helper owning the guard and handing back a PathBuf would return a path to a deleted directory, and a timing ratio over a missing ledger passes vacuously. That trap is now called out in the helper's doc comment.

Not in this PR

app::tests::perf_do_refresh_io_does_not_explode_with_repeated_calls gets the same treatment, but converting it to a cold-vs-warm ratio fails on real data — warm ticks cost about as much as the cold one (22.8 s vs 32.0 s in a sandbox; the host's 10.37 s for three calls implies the same flat shape). That is a real finding, not a test-calibration problem, so the rewritten test belongs in the same PR as its fix rather than landing red here. Filed separately.

Verification

$ cargo fmt --all -- --check                      # clean
$ cargo clippy --all-targets -- -D warnings       # clean
$ cargo test --lib usage_ledger::tests::perf      # 2 passed, in 1.88 s

Both pass inside the sandbox, where the versions they replace fail — which is the whole point.

@ndr-ds
ndr-ds marked this pull request as ready for review August 10, 2026 19:32
@ndr-ds
ndr-ds merged commit 36949f5 into main Aug 10, 2026
5 checks passed
@ndr-ds
ndr-ds deleted the ndr-ds/gate-wallclock-perf-tests branch August 10, 2026 19:32
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.

1 participant