Skip to content

search: deflake TestDirWatcherUnloadOnce#1015

Merged
keegancsmith merged 1 commit intomainfrom
k/dirwatcher-flake
Mar 18, 2026
Merged

search: deflake TestDirWatcherUnloadOnce#1015
keegancsmith merged 1 commit intomainfrom
k/dirwatcher-flake

Conversation

@keegancsmith
Copy link
Copy Markdown
Member

TestDirWatcherUnloadOnce occasionally failed in CI with a queued "spurious load" event after Stop().

This is expected under fsnotify: a single logical write can emit multiple filesystem events, and DirectoryWatcher can therefore enqueue extra load notifications before shutdown completes. The old assertion treated any leftover load event as a bug, which made the test timing-sensitive.

Update the test to drain queued load notifications after Stop() and keep asserting that no extra drop event is emitted. That preserves the behavior we care about (delete triggers unload, and unload is not repeated) while removing a brittle assumption about load event multiplicity.

Reproduced flake before with:
go test ./search -run TestDirWatcherUnloadOnce -count=500

Validated after change with:
go test ./search -run TestDirWatcherUnloadOnce -count=500

TestDirWatcherUnloadOnce occasionally failed in CI with a queued
"spurious load" event after Stop().

This is expected under fsnotify: a single logical write can emit multiple
filesystem events, and DirectoryWatcher can therefore enqueue extra load
notifications before shutdown completes. The old assertion treated any
leftover load event as a bug, which made the test timing-sensitive.

Update the test to drain queued load notifications after Stop() and keep
asserting that no extra drop event is emitted. That preserves the behavior
we care about (delete triggers unload, and unload is not repeated) while
removing a brittle assumption about load event multiplicity.

Reproduced flake before with:
  go test ./search -run TestDirWatcherUnloadOnce -count=500

Validated after change with:
  go test ./search -run TestDirWatcherUnloadOnce -count=500

Amp-Thread-ID: https://ampcode.com/threads/T-019d0104-367c-719f-a5f0-e7a95136407c
Co-authored-by: Amp <amp@ampcode.com>
@keegancsmith keegancsmith merged commit 034d5a3 into main Mar 18, 2026
8 checks passed
@keegancsmith keegancsmith deleted the k/dirwatcher-flake branch March 18, 2026 14:04
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.

2 participants