Skip to content

Commit

Permalink
net/http: ensure server handler is done in TestServerNoWriteTimeout
Browse files Browse the repository at this point in the history
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 <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Auto-Submit: Damien Neil <[email protected]>
  • Loading branch information
neild committed Mar 22, 2024
1 parent 5f5b20c commit 8aeec7c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/net/http/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 8aeec7c

Please sign in to comment.