Skip to content

Commit d2d4d05

Browse files
nicksndeloof
authored andcommitted
Revert "watch: fix inotify tests on windows" (docker#3147)
This reverts commit 74ac7997b1c8f497babbbd499ff1f047563d699a.
1 parent dda0362 commit d2d4d05

File tree

3 files changed

+6
-47
lines changed

3 files changed

+6
-47
lines changed

pkg/watch/notify_test.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !windows
2+
13
package watch
24

35
import (
@@ -39,9 +41,6 @@ func TestNoWatches(t *testing.T) {
3941
}
4042

4143
func TestEventOrdering(t *testing.T) {
42-
if runtime.GOOS == "windows" {
43-
t.Skip("Skipping on windows for now")
44-
}
4544
f := newNotifyFixture(t)
4645
defer f.tearDown()
4746

@@ -74,9 +73,6 @@ func TestEventOrdering(t *testing.T) {
7473
// of directories, creates files in them, then deletes
7574
// them all quickly. Make sure there are no errors.
7675
func TestGitBranchSwitch(t *testing.T) {
77-
if runtime.GOOS == "windows" {
78-
t.Skip("Skipping on windows for now")
79-
}
8076
f := newNotifyFixture(t)
8177
defer f.tearDown()
8278

@@ -147,11 +143,10 @@ func TestWatchesAreRecursive(t *testing.T) {
147143
f.events = nil
148144
// change sub directory
149145
changeFilePath := filepath.Join(subPath, "change")
150-
h, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
146+
_, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
151147
if err != nil {
152148
t.Fatal(err)
153149
}
154-
defer h.Close()
155150

156151
f.assertEvents(changeFilePath)
157152
}
@@ -173,12 +168,10 @@ func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
173168

174169
// change something inside sub directory
175170
changeFilePath := filepath.Join(subPath, "change")
176-
h, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
171+
_, err := os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
177172
if err != nil {
178173
t.Fatal(err)
179174
}
180-
defer h.Close()
181-
182175
f.assertEvents(subPath, changeFilePath)
183176
}
184177

@@ -285,9 +278,6 @@ func TestSingleFile(t *testing.T) {
285278
}
286279

287280
func TestWriteBrokenLink(t *testing.T) {
288-
if runtime.GOOS == "windows" {
289-
t.Skip("Symlink creation requires admin privileges on Windows")
290-
}
291281
f := newNotifyFixture(t)
292282
defer f.tearDown()
293283

@@ -302,9 +292,6 @@ func TestWriteBrokenLink(t *testing.T) {
302292
}
303293

304294
func TestWriteGoodLink(t *testing.T) {
305-
if runtime.GOOS == "windows" {
306-
t.Skip("Symlink creation requires admin privileges on Windows")
307-
}
308295
f := newNotifyFixture(t)
309296
defer f.tearDown()
310297

@@ -324,9 +311,6 @@ func TestWriteGoodLink(t *testing.T) {
324311
}
325312

326313
func TestWatchBrokenLink(t *testing.T) {
327-
if runtime.GOOS == "windows" {
328-
t.Skip("Symlink creation requires admin privileges on Windows")
329-
}
330314
f := newNotifyFixture(t)
331315
defer f.tearDown()
332316

@@ -355,10 +339,6 @@ func TestWatchBrokenLink(t *testing.T) {
355339
}
356340

357341
func TestMoveAndReplace(t *testing.T) {
358-
if runtime.GOOS == "windows" {
359-
t.Skip("Skipping on windows for now")
360-
}
361-
362342
f := newNotifyFixture(t)
363343
defer f.tearDown()
364344

pkg/watch/watcher_naive.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9-
"runtime"
109

1110
"github.com/pkg/errors"
1211
"github.com/windmilleng/fsnotify"
@@ -136,7 +135,7 @@ func (d *naiveNotify) loop() {
136135
defer close(d.wrappedEvents)
137136
for e := range d.events {
138137
if e.Op&fsnotify.Create != fsnotify.Create {
139-
if d.shouldNotify(e.Name) && !isSpuriousWindowsDirChange(e) {
138+
if d.shouldNotify(e.Name) {
140139
d.wrappedEvents <- FileEvent{e.Name}
141140
}
142141
continue
@@ -263,22 +262,6 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*naiveNoti
263262
return wmw, nil
264263
}
265264

266-
// Windows' inotify implementation sometimes fires
267-
// of spurious WRITE events on directories when the
268-
// files inside change.
269-
func isSpuriousWindowsDirChange(e fsnotify.Event) bool {
270-
if runtime.GOOS != "windows" {
271-
return false
272-
}
273-
274-
if e.Op != fsnotify.Write {
275-
return false
276-
}
277-
278-
eIsDir, _ := isDir(e.Name)
279-
return eIsDir
280-
}
281-
282265
func isDir(pth string) (bool, error) {
283266
fi, err := os.Lstat(pth)
284267
if os.IsNotExist(err) {

pkg/watch/watcher_naive_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// +build !darwin
1+
// +build !darwin,!windows
22

33
package watch
44

55
import (
66
"fmt"
77
"os"
88
"os/exec"
9-
"runtime"
109
"strconv"
1110
"strings"
1211
"testing"
@@ -93,9 +92,6 @@ func TestDontWatchEachFile(t *testing.T) {
9392
f.events = nil
9493

9594
pid := os.Getpid()
96-
if runtime.GOOS == "windows" {
97-
return // skip the inotify count
98-
}
9995

10096
output, err := exec.Command("bash", "-c", fmt.Sprintf(
10197
"find /proc/%d/fd -lname anon_inode:inotify -printf '%%hinfo/%%f\n' | xargs cat | grep -c '^inotify'", pid)).Output()

0 commit comments

Comments
 (0)