aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2022-11-30 13:43:45 -0500
committerDamien Neil <dneil@google.com>2022-11-30 19:01:44 +0000
commit648f3febf54465162e095da99149de7a839576c6 (patch)
treed799d260c9e1e894afa57ab0118615955ff7f0a9 /src/net/http
parentc8057d85692c01e96d3c04815a0a364c7cfb4d90 (diff)
downloadgo-648f3febf54465162e095da99149de7a839576c6.tar.xz
net/http: deflake and fix TestWrappedResponseController
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>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/responsecontroller_test.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/net/http/responsecontroller_test.go b/src/net/http/responsecontroller_test.go
index d947504f50..0dca7332b7 100644
--- a/src/net/http/responsecontroller_test.go
+++ b/src/net/http/responsecontroller_test.go
@@ -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()
}