From f49e802892a225c7fd14a3a8bb8c0e83875d888d Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Mon, 18 Apr 2022 12:55:30 -0400 Subject: [PATCH] net/http: eliminate arbitrary timeouts in TestServerRequestContextCancel_ConnClose MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/net/http/serve_test.go | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index 435f828871..1c85a66599 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -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) { -- 2.50.0