Skip to content

Commit

Permalink
net: delete TestTCPSelfConnect
Browse files Browse the repository at this point in the history
This test is flaky, apparently due to a typo'd operator in CL 21447
that causes it to compare “same port OR IP” instead of
“same port AND IP”.

If we merely fixed the comparison, the test would hopefully stop being
flaky itself, but we would still be left with another problem:
repeatedly dialing a port that we believe to be unused can interfere
with other tests, which may open the previously-unused port and then
attempt a single Dial and expect it to succeed. Arbitrary other Dial
calls for that port may cause the wrong connection to be accepted,
leading to spurious test failures.

Moreover, the test can be extremely expensive for the amount of data
we hope to get from it, depending on the system's port-reuse
algorithms and dial implementations. It is already scaled back by up
to 1000x on a huge number of platforms due to latency, and may even be
ineffective on those platforms because of the arbitrary 1ms Dial
timeout. And the incremental value from it is quite low, too: it tests
the workaround for what is arguably a bug in the Linux kernel, which
ought to be fixed (and tested) upstream instead of worked around in
every open-source project that dials local ports.

Instead of trying to deflake this test, let's just get rid of it.

Fixes #18290.

Change-Id: I8a58b93d67916a33741c9ab29ef99c49c46b32c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/460657
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Jan 19, 2023
1 parent fbf14ae commit e08642c
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions src/net/tcpsock_test.go
Expand Up @@ -617,50 +617,6 @@ func TestTCPStress(t *testing.T) {
<-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 := newLocalListener(t, "tcp")
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", "ios", "dragonfly", "freebsd", "netbsd", "openbsd", "plan9", "illumos", "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()
}
}
}

// Test that >32-bit reads work on 64-bit systems.
// On 32-bit systems this tests that maxint reads work.
func TestTCPBig(t *testing.T) {
Expand Down

0 comments on commit e08642c

Please sign in to comment.