Commit 2ae749c1 authored by Mikio Hara's avatar Mikio Hara

net: rename TestSelfConnect to TestTCPSelfConnect

Alos moves TestTCPSelfConnect into tcpsock_test.go

Change-Id: I3e1cbd029594ecb36a67f42bc3ecdbc7176a95dc
Reviewed-on: https://go-review.googlesource.com/21447
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent bc942823
......@@ -54,52 +54,6 @@ func TestProhibitionaryDialArg(t *testing.T) {
}
}
func TestSelfConnect(t *testing.T) {
if runtime.GOOS == "windows" {
// TODO(brainman): do not know why it hangs.
t.Skip("known-broken test on windows")
}
// 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", "dragonfly", "freebsd", "netbsd", "openbsd", "plan9", "solaris", "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 := DialTimeout("tcp", addr, time.Millisecond)
if err == nil {
if c.LocalAddr().String() == addr {
t.Errorf("#%d: Dial %q self-connect", i, addr)
} else {
t.Logf("#%d: Dial %q succeeded - possibly racing with other listener", i, addr)
}
c.Close()
}
}
}
func TestDialTimeoutFDLeak(t *testing.T) {
switch runtime.GOOS {
case "plan9":
......
......@@ -588,3 +588,50 @@ func TestTCPStress(t *testing.T) {
ln.Close()
<-done
}
func TestTCPSelfConnect(t *testing.T) {
if runtime.GOOS == "windows" {
// TODO(brainman): do not know why it hangs.
t.Skip("known-broken test on windows")
}
ln, err := newLocalListener("tcp")
if err != nil {
t.Fatal(err)
}
var d Dialer
c, err := d.Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil {
ln.Close()
t.Fatal(err)
}
network := c.LocalAddr().Network()
laddr := *c.LocalAddr().(*TCPAddr)
c.Close()
ln.Close()
// Try to connect to that address repeatedly.
n := 100000
if testing.Short() {
n = 1000
}
switch runtime.GOOS {
case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd", "plan9", "solaris", "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++ {
d.Timeout = time.Millisecond
c, err := d.Dial(network, laddr.String())
if err == nil {
addr := c.LocalAddr().(*TCPAddr)
if addr.Port == laddr.Port || addr.IP.Equal(laddr.IP) {
t.Errorf("Dial %v should fail", addr)
} else {
t.Logf("Dial %v succeeded - possibly racing with other listener", addr)
}
c.Close()
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment