From 0fe3ae7c227686ac209cffb3622ff7d4ed8543ab Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 28 Jan 2018 10:44:43 +0000 Subject: [PATCH] lib/fs: Unflake watch tests (fixes #4687) This removes a number of timing related things, leaving just the total test timeout now bumped to one minute. Normally we get the filesystem events within a second or so, so this doesn't affect the test time in the successfull case. If we don't actually get the events we expect within a minute I think we are legitimately in "failed" territory. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4715 LGTM: imsodin, AudriusButkevicius --- lib/fs/basicfs_watch_test.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/fs/basicfs_watch_test.go b/lib/fs/basicfs_watch_test.go index 51128052..5f351fdc 100644 --- a/lib/fs/basicfs_watch_test.go +++ b/lib/fs/basicfs_watch_test.go @@ -92,7 +92,9 @@ func TestWatchRename(t *testing.T) { destEvent, } - testScenario(t, name, testCase, expectedEvents, false, "") + // set the "allow others" flag because we might get the create of + // "oldfile" initially + testScenario(t, name, testCase, expectedEvents, true, "") } // TestWatchOutside checks that no changes from outside the folder make it in @@ -193,16 +195,10 @@ func testScenario(t *testing.T, name string, testCase func(), expectedEvents []E if err := testFs.MkdirAll(name, 0755); err != nil { panic(fmt.Sprintf("Failed to create directory %s: %s", name, err)) } - - // Tests pick up the previously created files/dirs, probably because - // they get flushed to disk with a delay. - initDelayMs := 500 - if runtime.GOOS == "darwin" { - initDelayMs = 2000 - } - sleepMs(initDelayMs) + defer testFs.RemoveAll(name) ctx, cancel := context.WithCancel(context.Background()) + defer cancel() if ignored != "" { ignored = filepath.Join(name, ignored) @@ -215,23 +211,13 @@ func testScenario(t *testing.T, name string, testCase func(), expectedEvents []E go testWatchOutput(t, name, eventChan, expectedEvents, allowOthers, ctx, cancel) - timeoutDuration := 2 * time.Second - if runtime.GOOS == "darwin" { - timeoutDuration *= 2 - } - timeout := time.NewTimer(timeoutDuration) - testCase() select { - case <-timeout.C: + case <-time.NewTimer(time.Minute).C: t.Errorf("Timed out before receiving all expected events") - cancel() - case <-ctx.Done(): - } - if err := testFs.RemoveAll(name); err != nil { - panic(fmt.Sprintf("Failed to remove directory %s: %s", name, err)) + case <-ctx.Done(): } }