summaryrefslogtreecommitdiff
path: root/libgo/go/net/dial_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/net/dial_test.go')
-rw-r--r--libgo/go/net/dial_test.go53
1 files changed, 48 insertions, 5 deletions
diff --git a/libgo/go/net/dial_test.go b/libgo/go/net/dial_test.go
index de35ec9f940..e5a797e13bf 100644
--- a/libgo/go/net/dial_test.go
+++ b/libgo/go/net/dial_test.go
@@ -27,8 +27,7 @@ func TestDialTimeout(t *testing.T) {
errc := make(chan error)
- const SOMAXCONN = 0x80 // copied from syscall, but not always available
- const numConns = SOMAXCONN + 10
+ numConns := listenerBacklog + 10
// TODO(bradfitz): It's hard to test this in a portable
// way. This is unforunate, but works for now.
@@ -43,7 +42,7 @@ func TestDialTimeout(t *testing.T) {
errc <- err
}()
}
- case "darwin", "windows":
+ case "darwin":
// At least OS X 10.7 seems to accept any number of
// connections, ignoring listen's backlog, so resort
// to connecting to a hopefully-dead 127/8 address.
@@ -54,8 +53,10 @@ func TestDialTimeout(t *testing.T) {
}()
default:
// TODO(bradfitz):
- // OpenBSD may have a reject route to 10/8.
- // FreeBSD likely works, but is untested.
+ // OpenBSD may have a reject route to 127/8 except 127.0.0.1/32
+ // by default. FreeBSD likely works, but is untested.
+ // TODO(rsc):
+ // The timeout never happens on Windows. Why? Issue 3016.
t.Logf("skipping test on %q; untested.", runtime.GOOS)
return
}
@@ -85,3 +86,45 @@ func TestDialTimeout(t *testing.T) {
}
}
}
+
+func TestSelfConnect(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ // TODO(brainman): do not know why it hangs.
+ t.Logf("skipping known-broken test on windows")
+ return
+ }
+ // Test that Dial does not honor self-connects.
+ // See the comment in DialTCP.
+
+ // Find a port that would be used as a local address.
+ l, err := Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ c, err := Dial("tcp", l.Addr().String())
+ if err != nil {
+ t.Fatal(err)
+ }
+ addr := c.LocalAddr().String()
+ c.Close()
+ l.Close()
+
+ // Try to connect to that address repeatedly.
+ n := 100000
+ if testing.Short() {
+ n = 1000
+ }
+ switch runtime.GOOS {
+ case "darwin", "freebsd", "openbsd", "windows":
+ // Non-Linux systems take a long time to figure
+ // out that there is nothing listening on localhost.
+ n = 100
+ }
+ for i := 0; i < n; i++ {
+ c, err := Dial("tcp", addr)
+ if err == nil {
+ c.Close()
+ t.Errorf("#%d: Dial %q succeeded", i, addr)
+ }
+ }
+}