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

Delta Between Two Patch Sets: src/pkg/exp/inotify/inotify_linux_test.go

Issue 5418045: code review 5418045: inotify: Fix readEntry hanging and Add/RemoveWatch fail... (Closed)
Left Patch Set: diff -r 6abf04c86097 https://code.google.com/p/go/ Created 12 years, 4 months ago
Right Patch Set: diff -r c8f7a5a37d09 https://code.google.com/p/go/ Created 12 years, 3 months 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/exp/inotify/inotify_linux.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 if event.Name == testFile { 119 if event.Name == testFile {
120 eventsReceived++ 120 eventsReceived++
121 t.Logf("event received: %s", event) 121 t.Logf("event received: %s", event)
122 } else if event.Mask&IN_IGNORED == IN_IGNORED { 122 } else if event.Mask&IN_IGNORED == IN_IGNORED {
123 //ignore· 123 //ignore·
124 } else { 124 } else {
125 unexpectedEvent = true 125 unexpectedEvent = true
126 t.Logf("unexpected event received: %s", event) 126 t.Logf("unexpected event received: %s", event)
127 } 127 }
128 } 128 }
129 println("watcher should be closed now")
130 done <- true 129 done <- true
131 }() 130 }()
132 131
133 go func() { 132 go func() {
134 for err1 := range watcher.Error { 133 for err1 := range watcher.Error {
135 t.Fatalf("Error received: %v", err1) 134 t.Fatalf("Error received: %v", err1)
136 } 135 }
137 }() 136 }()
138 137
139 createFn := func(removeAll bool, numGosched int, sleepNs int64) { 138 createFn := func(removeAll bool, numGosched int, sleepNs int64) {
(...skipping 10 matching lines...) Expand all
150 if removeAll { 149 if removeAll {
151 if err = os.RemoveAll(testdirpath); err != nil { 150 if err = os.RemoveAll(testdirpath); err != nil {
152 t.Fatalf("Unable to remove dir: %s. Error: %s", testdirpath, err) 151 t.Fatalf("Unable to remove dir: %s. Error: %s", testdirpath, err)
153 } 152 }
154 } 153 }
155 //give syscall sometime to auto-remove the directory 154 //give syscall sometime to auto-remove the directory
156 for j := 0; j < numGosched; j++ { 155 for j := 0; j < numGosched; j++ {
157 runtime.Gosched() 156 runtime.Gosched()
158 } 157 }
159 if sleepNs > 0 { 158 if sleepNs > 0 {
160 » » » time.Sleep(sleepNs) 159 » » » time.Sleep(time.Duration(sleepNs))
161 } 160 }
162 for j := 0; j < numGosched; j++ { 161 for j := 0; j < numGosched; j++ {
163 runtime.Gosched() 162 runtime.Gosched()
164 } 163 }
165 } 164 }
166 for i := 0; i < 2; i++ { 165 for i := 0; i < 2; i++ {
167 createFn(true, 0, 0) 166 createFn(true, 0, 0)
168 err = watcher.RemoveWatch(testdirpath) 167 err = watcher.RemoveWatch(testdirpath)
169 t.Logf("RemoveWatch() 1: expecting nil: received: %v", err) 168 t.Logf("RemoveWatch() 1: expecting nil: received: %v", err)
170 if err != nil { 169 if err != nil {
171 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)
172 } 171 }
173 //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
174 err = watcher.AddWatch(testdirpath, IN_CREATE|IN_DELETE) 173 err = watcher.AddWatch(testdirpath, IN_CREATE|IN_DELETE)
175 if err == nil { 174 if err == nil {
176 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",
177 testdirpath, err) 176 testdirpath, err)
178 } 177 }
179 } 178 }
180 createFn(true, 3, 3e8) 179 createFn(true, 3, 3e8)
181 err = watcher.RemoveWatch(testdirpath) 180 err = watcher.RemoveWatch(testdirpath)
182 if err != nil { 181 if err != nil {
183 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)
184 } 183 }
185 err = watcher.RemoveWatch(testdirpath) 184 err = watcher.RemoveWatch(testdirpath)
186 » 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)
187 if err == nil { 186 if err == nil {
188 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)
189 } else { 188 } else {
190 switch err.(type) { 189 switch err.(type) {
191 » » case *NoWatchExistError, NoWatchExistError: 190 » » case *noWatchExistError, noWatchExistError:
192 default: 191 default:
193 » » » t.Fatalf("Expecting NoWatchExistError. Got: %T, %v", err , err) 192 » » » t.Fatalf("Expecting noWatchExistError. Got: %T, %v", err , err)
194 } 193 }
195 } 194 }
196 195
197 // 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
198 time.Sleep(1e8) // 100 ms 197 time.Sleep(1e8) // 100 ms
199 if eventsReceived == 0 { 198 if eventsReceived == 0 {
200 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")
201 } else if unexpectedEvent { 200 } else if unexpectedEvent {
202 t.Fatal("Unexpected event received") 201 t.Fatal("Unexpected event received")
203 } 202 }
204 203
205 t.Log("calling Close()") 204 t.Log("calling Close()")
206 watcher.Close() 205 watcher.Close()
207 t.Log("waiting for the event channel to become closed...") 206 t.Log("waiting for the event channel to become closed...")
208 select { 207 select {
209 case <-done: 208 case <-done:
210 t.Log("event channel closed") 209 t.Log("event channel closed")
211 case <-time.After(5e9): 210 case <-time.After(5e9):
212 t.Fatal("event stream was not closed after 1 second") 211 t.Fatal("event stream was not closed after 1 second")
213 } 212 }
214 213
215 } 214 }
LEFTRIGHT

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