Skip to content

Commit 2b35e17

Browse files
committed
fix: stabilize TestWatchFile on Windows
On Windows, fsnotify may deliver the write event before the file content is fully flushed, causing ReadInConfig to read stale data. Replace the direct equality assertion with assert.Eventually to poll for the expected value, giving the watcher time to pick up the final content.
1 parent 1a60ee6 commit 2b35e17

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

viper_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,12 @@ func TestWatchFile(t *testing.T) {
24622462
wg.Wait()
24632463
// then the config value should have changed
24642464
require.NoError(t, err)
2465-
assert.Equal(t, "baz", v.Get("foo"))
2465+
// On Windows, fsnotify may deliver the event before the file write is fully
2466+
// flushed, causing ReadInConfig to read stale content. Poll briefly to allow
2467+
// a subsequent event (or re-read) to pick up the new value.
2468+
assert.Eventually(t, func() bool {
2469+
return v.Get("foo") == "baz"
2470+
}, 5*time.Second, 10*time.Millisecond, "expected foo to be \"baz\"")
24662471
})
24672472

24682473
t.Run("link to real file changed (à la Kubernetes)", func(t *testing.T) {

0 commit comments

Comments
 (0)