mirror of
https://github.com/golang/go
synced 2024-11-27 04:41:33 -07:00
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>
This commit is contained in:
parent
c8057d8569
commit
648f3febf5
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user