test(caching): fix flaky BackgroundRevalidationCoordinator tests - #10
Merged
Merged
Conversation
Two tests assumed a fixed delay was enough for a background refresh's finally block to release its key before the next Schedule call — flaky under CI/parallel-test thread-pool contention (observed: 1/369 locally, 368/369 passed). Add BackgroundRevalidationCoordinator.IsScheduled(key), an internal read-only accessor, so tests can poll the actual invariant instead of guessing a timing window. Retrying the Schedule call itself (my first attempt at a fix) was wrong in a more interesting way: Schedule is not idempotent — every successful call starts a new background task — so retrying it inside a polling loop double-counted completions and made the flakiness worse, timing out instead of asserting a wrong number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Found while running the pre-release test suite for v2.2.2:
Schedule_WhenRefreshThrows_ReleasesTheKeyfailed once in an otherwise-clean run (368/369), and repeated stress runs reproduced it inSchedule_AfterPreviousRefreshCompletes_StartsAgaintoo. Both tests, added in PR #8, assumed a fixedTask.Delaywindow was long enough for a background refresh'sfinallyblock to release its key before the test scheduled another one — not reliable under CI/parallel-test thread-pool contention.Changes
BackgroundRevalidationCoordinator.IsScheduled(string key)— new internal, read-only accessor so tests can poll the actual "is this key still claimed" invariant instead of guessing a timing window.WaitUntilAsync), bounded at ~2s, instead of a single fixed sleep.Worth flagging my own mistake along the way: my first attempt at this fix retried the
Schedulecall itself inside the polling loop.Scheduleis not idempotent — every successful call starts a new background task — so retrying it re-triggered work and over-counted completions, which made the test time out instead of failing cleanly. The fix here polls a side-effect-free condition and callsScheduleexactly once per logical step.Verification
--filter FullyQualifiedName~BackgroundRevalidationCoordinator), where the pre-fix version failed within the first handful of runs.dotnet build Stampede.Http.slnx --no-incremental: 0 warnings, 0 errorsNo product code behavior changes —
IsScheduledis additive and test-only in practice, gated behindinternal+ the existingInternalsVisibleTo Stampede.Http.Tests.🤖 Generated with Claude Code