mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
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:
parent
5d0eb80204
commit
0fe3ae7c22
@ -92,7 +92,9 @@ func TestWatchRename(t *testing.T) {
|
|||||||
destEvent,
|
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
|
// 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 {
|
if err := testFs.MkdirAll(name, 0755); err != nil {
|
||||||
panic(fmt.Sprintf("Failed to create directory %s: %s", name, err))
|
panic(fmt.Sprintf("Failed to create directory %s: %s", name, err))
|
||||||
}
|
}
|
||||||
|
defer testFs.RemoveAll(name)
|
||||||
// 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)
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
if ignored != "" {
|
if ignored != "" {
|
||||||
ignored = filepath.Join(name, 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)
|
go testWatchOutput(t, name, eventChan, expectedEvents, allowOthers, ctx, cancel)
|
||||||
|
|
||||||
timeoutDuration := 2 * time.Second
|
|
||||||
if runtime.GOOS == "darwin" {
|
|
||||||
timeoutDuration *= 2
|
|
||||||
}
|
|
||||||
timeout := time.NewTimer(timeoutDuration)
|
|
||||||
|
|
||||||
testCase()
|
testCase()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-timeout.C:
|
case <-time.NewTimer(time.Minute).C:
|
||||||
t.Errorf("Timed out before receiving all expected events")
|
t.Errorf("Timed out before receiving all expected events")
|
||||||
cancel()
|
|
||||||
case <-ctx.Done():
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := testFs.RemoveAll(name); err != nil {
|
case <-ctx.Done():
|
||||||
panic(fmt.Sprintf("Failed to remove directory %s: %s", name, err))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user