]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: deflake and fix TestWrappedResponseController
authorDamien Neil <dneil@google.com>
Wed, 30 Nov 2022 18:43:45 +0000 (13:43 -0500)
committerDamien Neil <dneil@google.com>
Wed, 30 Nov 2022 19:01:44 +0000 (19:01 +0000)
Read the full (empty) response body before closing it,
to avoid cancelling the request while the server handler
is still running.

Wrap the ResponseWriter before calling NewResponseController:
This test is intended to verify that wrapping the controller
works properly, but neglected to actually wrap the controller.

Fixes #56961.

Change-Id: I00269f897448ab34676338707b7a04d19ff17963
Reviewed-on: https://go-review.googlesource.com/c/go/+/453860
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/net/http/responsecontroller_test.go

index d947504f50ada190b17ed3da367cd9b5ea73df89..0dca7332b796704c90d5e935f46efa3d9a8abe79 100644 (file)
@@ -244,6 +244,7 @@ func (w wrapWriter) Unwrap() ResponseWriter {
 func TestWrappedResponseController(t *testing.T) { run(t, testWrappedResponseController) }
 func testWrappedResponseController(t *testing.T, mode testMode) {
        cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
+               w = wrapWriter{w}
                ctl := NewResponseController(w)
                if err := ctl.Flush(); err != nil {
                        t.Errorf("ctl.Flush() = %v, want nil", err)
@@ -259,5 +260,6 @@ func testWrappedResponseController(t *testing.T, mode testMode) {
        if err != nil {
                t.Fatalf("unexpected connection error: %v", err)
        }
+       io.Copy(io.Discard, res.Body)
        defer res.Body.Close()
 }