Skip to content

Commit

Permalink
Many files problem on OSX Sierra
Browse files Browse the repository at this point in the history
It seems like there is a problem with fsevents when dealing with a large amount
of files on OSX sierra this added test fails reliably on mac Macbook Pro, with
the error

```
2017-01-17 22:52 filemonitor.test[69205] (FSEvents.framework)
FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc()
=> (null) (-22)
```

This more or less reporduces #589 #605 #607 on the basis of this being related
to many files the fix would be to not monitor files individualy on OSX but
rather monitor directories and filter client side, this should reduce the number
of files / directories to be monitored.
  • Loading branch information
sideshowcoder committed Jan 17, 2017
1 parent efe6eea commit f85eee4
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions go/filemonitor/filemonitor_test.go
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/burke/zeus/go/filemonitor"
)

func writeTestFiles(dir string) ([]string, error) {
files := make([]string, 3)
func writeTestFiles(dir string, count int) ([]string, error) {
files := make([]string, count)

dir, err := filepath.EvalSymlinks(dir)
if err != nil {
Expand All @@ -35,14 +35,58 @@ func writeTestFiles(dir string) ([]string, error) {
return files, nil
}

func TestFileMonitorManyFiles(t *testing.T) {
count := 5000
dir, err := ioutil.TempDir("", "zeus_test_many_files")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

files, err := writeTestFiles(dir, count)
if err != nil {
t.Fatal(err)
}

fm, err := filemonitor.NewFileMonitor(filemonitor.DefaultFileChangeDelay)
if err != nil {
t.Fatal(err)
}
defer fm.Close()

watched := files[0:count]
for i, file := range watched {
err = fm.Add(file)
if err != nil {
t.Fatalf("%d, %v", i, err)
}
}

changes := fm.Listen()

// Without a short sleep we get notified for the original
// file creation using FSEvents
time.Sleep(20 * time.Millisecond)

for i, file := range files {
if err := ioutil.WriteFile(file, []byte("baz"), 0); err != nil {
t.Fatalf("%d: %v", i, err)
}
}

if err := expectChanges(changes, watched); err != nil {
t.Fatal(err)
}
}

func TestFileMonitor(t *testing.T) {
dir, err := ioutil.TempDir("", "zeus_test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

files, err := writeTestFiles(dir)
files, err := writeTestFiles(dir, 3)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit f85eee4

Please sign in to comment.