summaryrefslogtreecommitdiff
path: root/libgo/go/net/net_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/net/net_test.go')
-rw-r--r--libgo/go/net/net_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/libgo/go/net/net_test.go b/libgo/go/net/net_test.go
index dc0d49d23ac..b4a6e1f5d69 100644
--- a/libgo/go/net/net_test.go
+++ b/libgo/go/net/net_test.go
@@ -6,6 +6,7 @@ package net
import (
"flag"
+ "os"
"regexp"
"testing"
)
@@ -61,6 +62,8 @@ var dialErrorTests = []DialErrorTest{
},
}
+var duplicateErrorPattern = `dial (.*) dial (.*)`
+
func TestDialError(t *testing.T) {
if !*runErrorTest {
t.Logf("test disabled; use --run_error_test to enable")
@@ -80,6 +83,10 @@ func TestDialError(t *testing.T) {
if !match {
t.Errorf("#%d: %q, want match for %#q", i, s, tt.Pattern)
}
+ match, _ = regexp.MatchString(duplicateErrorPattern, s)
+ if match {
+ t.Errorf("#%d: %q, duplicate error return from Dial", i, s)
+ }
}
}
@@ -119,3 +126,46 @@ func TestReverseAddress(t *testing.T) {
}
}
}
+
+func TestShutdown(t *testing.T) {
+ l, err := Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ if l, err = Listen("tcp6", "[::1]:0"); err != nil {
+ t.Fatalf("ListenTCP on :0: %v", err)
+ }
+ }
+
+ go func() {
+ c, err := l.Accept()
+ if err != nil {
+ t.Fatalf("Accept: %v", err)
+ }
+ var buf [10]byte
+ n, err := c.Read(buf[:])
+ if n != 0 || err != os.EOF {
+ t.Fatalf("server Read = %d, %v; want 0, os.EOF", n, err)
+ }
+ c.Write([]byte("response"))
+ c.Close()
+ }()
+
+ c, err := Dial("tcp", l.Addr().String())
+ if err != nil {
+ t.Fatalf("Dial: %v", err)
+ }
+ defer c.Close()
+
+ err = c.(*TCPConn).CloseWrite()
+ if err != nil {
+ t.Fatalf("CloseWrite: %v", err)
+ }
+ var buf [10]byte
+ n, err := c.Read(buf[:])
+ if err != nil {
+ t.Fatalf("client Read: %d, %v", n, err)
+ }
+ got := string(buf[:n])
+ if got != "response" {
+ t.Errorf("read = %q, want \"response\"", got)
+ }
+}