]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: ensure server handler is done in TestServerNoWriteTimeout
authorDamien Neil <dneil@google.com>
Fri, 22 Mar 2024 21:33:50 +0000 (14:33 -0700)
committerDamien Neil <dneil@google.com>
Fri, 22 Mar 2024 23:15:35 +0000 (23:15 +0000)
Surprisingly, newClientServerTest doesn't ensure that server handlers
are done in its t.Cleanup function. This test's handler can outlive
the test and attempt to log after the test has completed, causing
race detector failures.

Add an explicit call to Server.Shutdown to ensure the handler
has completed.

We should also probably add a Shutdown to clientServerTest.close,
but that's a larger change; this fixes the immediate problem.

Change-Id: Ibe81b4b382c9c8a920b0ff5f76dea6afe69b10f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/573895
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>

src/net/http/serve_test.go

index 8998f38367e7deaf4d8fe16e2063553a0dae4d3a..94b8bdcc2e2378d2d316e68519199348f26159c3 100644 (file)
@@ -922,6 +922,10 @@ func testServerNoWriteTimeout(t *testing.T, mode testMode) {
                if n != 1<<20 || err != nil {
                        t.Errorf("client read response body: %d, %v", n, err)
                }
+               // This shutdown really should be automatic, but it isn't right now.
+               // Shutdown (rather than Close) ensures the handler is done before we return.
+               res.Body.Close()
+               cst.ts.Config.Shutdown(context.Background())
        }
 }