Răsfoiți Sursa

watch: fix a flaky test by ignoring spurious events correctly (#162)

Nick Santos 7 ani în urmă
părinte
comite
4801d2b1a4
2 a modificat fișierele cu 4 adăugiri și 3 ștergeri
  1. 1 0
      pkg/watch/notify_test.go
  2. 3 3
      pkg/watch/watcher_darwin.go

+ 1 - 0
pkg/watch/notify_test.go

@@ -231,6 +231,7 @@ func TestSingleFile(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
+	f.fsync()
 
 	d2 := []byte("hello\nworld\n")
 	err = ioutil.WriteFile(path, d2, 0644)

+ 3 - 3
pkg/watch/watcher_darwin.go

@@ -34,7 +34,7 @@ func (d *darwinNotify) isTrackingPath(path string) bool {
 }
 
 func (d *darwinNotify) loop() {
-	ignoredSpuriousEvent := false
+	ignoredSpuriousEvents := make(map[string]bool, 0)
 	for {
 		select {
 		case <-d.stop:
@@ -50,8 +50,8 @@ func (d *darwinNotify) loop() {
 				// ignore the first event that says the watched directory
 				// has been created. these are fired spuriously on initiation.
 				if e.Flags&fsevents.ItemCreated == fsevents.ItemCreated {
-					if d.isTrackingPath(e.Path) && !ignoredSpuriousEvent {
-						ignoredSpuriousEvent = true
+					if !ignoredSpuriousEvents[e.Path] && d.isTrackingPath(e.Path) {
+						ignoredSpuriousEvents[e.Path] = true
 						continue
 					}
 				}