]> go.fuhry.dev Git - fsnotify.git/commitdiff
BSD: timing issues
authorChris Howey <chris@howey.me>
Thu, 20 Oct 2011 01:02:06 +0000 (18:02 -0700)
committerChris Howey <chris@howey.me>
Thu, 20 Oct 2011 01:02:06 +0000 (18:02 -0700)
fsnotify_bsd.go
fsnotify_test.go

index f94c27ce29102f53c8986191910e924e1107fb8a..c018723b3daeab1f4010c5ec9945f48034dfb186 100644 (file)
@@ -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
 }
 
index 8e13979e3cbf23a12da832181862ce4682601290..51368d7a3092835fb3ad364aef3c6d2bf94ae706 100644 (file)
@@ -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) {