mirror of
https://github.com/golang/go
synced 2024-11-26 14:56:47 -07:00
net: change server_test.go so we could see failure messages
R=golang-dev, dave CC=golang-dev https://golang.org/cl/7323051
This commit is contained in:
parent
928fe51661
commit
ea1f7b8380
@ -113,8 +113,7 @@ func TestStreamConnServer(t *testing.T) {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
_, port, err := SplitHostPort(taddr)
|
||||
if err != nil {
|
||||
t.Errorf("SplitHostPort(%q) failed: %v", taddr, err)
|
||||
return
|
||||
t.Fatalf("SplitHostPort(%q) failed: %v", taddr, err)
|
||||
}
|
||||
taddr = tt.caddr + ":" + port
|
||||
}
|
||||
@ -169,11 +168,11 @@ func TestSeqpacketConnServer(t *testing.T) {
|
||||
}
|
||||
|
||||
func runStreamConnServer(t *testing.T, net, laddr string, listening chan<- string, done chan<- int) {
|
||||
defer close(done)
|
||||
l, err := Listen(net, laddr)
|
||||
if err != nil {
|
||||
t.Errorf("Listen(%q, %q) failed: %v", net, laddr, err)
|
||||
listening <- "<nil>"
|
||||
done <- 1
|
||||
return
|
||||
}
|
||||
defer l.Close()
|
||||
@ -188,13 +187,14 @@ func runStreamConnServer(t *testing.T, net, laddr string, listening chan<- strin
|
||||
}
|
||||
rw.Write(buf[0:n])
|
||||
}
|
||||
done <- 1
|
||||
close(done)
|
||||
}
|
||||
|
||||
run:
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
if err != nil {
|
||||
t.Logf("Accept failed: %v", err)
|
||||
continue run
|
||||
}
|
||||
echodone := make(chan int)
|
||||
@ -203,14 +203,12 @@ run:
|
||||
c.Close()
|
||||
break run
|
||||
}
|
||||
done <- 1
|
||||
}
|
||||
|
||||
func runStreamConnClient(t *testing.T, net, taddr string, isEmpty bool) {
|
||||
c, err := Dial(net, taddr)
|
||||
if err != nil {
|
||||
t.Errorf("Dial(%q, %q) failed: %v", net, taddr, err)
|
||||
return
|
||||
t.Fatalf("Dial(%q, %q) failed: %v", net, taddr, err)
|
||||
}
|
||||
defer c.Close()
|
||||
c.SetReadDeadline(time.Now().Add(1 * time.Second))
|
||||
@ -220,14 +218,12 @@ func runStreamConnClient(t *testing.T, net, taddr string, isEmpty bool) {
|
||||
wb = []byte("StreamConnClient by Dial\n")
|
||||
}
|
||||
if n, err := c.Write(wb); err != nil || n != len(wb) {
|
||||
t.Errorf("Write failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
return
|
||||
t.Fatalf("Write failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
}
|
||||
|
||||
rb := make([]byte, 1024)
|
||||
if n, err := c.Read(rb[0:]); err != nil || n != len(wb) {
|
||||
t.Errorf("Read failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
return
|
||||
t.Fatalf("Read failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
}
|
||||
|
||||
// Send explicit ending for unixpacket.
|
||||
@ -333,8 +329,7 @@ func TestDatagramPacketConnServer(t *testing.T) {
|
||||
case "udp", "udp4", "udp6":
|
||||
_, port, err := SplitHostPort(taddr)
|
||||
if err != nil {
|
||||
t.Errorf("SplitHostPort(%q) failed: %v", taddr, err)
|
||||
return
|
||||
t.Fatalf("SplitHostPort(%q) failed: %v", taddr, err)
|
||||
}
|
||||
taddr = tt.caddr + ":" + port
|
||||
tt.caddr += ":0"
|
||||
@ -397,14 +392,12 @@ func runDatagramConnClient(t *testing.T, net, laddr, taddr string, isEmpty bool)
|
||||
case "udp", "udp4", "udp6":
|
||||
c, err = Dial(net, taddr)
|
||||
if err != nil {
|
||||
t.Errorf("Dial(%q, %q) failed: %v", net, taddr, err)
|
||||
return
|
||||
t.Fatalf("Dial(%q, %q) failed: %v", net, taddr, err)
|
||||
}
|
||||
case "unixgram":
|
||||
c, err = DialUnix(net, &UnixAddr{laddr, net}, &UnixAddr{taddr, net})
|
||||
if err != nil {
|
||||
t.Errorf("DialUnix(%q, {%q, %q}) failed: %v", net, laddr, taddr, err)
|
||||
return
|
||||
t.Fatalf("DialUnix(%q, {%q, %q}) failed: %v", net, laddr, taddr, err)
|
||||
}
|
||||
}
|
||||
defer c.Close()
|
||||
@ -415,14 +408,12 @@ func runDatagramConnClient(t *testing.T, net, laddr, taddr string, isEmpty bool)
|
||||
wb = []byte("DatagramConnClient by Dial\n")
|
||||
}
|
||||
if n, err := c.Write(wb[0:]); err != nil || n != len(wb) {
|
||||
t.Errorf("Write failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
return
|
||||
t.Fatalf("Write failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
}
|
||||
|
||||
rb := make([]byte, 1024)
|
||||
if n, err := c.Read(rb[0:]); err != nil || n != len(wb) {
|
||||
t.Errorf("Read failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
return
|
||||
t.Fatalf("Read failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,20 +424,17 @@ func runDatagramPacketConnClient(t *testing.T, net, laddr, taddr string, isEmpty
|
||||
case "udp", "udp4", "udp6":
|
||||
ra, err = ResolveUDPAddr(net, taddr)
|
||||
if err != nil {
|
||||
t.Errorf("ResolveUDPAddr(%q, %q) failed: %v", net, taddr, err)
|
||||
return
|
||||
t.Fatalf("ResolveUDPAddr(%q, %q) failed: %v", net, taddr, err)
|
||||
}
|
||||
case "unixgram":
|
||||
ra, err = ResolveUnixAddr(net, taddr)
|
||||
if err != nil {
|
||||
t.Errorf("ResolveUxixAddr(%q, %q) failed: %v", net, taddr, err)
|
||||
return
|
||||
t.Fatalf("ResolveUxixAddr(%q, %q) failed: %v", net, taddr, err)
|
||||
}
|
||||
}
|
||||
c, err := ListenPacket(net, laddr)
|
||||
if err != nil {
|
||||
t.Errorf("ListenPacket(%q, %q) faild: %v", net, laddr, err)
|
||||
return
|
||||
t.Fatalf("ListenPacket(%q, %q) faild: %v", net, laddr, err)
|
||||
}
|
||||
defer c.Close()
|
||||
c.SetReadDeadline(time.Now().Add(1 * time.Second))
|
||||
@ -456,13 +444,11 @@ func runDatagramPacketConnClient(t *testing.T, net, laddr, taddr string, isEmpty
|
||||
wb = []byte("DatagramPacketConnClient by ListenPacket\n")
|
||||
}
|
||||
if n, err := c.WriteTo(wb[0:], ra); err != nil || n != len(wb) {
|
||||
t.Errorf("WriteTo(%v) failed: %v, %v; want %v, <nil>", ra, n, err, len(wb))
|
||||
return
|
||||
t.Fatalf("WriteTo(%v) failed: %v, %v; want %v, <nil>", ra, n, err, len(wb))
|
||||
}
|
||||
|
||||
rb := make([]byte, 1024)
|
||||
if n, _, err := c.ReadFrom(rb[0:]); err != nil || n != len(wb) {
|
||||
t.Errorf("ReadFrom failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
return
|
||||
t.Fatalf("ReadFrom failed: %v, %v; want %v, <nil>", n, err, len(wb))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user