netutil: in TestLimitListenerSaturation, allow some connections to fail to dial

When the listener saturates, the kernel will typically buffer the
remaining pending connections (so they will eventually succeed in
dialing). However, that behavior is not guaranteed, and it empirically
doesn't always hold: a failure was observed in
https://build.golang.org/log/5ac7312814bcff4841563be043f28aaefa9b3c90.

We do expect to be able to dial at least as many connections as the
listener will accept, and we expect every connection that is accepted
to be served to completion.

Updates golang/go#22926

Change-Id: I4cb39c8f39fda0dcb905f548612ccdf1856f2a66
Reviewed-on: https://go-review.googlesource.com/c/net/+/380155
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/netutil/listen_test.go b/netutil/listen_test.go
index 793a91d..77304fd 100644
--- a/netutil/listen_test.go
+++ b/netutil/listen_test.go
@@ -203,11 +203,17 @@
 		wg.Wait()
 
 		t.Logf("served %d connections (of %d dialed, %d attempted)", served, dialed, attemptsPerWave)
-		// We expect that the kernel can queue at least attemptsPerWave
-		// connections at a time (since it's only a small number), so every
-		// connection should eventually be served.
-		if served != attemptsPerWave {
-			t.Errorf("expected %d served", attemptsPerWave)
+
+		// Depending on the kernel's queueing behavior, we could get unlucky
+		// and drop one or more connections. However, we should certainly
+		// be able to serve at least max attempts out of each wave.
+		// (In the typical case, the kernel will queue all of the connections
+		// and they will all be served successfully.)
+		if dialed < max {
+			t.Errorf("expected at least %d dialed", max)
+		}
+		if served < dialed {
+			t.Errorf("expected all dialed connections to be served")
 		}
 	}
 }