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
This commit is contained in:
Jakob Borg 2018-01-28 10:44:43 +00:00 committed by Audrius Butkevicius
parent 5d0eb80204
commit 0fe3ae7c22
1 changed files with 7 additions and 21 deletions

View File

@ -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():
}
}