Skip to content

test(cache): sample metrics before final read in refresh_dropped_when_hard_miss_races - #881

Draft
Dodothereal wants to merge 1 commit into
ExtendDB:mainfrom
Dodothereal:fix/877-cache-test-metrics-race
Draft

Dodothereal wants to merge 1 commit into
ExtendDB:mainfrom
Dodothereal:fix/877-cache-test-metrics-race

Conversation

@Dodothereal

Copy link
Copy Markdown

Summary

Fixes #877. In crates/cache/src/tests.rs, the test tests::refresh_dropped_when_hard_miss_races occasionally failed in CI when its final read (v4) started an asynchronous background refresh that completed before cache.metrics().snapshot() was called, resulting in refresh_success == 1 instead of 0.

Because soft_ttl is 50ms and the post-hard-miss entry (v3) was loaded ~150ms earlier, v4 is a stale hit and legitimately triggers a background refresh. Sampling metrics immediately after waiting for the slow refresh (n=2) finishes ensures the assertion only measures the dropped slow refresh. v4 is then read immediately after to verify that n=3 was preserved.

Validation

  • cargo fmt --check passed.
  • cargo test -p extenddb-cache --lib passed (27 tests passed in 0.42s).

Provenance

Prepared with AI assistance (Gemini 3.8 Flash) under contributor authorization. Draft status preserved pending review.

…_hard_miss_races

Fixes ExtendDB#877. In refresh_dropped_when_hard_miss_races, read the metrics
snapshot immediately after the slow refresh finishes rather than after
reading the post-hard-miss value. Because soft_ttl is 50ms and the post-
hard-miss entry is ~150ms old at the time of the read, the read was
triggering a background refresh that could finish and increment
refresh_success before metrics were sampled.

This branch has not been deployed

No deployments
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.

extenddb-cache: refresh_dropped_when_hard_miss_races fails when its last read starts a refresh

1 participant