From d2d4d05264bcd616be12949a12a2fa9b43b02369 Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Mon, 30 Mar 2020 13:24:49 -0400 Subject: [PATCH] Revert "watch: fix inotify tests on windows" (#3147) This reverts commit 74ac7997b1c8f497babbbd499ff1f047563d699a. --- pkg/watch/notify_test.go | 28 ++++------------------------ pkg/watch/watcher_naive.go | 19 +------------------ pkg/watch/watcher_naive_test.go | 6 +----- 3 files changed, 6 insertions(+), 47 deletions(-) diff --git a/pkg/watch/notify_test.go b/pkg/watch/notify_test.go index e873c94ee..1d3a7c05e 100644 --- a/pkg/watch/notify_test.go +++ b/pkg/watch/notify_test.go @@ -1,3 +1,5 @@ +// +build !windows + package watch import ( @@ -39,9 +41,6 @@ func TestNoWatches(t *testing.T) { } func TestEventOrdering(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping on windows for now") - } f := newNotifyFixture(t) defer f.tearDown() @@ -74,9 +73,6 @@ func TestEventOrdering(t *testing.T) { // of directories, creates files in them, then deletes // them all quickly. Make sure there are no errors. func TestGitBranchSwitch(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping on windows for now") - } f := newNotifyFixture(t) defer f.tearDown() @@ -147,11 +143,10 @@ func TestWatchesAreRecursive(t *testing.T) { f.events = nil // change sub directory changeFilePath := filepath.Join(subPath, "change") - h, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666) + _, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666) if err != nil { t.Fatal(err) } - defer h.Close() f.assertEvents(changeFilePath) } @@ -173,12 +168,10 @@ func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) { // change something inside sub directory changeFilePath := filepath.Join(subPath, "change") - h, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666) + _, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666) if err != nil { t.Fatal(err) } - defer h.Close() - f.assertEvents(subPath, changeFilePath) } @@ -285,9 +278,6 @@ func TestSingleFile(t *testing.T) { } func TestWriteBrokenLink(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Symlink creation requires admin privileges on Windows") - } f := newNotifyFixture(t) defer f.tearDown() @@ -302,9 +292,6 @@ func TestWriteBrokenLink(t *testing.T) { } func TestWriteGoodLink(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Symlink creation requires admin privileges on Windows") - } f := newNotifyFixture(t) defer f.tearDown() @@ -324,9 +311,6 @@ func TestWriteGoodLink(t *testing.T) { } func TestWatchBrokenLink(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Symlink creation requires admin privileges on Windows") - } f := newNotifyFixture(t) defer f.tearDown() @@ -355,10 +339,6 @@ func TestWatchBrokenLink(t *testing.T) { } func TestMoveAndReplace(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("Skipping on windows for now") - } - f := newNotifyFixture(t) defer f.tearDown() diff --git a/pkg/watch/watcher_naive.go b/pkg/watch/watcher_naive.go index 46f908288..2c61b7218 100644 --- a/pkg/watch/watcher_naive.go +++ b/pkg/watch/watcher_naive.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "path/filepath" - "runtime" "github.com/pkg/errors" "github.com/windmilleng/fsnotify" @@ -136,7 +135,7 @@ func (d *naiveNotify) loop() { defer close(d.wrappedEvents) for e := range d.events { if e.Op&fsnotify.Create != fsnotify.Create { - if d.shouldNotify(e.Name) && !isSpuriousWindowsDirChange(e) { + if d.shouldNotify(e.Name) { d.wrappedEvents <- FileEvent{e.Name} } continue @@ -263,22 +262,6 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*naiveNoti return wmw, nil } -// Windows' inotify implementation sometimes fires -// of spurious WRITE events on directories when the -// files inside change. -func isSpuriousWindowsDirChange(e fsnotify.Event) bool { - if runtime.GOOS != "windows" { - return false - } - - if e.Op != fsnotify.Write { - return false - } - - eIsDir, _ := isDir(e.Name) - return eIsDir -} - func isDir(pth string) (bool, error) { fi, err := os.Lstat(pth) if os.IsNotExist(err) { diff --git a/pkg/watch/watcher_naive_test.go b/pkg/watch/watcher_naive_test.go index d709d4d38..35ec894b8 100644 --- a/pkg/watch/watcher_naive_test.go +++ b/pkg/watch/watcher_naive_test.go @@ -1,4 +1,4 @@ -// +build !darwin +// +build !darwin,!windows package watch @@ -6,7 +6,6 @@ import ( "fmt" "os" "os/exec" - "runtime" "strconv" "strings" "testing" @@ -93,9 +92,6 @@ func TestDontWatchEachFile(t *testing.T) { f.events = nil pid := os.Getpid() - if runtime.GOOS == "windows" { - return // skip the inotify count - } output, err := exec.Command("bash", "-c", fmt.Sprintf( "find /proc/%d/fd -lname anon_inode:inotify -printf '%%hinfo/%%f\n' | xargs cat | grep -c '^inotify'", pid)).Output()