go.net/netutil: fix unintentional test deadlock on resource starvation
It's been observed when the node under test has a tiny resource
configutation or package http has changed the behavior of its own
active connection pool.
For example,
http://build.golang.org/log/8912bc0944628cf1b4fe4063a77d36d19f9dd6a3
LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/78640043
diff --git a/netutil/listen_test.go b/netutil/listen_test.go
index 240eca1..a4345b1 100644
--- a/netutil/listen_test.go
+++ b/netutil/listen_test.go
@@ -45,7 +45,8 @@
wg.Add(1)
go func() {
defer wg.Done()
- r, err := http.Get("http://" + l.Addr().String())
+ c := http.Client{Timeout: 3 * time.Second}
+ r, err := c.Get("http://" + l.Addr().String())
if err != nil {
t.Logf("Get: %v", err)
atomic.AddInt32(&failed, 1)
@@ -60,6 +61,6 @@
// We expect some Gets to fail as the kernel's accept queue is filled,
// but most should succeed.
if failed >= num/2 {
- t.Errorf("too many Gets failed")
+ t.Errorf("too many Gets failed: %v", failed)
}
}