Skip to content

Commit

Permalink
fixup! Watch for config file changes in fileprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Świątek committed Aug 23, 2022
1 parent 9df0776 commit f947437
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions confmap/provider/fileprovider/filewatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ func TestEventIfFileContentChanged(t *testing.T) {

watcher := newPollingFileWatcher(f.Name(), pollInterval)
require.NoError(t, watcher.Start())
assert.Nil(t, getEventWithTimeout(watcher.Events, pollInterval*2))
assert.Nil(t, getEventWithTimeout(watcher.Events, pollInterval*100))

// write to the file, we should get an event
_, err = f.WriteString("\n")
require.NoError(t, err)
event := getEventWithTimeout(watcher.Events, pollInterval*2)
event := getEventWithTimeout(watcher.Events, pollInterval*100)
require.NotNil(t, event)
require.Nil(t, event.Error)
}
Expand All @@ -98,12 +98,12 @@ func TestEventIfFileRemoved(t *testing.T) {

watcher := newPollingFileWatcher(f.Name(), pollInterval)
require.NoError(t, watcher.Start())
assert.Nil(t, getEventWithTimeout(watcher.Events, pollInterval*2))
assert.Nil(t, getEventWithTimeout(watcher.Events, pollInterval*100))

// remove the file, we should get an error event
err = os.Remove(f.Name())
require.NoError(t, err)
event := getEventWithTimeout(watcher.Events, pollInterval*2)
event := getEventWithTimeout(watcher.Events, pollInterval*100)
require.NotNil(t, event)
require.NotNil(t, event.Error)
}
Expand Down
6 changes: 4 additions & 2 deletions confmap/provider/fileprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ func TestWatcherConfigChange(t *testing.T) {
// change the file, we should get an update event
_, err = testFile.WriteString("\n")
require.NoError(t, err)
event := getEventWithTimeout(events, fp.filePollInterval*2)
event := getEventWithTimeout(events, fp.filePollInterval*100)
require.NotNil(t, event)
assert.Nil(t, event.Error)

// delete the file, we should get an error
err = testFile.Close()
require.NoError(t, err)
err = os.Remove(testFile.Name())
require.NoError(t, err)
event = getEventWithTimeout(events, fp.filePollInterval*2)
event = getEventWithTimeout(events, fp.filePollInterval*100)
require.NotNil(t, event)
assert.Error(t, event.Error)

Expand Down

0 comments on commit f947437

Please sign in to comment.