Deflake the drop-abort freshness test with a deterministic gate - #6
Merged
Merged
Conversation
`dropping_speculative_sim_aborts_before_queueing_correction` assumed the SpeculativeSim's drop-abort would win a race against the spawned multi-thread validator's first poll, which fails intermittently under full-suite parallel load. Replace the racy "called" atomic flag with a `Gate` (Mutex + Condvar): the fetcher blocks until the test releases the gate, and the test releases it only *after* `drop(sim)` sets the cancel flag. So the validator's fetch — and thus its post-fetch, correction-queuing checkpoint — can only complete once cancellation is already observable, regardless of scheduler interleaving. Drops the over-strict "fetcher never reached" assertion (the product guarantees a cancel seen at a checkpoint suppresses side effects, not that an in-flight fetch is skipped) and keeps the real invariants: no correction queued, no re-run. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes the pre-existing flaky test
dropping_speculative_sim_aborts_before_queueing_correction(tests/freshness.rs), surfaced during the Phase 5 review: it passes in isolation but trips intermittently under full-suite parallel load. Stacked onphase-5-cow-snapshots; product code is untouched.Root cause
The test did
let sim = controller.run(...); drop(sim);and assumed theSpeculativeSim's drop-abort()would win a race against the spawnedmulti_threadvalidator's first poll — asserting (via acalledatomic) that the validator never even reached the fetcher. Under load the spawned task can reach the fetcher / queue a correction before the abort lands, so the assertion fails. The flakiness is in the test's timing assumption, not the product (the abort-on-drop behavior is correct).Fix
Replace the racy
calledflag with aGate(Mutex+Condvar,Send + Sync): the fetcher blocks until the test callsgate.release(), and the test releases it only afterdrop(sim)has set the cancel flag. So the validator's fetch — and therefore its post-fetch, correction-queuing checkpoint — can only complete once cancellation is already observable, regardless of how the scheduler interleaves the two threads. Drops the over-strict "fetcher never reached" assertion (the product guarantees a cancel seen at a checkpoint suppresses side effects, not that an in-flight fetch is skipped) and keeps the real invariants: no correction queued, no re-run.Verification
Deflaked test 10/10 under repeated runs; full
freshnesssuite green in both configs; full default suite clean. Test-only change (tests/freshness.rs+ theGate/gated_tracking_fetcherhelper intests/common/mod.rs).🤖 Generated with Claude Code