mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +00:00
Increase sleeps in WatchConfig test because travis-ci wasn't as fast as my laptop.
I'd love any input on how to reliably perform the test with no sleeps!
This commit is contained in:
parent
bab97b4ec3
commit
a0ade1f92b
1 changed files with 3 additions and 3 deletions
|
@ -814,7 +814,7 @@ func TestWatchConfig(t *testing.T) {
|
||||||
assert.Equal(t, `value is before`, v.GetString(`key`), "viper did not see the correct initial value for the config file.")
|
assert.Equal(t, `value is before`, v.GetString(`key`), "viper did not see the correct initial value for the config file.")
|
||||||
|
|
||||||
// Set up a context with deadline so we won't wait forever if we don't see a change.
|
// Set up a context with deadline so we won't wait forever if we don't see a change.
|
||||||
ctx, cancel = context.WithTimeout(context.Background(), 100*time.Millisecond)
|
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Turn on watch config.
|
// Turn on watch config.
|
||||||
|
@ -826,7 +826,7 @@ func TestWatchConfig(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// XXX: I'm not sure why, but if we don't sleep, the watcher won't see a change that happens immediately after WatchConfig() is called.
|
// XXX: I'm not sure why, but if we don't sleep, the watcher won't see a change that happens immediately after WatchConfig() is called.
|
||||||
time.Sleep(50 * time.Millisecond)
|
time.Sleep(1 * time.Second)
|
||||||
t.Log("Writing changed value to ", tmpfile.Name())
|
t.Log("Writing changed value to ", tmpfile.Name())
|
||||||
|
|
||||||
// Not sure if the TRUNC is necessary, but basically re-open the file so we can change it.
|
// Not sure if the TRUNC is necessary, but basically re-open the file so we can change it.
|
||||||
|
@ -852,7 +852,7 @@ func TestWatchConfig(t *testing.T) {
|
||||||
// Canceling turns off the fsevent Watcher so even if we end up starting a new viper instance (or calling viper.Reset()) we won't pick up spurious change events.
|
// Canceling turns off the fsevent Watcher so even if we end up starting a new viper instance (or calling viper.Reset()) we won't pick up spurious change events.
|
||||||
v.CancelWatchConfig()
|
v.CancelWatchConfig()
|
||||||
// XXX: I'm not sure why, but if we don't sleep, the watcher might not fully close down before the next event happens. Doesn't affect this test, but can cause an error on the next one.
|
// XXX: I'm not sure why, but if we don't sleep, the watcher might not fully close down before the next event happens. Doesn't affect this test, but can cause an error on the next one.
|
||||||
time.Sleep(50 * time.Millisecond)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
// Now we make one more change to the file to verify the viper config doesn't pick up the change.
|
// Now we make one more change to the file to verify the viper config doesn't pick up the change.
|
||||||
tmpfile, err = os.OpenFile(tmpfile.Name(), os.O_TRUNC|os.O_RDWR, 0644)
|
tmpfile, err = os.OpenFile(tmpfile.Name(), os.O_TRUNC|os.O_RDWR, 0644)
|
||||||
|
|
Loading…
Reference in a new issue