From: Chris Howey Date: Thu, 20 Oct 2011 01:02:06 +0000 (-0700) Subject: BSD: timing issues X-Git-Tag: v1.7.2~451 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=b62103f4d8d79cbd1300e0718a66d846c0cf258f;p=fsnotify.git BSD: timing issues --- diff --git a/fsnotify_bsd.go b/fsnotify_bsd.go index f94c27c..c018723 100644 --- a/fsnotify_bsd.go +++ b/fsnotify_bsd.go @@ -125,6 +125,9 @@ func (w *Watcher) addWatch(path string, flags uint32) os.Error { w.watches[path] = watchfd w.paths[watchfd] = path + + fi, _ := os.Stat(path) + w.finfo[watchfd] = fi } syscall.SetKevent(watchEntry, watchfd, syscall.EVFILT_VNODE, syscall.EV_ADD|syscall.EV_CLEAR) @@ -135,9 +138,6 @@ func (w *Watcher) addWatch(path string, flags uint32) os.Error { return &os.PathError{"kevent_add_watch", path, os.Errno(int(watchEntry.Data))} } - fi, _ := os.Stat(path) - w.finfo[watchfd] = fi - return nil } diff --git a/fsnotify_test.go b/fsnotify_test.go index 8e13979..51368d7 100644 --- a/fsnotify_test.go +++ b/fsnotify_test.go @@ -75,6 +75,8 @@ func TestFsnotifyDirOnly(t *testing.T) { f.Sync() f.Close() + time.Sleep(200e6) // give system time to sync write change before delete + os.Remove(testFile) // We expect this event to be received almost immediately, but let's wait 500 ms to be sure @@ -170,8 +172,6 @@ func TestFsnotifyRename(t *testing.T) { t.Fatalf("rename failed: %s", err) } - os.Remove(testFileRenamed) - // We expect this event to be received almost immediately, but let's wait 500 ms to be sure time.Sleep(500e6) // 500 ms if renameReceived == 0 { @@ -188,6 +188,8 @@ func TestFsnotifyRename(t *testing.T) { case <-time.After(1e9): t.Fatal("event stream was not closed after 1 second") } + + os.Remove(testFileRenamed) } func TestFsnotifyAttrib(t *testing.T) { @@ -258,8 +260,6 @@ func TestFsnotifyAttrib(t *testing.T) { t.Fatalf("chmod failed: %s", err) } - os.Remove(testFile) - // We expect this event to be received almost immediately, but let's wait 500 ms to be sure time.Sleep(500e6) // 500 ms if attribReceived == 0 { @@ -276,6 +276,8 @@ func TestFsnotifyAttrib(t *testing.T) { case <-time.After(1e9): t.Fatal("event stream was not closed after 1 second") } + + os.Remove(testFile) } func TestFsnotifyClose(t *testing.T) {