Repository navigation
test(cache): wait on the observed-store flush's completion, not a 2s file poll (#955) - #981
Merged
Merged
Conversation
…file poll (#955) The observed-upstreams store tests polled the persisted file for up to 2s after a change. The debounce under test is only 10ms; the real cost is the write behind it, file.WriteFileAtomic, which fsyncs the temp file and then the directory. On a loaded workstation disk those two fsyncs alone can exceed 2s, so the tests went red 6/6 locally while passing in CI. waitObservedFlush now waits on the store's own completion order: flushObservedUpstreams holds observedWriteMu across takeObservedSnapshot (which disarms the timer and clears the dirty bit) and the write. Once the timer is disarmed and nothing is dirty, acquiring observedWriteMu returns only after that write landed. The only bounded wait (30s) covers scheduling a 10ms timer, not I/O. The tests then read the file strictly. Test-only; no production change and no new seam. The tests still exercise the real debounce timer path. Closes #955 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
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.
Closes #955
Root cause
The issue suspected the 1s production debounce, but
newStoreTestCachealready setsobservedFlushDebounce = 10ms. The real cost sits behind the debounce:writeObservedUpstreams→file.WriteFileAtomicfsyncs the temp file and then the parent directory. On a loaded workstation disk (the output base is on/mnt/md0) those two fsyncs alone can take longer than the tests' 2sEventuallybudget. So the tests went red 6/6 locally and green in CI.Fix (test-only)
waitObservedFlush(t, c)waits on the store's own completion order instead of polling the file against a deadline:flushObservedUpstreamsholdsobservedWriteMuacross bothtakeObservedSnapshotand the write.takeObservedSnapshotis what disarms the timer and clearsobservedDirty.observedFlushTimer == nil && !observedDirty(read underdepMu), the pending change has been taken by a flush that holds, or already released,observedWriteMu. AcquiringobservedWriteMuthen returns only after that write has landed.flushFireWait = 30s) covers scheduling a 10ms timer, not I/O. After it, the tests read the file with strict assertions.No production change and no new seam: the helper reads existing unexported fields from the in-package test. The tests still go through the real debounce timer; they don't call
FlushObservedUpstreams()to short-circuit it.eventuallyWaitis removed.Evidence
--runs_per_test=20, idle workstation--runs_per_test=200/ race ×100, idle--config=race --runs_per_test=20time.Sleep(3s)beforeWriteFileAtomic(a slow fsync), ×5:150,:202,:227(the issue's lines) plus:100,:189On an idle machine the flake does not reproduce, so the slow-write experiment is the proof. It reproduces the issue's exact failure lines on the old tests, and the new tests pass against it. Full
//agent/internal/xds/cache:allpasses. Lint (--config=lint --@aspect_rules_lint//lint:fail_on_violation) and//:formatare clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr