mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: make TestSelfConnect less fragile
We believe TestSelfConnect can accidentally connect to something else listening on or dialing from that port. Fixes #8680. LGTM=bradfitz R=bradfitz CC=golang-codereviews, rlh https://golang.org/cl/136700043
This commit is contained in:
parent
c1c5d479bd
commit
95c899f03c
1 changed files with 6 additions and 1 deletions
|
|
@ -119,6 +119,7 @@ func TestSelfConnect(t *testing.T) {
|
|||
// TODO(brainman): do not know why it hangs.
|
||||
t.Skip("skipping known-broken test on windows")
|
||||
}
|
||||
|
||||
// Test that Dial does not honor self-connects.
|
||||
// See the comment in DialTCP.
|
||||
|
||||
|
|
@ -149,8 +150,12 @@ func TestSelfConnect(t *testing.T) {
|
|||
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()
|
||||
t.Errorf("#%d: Dial %q succeeded", i, addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue