net/http: eliminate arbitrary timeouts in TestServerRequestContextCancel_ConnClose

These timeouts are empirically sometimes (but rarely) too short on
slower builders, and at any rate if this test fails “for real” we'll
want a goroutine dump in order to debug it anyway. A goroutine dump is
exactly what we get if we let the test time out on its own.

Fixes #52414.

Change-Id: Id2dd3839977bd8a41f296d67d1cccbf068fd73f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/400816
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Bryan C. Mills 2022-04-18 12:55:30 -04:00 committed by Gopher Robot
parent 3df9df8d6a
commit f49e802892

View File

@ -4877,11 +4877,7 @@ func TestServerRequestContextCancel_ConnClose(t *testing.T) {
handlerDone := make(chan struct{})
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
close(inHandler)
select {
case <-r.Context().Done():
case <-time.After(3 * time.Second):
t.Errorf("timeout waiting for context to be done")
}
<-r.Context().Done()
close(handlerDone)
}))
defer ts.Close()
@ -4891,18 +4887,9 @@ func TestServerRequestContextCancel_ConnClose(t *testing.T) {
}
defer c.Close()
io.WriteString(c, "GET / HTTP/1.1\r\nHost: foo\r\n\r\n")
select {
case <-inHandler:
case <-time.After(3 * time.Second):
t.Fatalf("timeout waiting to see ServeHTTP get called")
}
<-inHandler
c.Close() // this should trigger the context being done
select {
case <-handlerDone:
case <-time.After(4 * time.Second):
t.Fatalf("timeout waiting to see ServeHTTP exit")
}
<-handlerDone
}
func TestServerContext_ServerContextKey_h1(t *testing.T) {