Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(83)

Side by Side Diff: src/pkg/exp/inotify/inotify_linux_test.go

Issue 6553059: code review 6553059: exp/inotify: cleanup ignored watch
Patch Set: diff -r 3836bcbafa69 https://code.google.com/p/go Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/exp/inotify/inotify_linux.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // +build linux 5 // +build linux
6 6
7 package inotify 7 package inotify
8 8
9 import ( 9 import (
10 "io/ioutil" 10 "io/ioutil"
(...skipping 18 matching lines...) Expand all
29 29
30 // Add a watch for "_test" 30 // Add a watch for "_test"
31 err = watcher.Watch(dir) 31 err = watcher.Watch(dir)
32 if err != nil { 32 if err != nil {
33 t.Fatalf("Watch failed: %s", err) 33 t.Fatalf("Watch failed: %s", err)
34 } 34 }
35 35
36 // Receive errors on the error channel on a separate goroutine 36 // Receive errors on the error channel on a separate goroutine
37 go func() { 37 go func() {
38 for err := range watcher.Error { 38 for err := range watcher.Error {
39 » » » t.Fatalf("error received: %s", err) 39 » » » t.Errorf("error received: %s", err)
40 } 40 }
41 }() 41 }()
42 42
43 testFile := dir + "/TestInotifyEvents.testfile" 43 testFile := dir + "/TestInotifyEvents.testfile"
44 44
45 // Receive events on the event channel on a separate goroutine 45 // Receive events on the event channel on a separate goroutine
46 eventstream := watcher.Event 46 eventstream := watcher.Event
47 var eventsReceived int32 = 0 47 var eventsReceived int32 = 0
48 done := make(chan bool) 48 done := make(chan bool)
49 go func() { 49 go func() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 case <-done: 98 case <-done:
99 case <-time.After(50 * time.Millisecond): 99 case <-time.After(50 * time.Millisecond):
100 t.Fatal("double Close() test failed: second Close() call didn't return") 100 t.Fatal("double Close() test failed: second Close() call didn't return")
101 } 101 }
102 102
103 err := watcher.Watch(os.TempDir()) 103 err := watcher.Watch(os.TempDir())
104 if err == nil { 104 if err == nil {
105 t.Fatal("expected error on Watch() after Close(), got nil") 105 t.Fatal("expected error on Watch() after Close(), got nil")
106 } 106 }
107 } 107 }
108 func TestInotifyIgnored(t *testing.T) {
109 watcher, err := NewWatcher()
110 if err != nil {
111 t.Fatalf("NewWatcher failed: %s", err)
112 }
113 defer watcher.Close()
114
115 dir, err := ioutil.TempDir("", "inotify")
116 if err != nil {
117 t.Fatalf("TempDir failed: %s", err)
118 }
119 err = watcher.Watch(dir)
120 if err != nil {
121 t.Fatalf("Watch failed: %s", err)
122 }
123 done := make(chan bool)
124 go func() {
125 for err := range watcher.Error {
126 t.Errorf("error received: %s", err)
127 }
128 t.Log("error channel closed")
129 done <- true
130 }()
131 go func() {
132 for event := range watcher.Event {
133 t.Logf("event received: %s", event)
134 }
135 t.Log("event channel closed")
136 }()
137 os.Remove(dir)
138 time.Sleep(50 * time.Millisecond)
139 // Check if the watch was removed by attempting to remove it explicitly
140 err = watcher.RemoveWatch(dir)
141 if err == nil || err.Error() != "can't remove non-existent inotify watch for: "+dir {
142 t.Error("expected removed watch")
143 }
144 watcher.Close()
145 select {
146 case <-done:
147 case <-time.After(50 * time.Millisecond):
148 t.Fatal("double Close() test failed: second Close() call didn't return")
149 }
150 }
OLDNEW
« no previous file with comments | « src/pkg/exp/inotify/inotify_linux.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b