mirror of
https://github.com/golang/go
synced 2024-10-14 11:53:56 +00:00
net/http: improve failure mode for TestResponseControllerSetPastReadDeadline
A test flake in #59447 seems to indicate that this test got stuck waiting for the test handler to close the readc channel. If the handler returns early due to an unexpected error, it might fail to close this channel. Add a second channel to act as a signal that the handler has given up and the test should stop. This won't fix whatever happened in the flake, but might help us debug it if it happens again. For #59447 Change-Id: I05d84c6176aa938887d93126a6f3bb4dc941c90d Reviewed-on: https://go-review.googlesource.com/c/go/+/482935 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com>
This commit is contained in:
parent
e61ba8e537
commit
ef4b2fdc48
|
@ -156,7 +156,9 @@ func TestResponseControllerSetPastReadDeadline(t *testing.T) {
|
|||
}
|
||||
func testResponseControllerSetPastReadDeadline(t *testing.T, mode testMode) {
|
||||
readc := make(chan struct{})
|
||||
donec := make(chan struct{})
|
||||
cst := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||
defer close(donec)
|
||||
ctl := NewResponseController(w)
|
||||
b := make([]byte, 3)
|
||||
n, err := io.ReadFull(r.Body, b)
|
||||
|
@ -192,10 +194,15 @@ func testResponseControllerSetPastReadDeadline(t *testing.T, mode testMode) {
|
|||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer pw.Close()
|
||||
pw.Write([]byte("one"))
|
||||
<-readc
|
||||
select {
|
||||
case <-readc:
|
||||
case <-donec:
|
||||
t.Errorf("server handler unexpectedly exited without closing readc")
|
||||
return
|
||||
}
|
||||
pw.Write([]byte("two"))
|
||||
pw.Close()
|
||||
}()
|
||||
defer wg.Wait()
|
||||
res, err := cst.c.Post(cst.ts.URL, "text/foo", pr)
|
||||
|
|
Loading…
Reference in a new issue