From a0ade1f92bc8fd2c6cf111edbcd9f7e2c62802c6 Mon Sep 17 00:00:00 2001 From: Daniel Einspanjer Date: Tue, 31 Jul 2018 18:37:44 -0400 Subject: [PATCH] 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! --- viper_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/viper_test.go b/viper_test.go index 06ba577..772e017 100644 --- a/viper_test.go +++ b/viper_test.go @@ -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.") // 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() // 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. - time.Sleep(50 * time.Millisecond) + time.Sleep(1 * time.Second) 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. @@ -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. 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. - 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. tmpfile, err = os.OpenFile(tmpfile.Name(), os.O_TRUNC|os.O_RDWR, 0644)