fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

search: deflake TestDirWatcherUnloadOnce (#1015)

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>

author
Keegan Carruthers-Smith
co-author
Amp
committer
GitHub
date (Mar 18, 2026, 4:03 PM +0200) commit 034d5a3e parent 55578289
+7 -2
+7 -2
search/watcher_test.go
··· 99 99 100 100 dw.Stop() 101 101 102 + // fsnotify can produce multiple events for a single write, which can lead to 103 + // extra queued load notifications by the time we stop. Drain them and only 104 + // assert we don't drop the same shard again. 105 + for len(logger.loads) > 0 { 106 + <-logger.loads 107 + } 108 + 102 109 select { 103 - case k := <-logger.loads: 104 - t.Errorf("spurious load of %q", k) 105 110 case k := <-logger.drops: 106 111 t.Errorf("spurious drops of %q", k) 107 112 default: