mirror of
https://github.com/golang/go
synced 2024-11-17 05:54:46 -07:00
net/http: deflake TestResponseControllerSetFutureWriteDeadline
Don't set the server's write deadline until after the client has read the response headers, avoiding test failures if the deadline expires before or while writing headers. Fixes #56807. Change-Id: I5f80c108b360d030132a13661774a30fac453856 Reviewed-on: https://go-review.googlesource.com/c/go/+/451715 Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
5f7abeca5a
commit
b74aaa1427
@ -132,8 +132,14 @@ func testResponseControllerSetFutureWriteDeadline(t *testing.T, mode testMode) {
|
||||
t.Skip("skip until h2_bundle.go is updated")
|
||||
}
|
||||
errc := make(chan error, 1)
|
||||
startwritec := make(chan struct{})
|
||||
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
ctl := NewResponseController(w)
|
||||
w.WriteHeader(200)
|
||||
if err := ctl.Flush(); err != nil {
|
||||
t.Errorf("ctl.Flush() = %v, want nil", err)
|
||||
}
|
||||
<-startwritec // don't set the deadline until the client reads response headers
|
||||
if err := ctl.SetWriteDeadline(time.Now().Add(1 * time.Millisecond)); err != nil {
|
||||
t.Errorf("ctl.SetWriteDeadline() = %v, want nil", err)
|
||||
}
|
||||
@ -142,6 +148,7 @@ func testResponseControllerSetFutureWriteDeadline(t *testing.T, mode testMode) {
|
||||
}))
|
||||
|
||||
res, err := cst.c.Get(cst.ts.URL)
|
||||
close(startwritec)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected connection error: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user