Browse Source

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
Jakob Borg 7 năm trước cách đây
mục cha
commit
0fe3ae7c22
1 tập tin đã thay đổi với 7 bổ sung21 xóa
  1. 7 21
      lib/fs/basicfs_watch_test.go

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