LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package inotify | 5 package inotify |
6 | 6 |
7 import ( | 7 import ( |
8 "os" | 8 "os" |
9 "path/filepath" | 9 "path/filepath" |
10 "runtime" | 10 "runtime" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 if removeAll { | 149 if removeAll { |
150 if err = os.RemoveAll(testdirpath); err != nil { | 150 if err = os.RemoveAll(testdirpath); err != nil { |
151 t.Fatalf("Unable to remove dir: %s. Error: %s",
testdirpath, err) | 151 t.Fatalf("Unable to remove dir: %s. Error: %s",
testdirpath, err) |
152 } | 152 } |
153 } | 153 } |
154 //give syscall sometime to auto-remove the directory | 154 //give syscall sometime to auto-remove the directory |
155 for j := 0; j < numGosched; j++ { | 155 for j := 0; j < numGosched; j++ { |
156 runtime.Gosched() | 156 runtime.Gosched() |
157 } | 157 } |
158 if sleepNs > 0 { | 158 if sleepNs > 0 { |
159 » » » time.Sleep(sleepNs) | 159 » » » time.Sleep(time.Duration(sleepNs)) |
160 } | 160 } |
161 for j := 0; j < numGosched; j++ { | 161 for j := 0; j < numGosched; j++ { |
162 runtime.Gosched() | 162 runtime.Gosched() |
163 } | 163 } |
164 } | 164 } |
165 for i := 0; i < 2; i++ { | 165 for i := 0; i < 2; i++ { |
166 createFn(true, 0, 0) | 166 createFn(true, 0, 0) |
167 err = watcher.RemoveWatch(testdirpath) | 167 err = watcher.RemoveWatch(testdirpath) |
168 t.Logf("RemoveWatch() 1: expecting nil: received: %v", err) | 168 t.Logf("RemoveWatch() 1: expecting nil: received: %v", err) |
169 if err != nil { | 169 if err != nil { |
170 t.Fatalf("Unexpected Error in RemoveWatch() for path: %s
. Error: %v", testdirpath, err) | 170 t.Fatalf("Unexpected Error in RemoveWatch() for path: %s
. Error: %v", testdirpath, err) |
171 } | 171 } |
172 //do an add again at the end, to test that an add on a non-exist
ent file | 172 //do an add again at the end, to test that an add on a non-exist
ent file |
173 err = watcher.AddWatch(testdirpath, IN_CREATE|IN_DELETE) | 173 err = watcher.AddWatch(testdirpath, IN_CREATE|IN_DELETE) |
174 if err == nil { | 174 if err == nil { |
175 t.Fatalf("Expected error adding watch for non-existent p
ath: %s. Error: %s", | 175 t.Fatalf("Expected error adding watch for non-existent p
ath: %s. Error: %s", |
176 testdirpath, err) | 176 testdirpath, err) |
177 } | 177 } |
178 } | 178 } |
179 createFn(true, 3, 3e8) | 179 createFn(true, 3, 3e8) |
180 err = watcher.RemoveWatch(testdirpath) | 180 err = watcher.RemoveWatch(testdirpath) |
181 if err != nil { | 181 if err != nil { |
182 t.Fatalf("Unexpected Error in RemoveWatch() for path: %s. Error:
%v", testdirpath, err) | 182 t.Fatalf("Unexpected Error in RemoveWatch() for path: %s. Error:
%v", testdirpath, err) |
183 } | 183 } |
184 err = watcher.RemoveWatch(testdirpath) | 184 err = watcher.RemoveWatch(testdirpath) |
185 » t.Logf("RemoveWatch() 2: expecting *inotify.NoWatchExistError. received:
%T, %v", err, err) | 185 » t.Logf("RemoveWatch() 2: expecting *inotify.noWatchExistError. received:
%T, %v", err, err) |
186 if err == nil { | 186 if err == nil { |
187 t.Fatalf("Expecting an Error in RemoveWatch() for path: %s", tes
tdirpath) | 187 t.Fatalf("Expecting an Error in RemoveWatch() for path: %s", tes
tdirpath) |
188 } else { | 188 } else { |
189 switch err.(type) { | 189 switch err.(type) { |
190 » » case *NoWatchExistError, NoWatchExistError: | 190 » » case *noWatchExistError, noWatchExistError: |
191 default: | 191 default: |
192 » » » t.Fatalf("Expecting NoWatchExistError. Got: %T, %v", err
, err) | 192 » » » t.Fatalf("Expecting noWatchExistError. Got: %T, %v", err
, err) |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 // We expect this event to be received almost immediately, but let's wai
t 100 ms to be sure | 196 // We expect this event to be received almost immediately, but let's wai
t 100 ms to be sure |
197 time.Sleep(1e8) // 100 ms | 197 time.Sleep(1e8) // 100 ms |
198 if eventsReceived == 0 { | 198 if eventsReceived == 0 { |
199 t.Fatal("No inotify event hasn't been received after 1 second") | 199 t.Fatal("No inotify event hasn't been received after 1 second") |
200 } else if unexpectedEvent { | 200 } else if unexpectedEvent { |
201 t.Fatal("Unexpected event received") | 201 t.Fatal("Unexpected event received") |
202 } | 202 } |
203 | 203 |
204 t.Log("calling Close()") | 204 t.Log("calling Close()") |
205 watcher.Close() | 205 watcher.Close() |
206 t.Log("waiting for the event channel to become closed...") | 206 t.Log("waiting for the event channel to become closed...") |
207 select { | 207 select { |
208 case <-done: | 208 case <-done: |
209 t.Log("event channel closed") | 209 t.Log("event channel closed") |
210 case <-time.After(5e9): | 210 case <-time.After(5e9): |
211 t.Fatal("event stream was not closed after 1 second") | 211 t.Fatal("event stream was not closed after 1 second") |
212 } | 212 } |
213 | 213 |
214 } | 214 } |
LEFT | RIGHT |