1
0
mirror of https://github.com/golang/go synced 2024-11-12 05:50:21 -07:00

net: make use of testing.Errorf instead of testing.Fatalf in non-test function goroutines

See testing.FailNow for further information.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/75900043
This commit is contained in:
Mikio Hara 2014-03-15 13:43:02 +09:00
parent 6436df0d81
commit f0433e422b
4 changed files with 48 additions and 24 deletions

View File

@ -63,7 +63,8 @@ func TestMutexCloseUnblock(t *testing.T) {
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
go func() { go func() {
if mu.RWLock(true) { if mu.RWLock(true) {
t.Fatal("broken") t.Error("broken")
return
} }
c <- true c <- true
}() }()
@ -138,36 +139,44 @@ func TestMutexStress(t *testing.T) {
switch r.Intn(3) { switch r.Intn(3) {
case 0: case 0:
if !mu.Incref() { if !mu.Incref() {
t.Fatal("broken") t.Error("broken")
return
} }
if mu.Decref() { if mu.Decref() {
t.Fatal("broken") t.Error("broken")
return
} }
case 1: case 1:
if !mu.RWLock(true) { if !mu.RWLock(true) {
t.Fatal("broken") t.Error("broken")
return
} }
// Ensure that it provides mutual exclusion for readers. // Ensure that it provides mutual exclusion for readers.
if readState[0] != readState[1] { if readState[0] != readState[1] {
t.Fatal("broken") t.Error("broken")
return
} }
readState[0]++ readState[0]++
readState[1]++ readState[1]++
if mu.RWUnlock(true) { if mu.RWUnlock(true) {
t.Fatal("broken") t.Error("broken")
return
} }
case 2: case 2:
if !mu.RWLock(false) { if !mu.RWLock(false) {
t.Fatal("broken") t.Error("broken")
return
} }
// Ensure that it provides mutual exclusion for writers. // Ensure that it provides mutual exclusion for writers.
if writeState[0] != writeState[1] { if writeState[0] != writeState[1] {
t.Fatal("broken") t.Error("broken")
return
} }
writeState[0]++ writeState[0]++
writeState[1]++ writeState[1]++
if mu.RWUnlock(false) { if mu.RWUnlock(false) {
t.Fatal("broken") t.Error("broken")
return
} }
} }
} }

View File

@ -28,12 +28,14 @@ func TestShutdown(t *testing.T) {
defer ln.Close() defer ln.Close()
c, err := ln.Accept() c, err := ln.Accept()
if err != nil { if err != nil {
t.Fatalf("Accept: %v", err) t.Errorf("Accept: %v", err)
return
} }
var buf [10]byte var buf [10]byte
n, err := c.Read(buf[:]) n, err := c.Read(buf[:])
if n != 0 || err != io.EOF { if n != 0 || err != io.EOF {
t.Fatalf("server Read = %d, %v; want 0, io.EOF", n, err) t.Errorf("server Read = %d, %v; want 0, io.EOF", n, err)
return
} }
c.Write([]byte("response")) c.Write([]byte("response"))
c.Close() c.Close()
@ -84,12 +86,14 @@ func TestShutdownUnix(t *testing.T) {
go func() { go func() {
c, err := ln.Accept() c, err := ln.Accept()
if err != nil { if err != nil {
t.Fatalf("Accept: %v", err) t.Errorf("Accept: %v", err)
return
} }
var buf [10]byte var buf [10]byte
n, err := c.Read(buf[:]) n, err := c.Read(buf[:])
if n != 0 || err != io.EOF { if n != 0 || err != io.EOF {
t.Fatalf("server Read = %d, %v; want 0, io.EOF", n, err) t.Errorf("server Read = %d, %v; want 0, io.EOF", n, err)
return
} }
c.Write([]byte("response")) c.Write([]byte("response"))
c.Close() c.Close()
@ -196,7 +200,8 @@ func TestTCPClose(t *testing.T) {
go func() { go func() {
c, err := Dial("tcp", l.Addr().String()) c, err := Dial("tcp", l.Addr().String())
if err != nil { if err != nil {
t.Fatal(err) t.Errorf("Dial: %v", err)
return
} }
go read(c) go read(c)

View File

@ -185,7 +185,8 @@ func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
for p := 0; p < P; p++ { for p := 0; p < P; p++ {
s, err := ln.Accept() s, err := ln.Accept()
if err != nil { if err != nil {
b.Fatalf("Accept failed: %v", err) b.Errorf("Accept failed: %v", err)
return
} }
servers[p] = s servers[p] = s
} }
@ -217,7 +218,8 @@ func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
buf[0] = v buf[0] = v
_, err := c.Write(buf[:]) _, err := c.Write(buf[:])
if err != nil { if err != nil {
b.Fatalf("Write failed: %v", err) b.Errorf("Write failed: %v", err)
return
} }
} }
}(clients[p]) }(clients[p])
@ -232,7 +234,8 @@ func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
_, err := s.Read(buf[:]) _, err := s.Read(buf[:])
if err != nil { if err != nil {
b.Fatalf("Read failed: %v", err) b.Errorf("Read failed: %v", err)
return
} }
pipe <- buf[0] pipe <- buf[0]
} }
@ -250,7 +253,8 @@ func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
buf[0] = v buf[0] = v
_, err := s.Write(buf[:]) _, err := s.Write(buf[:])
if err != nil { if err != nil {
b.Fatalf("Write failed: %v", err) b.Errorf("Write failed: %v", err)
return
} }
} }
s.Close() s.Close()
@ -263,7 +267,8 @@ func benchmarkTCPConcurrentReadWrite(b *testing.B, laddr string) {
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
_, err := c.Read(buf[:]) _, err := c.Read(buf[:])
if err != nil { if err != nil {
b.Fatalf("Read failed: %v", err) b.Errorf("Read failed: %v", err)
return
} }
} }
c.Close() c.Close()

View File

@ -348,7 +348,8 @@ func TestReadWriteDeadline(t *testing.T) {
go func() { go func() {
c, err := ln.Accept() c, err := ln.Accept()
if err != nil { if err != nil {
t.Fatalf("Accept: %v", err) t.Errorf("Accept: %v", err)
return
} }
defer c.Close() defer c.Close()
lnquit <- true lnquit <- true
@ -536,7 +537,8 @@ func TestReadDeadlineDataAvailable(t *testing.T) {
go func() { go func() {
c, err := ln.Accept() c, err := ln.Accept()
if err != nil { if err != nil {
t.Fatalf("Accept: %v", err) t.Errorf("Accept: %v", err)
return
} }
defer c.Close() defer c.Close()
n, err := c.Write([]byte(msg)) n, err := c.Write([]byte(msg))
@ -574,7 +576,8 @@ func TestWriteDeadlineBufferAvailable(t *testing.T) {
go func() { go func() {
c, err := ln.Accept() c, err := ln.Accept()
if err != nil { if err != nil {
t.Fatalf("Accept: %v", err) t.Errorf("Accept: %v", err)
return
} }
defer c.Close() defer c.Close()
c.SetWriteDeadline(time.Now().Add(-5 * time.Second)) // in the past c.SetWriteDeadline(time.Now().Add(-5 * time.Second)) // in the past
@ -610,7 +613,8 @@ func TestAcceptDeadlineConnectionAvailable(t *testing.T) {
go func() { go func() {
c, err := Dial("tcp", ln.Addr().String()) c, err := Dial("tcp", ln.Addr().String())
if err != nil { if err != nil {
t.Fatalf("Dial: %v", err) t.Errorf("Dial: %v", err)
return
} }
defer c.Close() defer c.Close()
var buf [1]byte var buf [1]byte
@ -669,7 +673,8 @@ func TestProlongTimeout(t *testing.T) {
s, err := ln.Accept() s, err := ln.Accept()
connected <- true connected <- true
if err != nil { if err != nil {
t.Fatalf("ln.Accept: %v", err) t.Errorf("ln.Accept: %v", err)
return
} }
defer s.Close() defer s.Close()
s.SetDeadline(time.Now().Add(time.Hour)) s.SetDeadline(time.Now().Add(time.Hour))