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

Side by Side Diff: src/pkg/net/timeout_test.go

Issue 7193044: all: use t.Skip{,f} (Closed)
Patch Set: diff -r 76dc0d7cec07 https://go.googlecode.com/hg/ Created 12 years, 2 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:
View unified diff | Download patch
« no previous file with comments | « src/pkg/net/tcp_test.go ('k') | src/pkg/net/udp_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 net 5 package net
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "io" 9 "io"
10 "io/ioutil" 10 "io/ioutil"
11 "runtime" 11 "runtime"
12 "testing" 12 "testing"
13 "time" 13 "time"
14 ) 14 )
15 15
16 func isTimeout(err error) bool { 16 func isTimeout(err error) bool {
17 e, ok := err.(Error) 17 e, ok := err.(Error)
18 return ok && e.Timeout() 18 return ok && e.Timeout()
19 } 19 }
20 20
21 type copyRes struct { 21 type copyRes struct {
22 n int64 22 n int64
23 err error 23 err error
24 d time.Duration 24 d time.Duration
25 } 25 }
26 26
27 func TestAcceptTimeout(t *testing.T) { 27 func TestAcceptTimeout(t *testing.T) {
28 switch runtime.GOOS { 28 switch runtime.GOOS {
29 case "plan9": 29 case "plan9":
30 » » t.Logf("skipping test on %q", runtime.GOOS) 30 » » t.Skipf("skipping test on %q", runtime.GOOS)
31 » » return
32 } 31 }
33 32
34 ln := newLocalListener(t).(*TCPListener) 33 ln := newLocalListener(t).(*TCPListener)
35 defer ln.Close() 34 defer ln.Close()
36 ln.SetDeadline(time.Now().Add(-1 * time.Second)) 35 ln.SetDeadline(time.Now().Add(-1 * time.Second))
37 if _, err := ln.Accept(); !isTimeout(err) { 36 if _, err := ln.Accept(); !isTimeout(err) {
38 t.Fatalf("Accept: expected err %v, got %v", errTimeout, err) 37 t.Fatalf("Accept: expected err %v, got %v", errTimeout, err)
39 } 38 }
40 if _, err := ln.Accept(); !isTimeout(err) { 39 if _, err := ln.Accept(); !isTimeout(err) {
41 t.Fatalf("Accept: expected err %v, got %v", errTimeout, err) 40 t.Fatalf("Accept: expected err %v, got %v", errTimeout, err)
(...skipping 26 matching lines...) Expand all
68 default: 67 default:
69 if err != errClosing { 68 if err != errClosing {
70 t.Fatalf("Accept: expected err %v, got %v", errClosing, err) 69 t.Fatalf("Accept: expected err %v, got %v", errClosing, err)
71 } 70 }
72 } 71 }
73 } 72 }
74 73
75 func TestReadTimeout(t *testing.T) { 74 func TestReadTimeout(t *testing.T) {
76 switch runtime.GOOS { 75 switch runtime.GOOS {
77 case "plan9": 76 case "plan9":
78 » » t.Logf("skipping test on %q", runtime.GOOS) 77 » » t.Skipf("skipping test on %q", runtime.GOOS)
79 » » return
80 } 78 }
81 79
82 ln := newLocalListener(t) 80 ln := newLocalListener(t)
83 defer ln.Close() 81 defer ln.Close()
84 c, err := DialTCP("tcp", nil, ln.Addr().(*TCPAddr)) 82 c, err := DialTCP("tcp", nil, ln.Addr().(*TCPAddr))
85 if err != nil { 83 if err != nil {
86 t.Fatalf("Connect: %v", err) 84 t.Fatalf("Connect: %v", err)
87 } 85 }
88 defer c.Close() 86 defer c.Close()
89 c.SetDeadline(time.Now().Add(time.Hour)) 87 c.SetDeadline(time.Now().Add(time.Hour))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 default: 122 default:
125 if err != errClosing { 123 if err != errClosing {
126 t.Fatalf("Read: expected err %v, got %v", errClosing, er r) 124 t.Fatalf("Read: expected err %v, got %v", errClosing, er r)
127 } 125 }
128 } 126 }
129 } 127 }
130 128
131 func TestWriteTimeout(t *testing.T) { 129 func TestWriteTimeout(t *testing.T) {
132 switch runtime.GOOS { 130 switch runtime.GOOS {
133 case "plan9": 131 case "plan9":
134 » » t.Logf("skipping test on %q", runtime.GOOS) 132 » » t.Skipf("skipping test on %q", runtime.GOOS)
135 » » return
136 } 133 }
137 134
138 ln := newLocalListener(t) 135 ln := newLocalListener(t)
139 defer ln.Close() 136 defer ln.Close()
140 c, err := DialTCP("tcp", nil, ln.Addr().(*TCPAddr)) 137 c, err := DialTCP("tcp", nil, ln.Addr().(*TCPAddr))
141 if err != nil { 138 if err != nil {
142 t.Fatalf("Connect: %v", err) 139 t.Fatalf("Connect: %v", err)
143 } 140 }
144 defer c.Close() 141 defer c.Close()
145 c.SetDeadline(time.Now().Add(time.Hour)) 142 c.SetDeadline(time.Now().Add(time.Hour))
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 t.Error(err) 228 t.Error(err)
232 } 229 }
233 case <-time.After(1 * time.Second): 230 case <-time.After(1 * time.Second):
234 t.Errorf("%s(%q, %q) took over 1 second, expected 0.1s", what, n et, addr) 231 t.Errorf("%s(%q, %q) took over 1 second, expected 0.1s", what, n et, addr)
235 } 232 }
236 } 233 }
237 234
238 func TestTimeoutUDP(t *testing.T) { 235 func TestTimeoutUDP(t *testing.T) {
239 switch runtime.GOOS { 236 switch runtime.GOOS {
240 case "plan9": 237 case "plan9":
241 » » t.Logf("skipping test on %q", runtime.GOOS) 238 » » t.Skipf("skipping test on %q", runtime.GOOS)
242 » » return
243 } 239 }
244 240
245 // set up a listener that won't talk back 241 // set up a listener that won't talk back
246 listening := make(chan string) 242 listening := make(chan string)
247 done := make(chan int) 243 done := make(chan int)
248 go runDatagramPacketConnServer(t, "udp", "127.0.0.1:0", listening, done) 244 go runDatagramPacketConnServer(t, "udp", "127.0.0.1:0", listening, done)
249 addr := <-listening 245 addr := <-listening
250 246
251 testTimeout(t, "udp", addr, false) 247 testTimeout(t, "udp", addr, false)
252 testTimeout(t, "udp", addr, true) 248 testTimeout(t, "udp", addr, true)
253 <-done 249 <-done
254 } 250 }
255 251
256 func TestTimeoutTCP(t *testing.T) { 252 func TestTimeoutTCP(t *testing.T) {
257 switch runtime.GOOS { 253 switch runtime.GOOS {
258 case "plan9": 254 case "plan9":
259 » » t.Logf("skipping test on %q", runtime.GOOS) 255 » » t.Skipf("skipping test on %q", runtime.GOOS)
260 » » return
261 } 256 }
262 257
263 // set up a listener that won't talk back 258 // set up a listener that won't talk back
264 listening := make(chan string) 259 listening := make(chan string)
265 done := make(chan int) 260 done := make(chan int)
266 go runStreamConnServer(t, "tcp", "127.0.0.1:0", listening, done) 261 go runStreamConnServer(t, "tcp", "127.0.0.1:0", listening, done)
267 addr := <-listening 262 addr := <-listening
268 263
269 testTimeout(t, "tcp", addr, false) 264 testTimeout(t, "tcp", addr, false)
270 <-done 265 <-done
271 } 266 }
272 267
273 func TestDeadlineReset(t *testing.T) { 268 func TestDeadlineReset(t *testing.T) {
274 switch runtime.GOOS { 269 switch runtime.GOOS {
275 case "plan9": 270 case "plan9":
276 » » t.Logf("skipping test on %q", runtime.GOOS) 271 » » t.Skipf("skipping test on %q", runtime.GOOS)
277 » » return
278 } 272 }
279 ln, err := Listen("tcp", "127.0.0.1:0") 273 ln, err := Listen("tcp", "127.0.0.1:0")
280 if err != nil { 274 if err != nil {
281 t.Fatal(err) 275 t.Fatal(err)
282 } 276 }
283 defer ln.Close() 277 defer ln.Close()
284 tl := ln.(*TCPListener) 278 tl := ln.(*TCPListener)
285 tl.SetDeadline(time.Now().Add(1 * time.Minute)) 279 tl.SetDeadline(time.Now().Add(1 * time.Minute))
286 tl.SetDeadline(noDeadline) // reset it 280 tl.SetDeadline(noDeadline) // reset it
287 errc := make(chan error, 1) 281 errc := make(chan error, 1)
288 go func() { 282 go func() {
289 _, err := ln.Accept() 283 _, err := ln.Accept()
290 errc <- err 284 errc <- err
291 }() 285 }()
292 select { 286 select {
293 case <-time.After(50 * time.Millisecond): 287 case <-time.After(50 * time.Millisecond):
294 // Pass. 288 // Pass.
295 case err := <-errc: 289 case err := <-errc:
296 // Accept should never return; we never 290 // Accept should never return; we never
297 // connected to it. 291 // connected to it.
298 t.Errorf("unexpected return from Accept; err=%v", err) 292 t.Errorf("unexpected return from Accept; err=%v", err)
299 } 293 }
300 } 294 }
301 295
302 func TestTimeoutAccept(t *testing.T) { 296 func TestTimeoutAccept(t *testing.T) {
303 switch runtime.GOOS { 297 switch runtime.GOOS {
304 case "plan9": 298 case "plan9":
305 » » t.Logf("skipping test on %q", runtime.GOOS) 299 » » t.Skipf("skipping test on %q", runtime.GOOS)
306 » » return
307 } 300 }
308 ln, err := Listen("tcp", "127.0.0.1:0") 301 ln, err := Listen("tcp", "127.0.0.1:0")
309 if err != nil { 302 if err != nil {
310 t.Fatal(err) 303 t.Fatal(err)
311 } 304 }
312 defer ln.Close() 305 defer ln.Close()
313 tl := ln.(*TCPListener) 306 tl := ln.(*TCPListener)
314 tl.SetDeadline(time.Now().Add(100 * time.Millisecond)) 307 tl.SetDeadline(time.Now().Add(100 * time.Millisecond))
315 errc := make(chan error, 1) 308 errc := make(chan error, 1)
316 go func() { 309 go func() {
317 _, err := ln.Accept() 310 _, err := ln.Accept()
318 errc <- err 311 errc <- err
319 }() 312 }()
320 select { 313 select {
321 case <-time.After(1 * time.Second): 314 case <-time.After(1 * time.Second):
322 // Accept shouldn't block indefinitely 315 // Accept shouldn't block indefinitely
323 t.Errorf("Accept didn't return in an expected time") 316 t.Errorf("Accept didn't return in an expected time")
324 case <-errc: 317 case <-errc:
325 // Pass. 318 // Pass.
326 } 319 }
327 } 320 }
328 321
329 func TestReadWriteDeadline(t *testing.T) { 322 func TestReadWriteDeadline(t *testing.T) {
330 switch runtime.GOOS { 323 switch runtime.GOOS {
331 case "plan9": 324 case "plan9":
332 » » t.Logf("skipping test on %q", runtime.GOOS) 325 » » t.Skipf("skipping test on %q", runtime.GOOS)
333 » » return
334 } 326 }
335 327
336 if !canCancelIO { 328 if !canCancelIO {
337 » » t.Logf("skipping test on this system") 329 » » t.Skip("skipping test on this system")
338 » » return
339 } 330 }
340 const ( 331 const (
341 readTimeout = 50 * time.Millisecond 332 readTimeout = 50 * time.Millisecond
342 writeTimeout = 250 * time.Millisecond 333 writeTimeout = 250 * time.Millisecond
343 ) 334 )
344 checkTimeout := func(command string, start time.Time, should time.Durati on) { 335 checkTimeout := func(command string, start time.Time, should time.Durati on) {
345 is := time.Now().Sub(start) 336 is := time.Now().Sub(start)
346 d := is - should 337 d := is - should
347 if d < -30*time.Millisecond || !testing.Short() && 150*time.Mill isecond < d { 338 if d < -30*time.Millisecond || !testing.Short() && 150*time.Mill isecond < d {
348 t.Errorf("%s timeout test failed: is=%v should=%v\n", co mmand, is, should) 339 t.Errorf("%s timeout test failed: is=%v should=%v\n", co mmand, is, should)
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 if !isTimeout(res.err) { 579 if !isTimeout(res.err) {
589 t.Errorf("Write error = %v; want timeout", res.err) 580 t.Errorf("Write error = %v; want timeout", res.err)
590 } 581 }
591 } 582 }
592 583
593 // TestProlongTimeout tests concurrent deadline modification. 584 // TestProlongTimeout tests concurrent deadline modification.
594 // Known to cause data races in the past. 585 // Known to cause data races in the past.
595 func TestProlongTimeout(t *testing.T) { 586 func TestProlongTimeout(t *testing.T) {
596 switch runtime.GOOS { 587 switch runtime.GOOS {
597 case "plan9": 588 case "plan9":
598 » » t.Logf("skipping test on %q", runtime.GOOS) 589 » » t.Skipf("skipping test on %q", runtime.GOOS)
599 » » return
600 } 590 }
601 591
602 ln := newLocalListener(t) 592 ln := newLocalListener(t)
603 defer ln.Close() 593 defer ln.Close()
604 connected := make(chan bool) 594 connected := make(chan bool)
605 go func() { 595 go func() {
606 s, err := ln.Accept() 596 s, err := ln.Accept()
607 connected <- true 597 connected <- true
608 if err != nil { 598 if err != nil {
609 t.Fatalf("ln.Accept: %v", err) 599 t.Fatalf("ln.Accept: %v", err)
(...skipping 23 matching lines...) Expand all
633 if err != nil { 623 if err != nil {
634 t.Fatalf("DialTCP: %v", err) 624 t.Fatalf("DialTCP: %v", err)
635 } 625 }
636 defer c.Close() 626 defer c.Close()
637 <-connected 627 <-connected
638 for i := 0; i < 1024; i++ { 628 for i := 0; i < 1024; i++ {
639 var buf [1]byte 629 var buf [1]byte
640 c.Write(buf[:]) 630 c.Write(buf[:])
641 } 631 }
642 } 632 }
OLDNEW
« no previous file with comments | « src/pkg/net/tcp_test.go ('k') | src/pkg/net/udp_test.go » ('j') | no next file with comments »

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