diff options
| author | Damien Neil <dneil@google.com> | 2023-04-06 12:09:04 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-04-06 21:23:31 +0000 |
| commit | ef4b2fdc48f242fe8f95f15df055c674efa8f35e (patch) | |
| tree | 40686e958503cb0078930f76bf4181cffacf226e /src/net | |
| parent | e61ba8e537ecc845ffdc0a33d7062106a983592b (diff) | |
| download | go-ef4b2fdc48f242fe8f95f15df055c674efa8f35e.tar.xz | |
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>
Diffstat (limited to 'src/net')
| -rw-r--r-- | src/net/http/responsecontroller_test.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/net/http/responsecontroller_test.go b/src/net/http/responsecontroller_test.go index ee8b55a89f..c560e4bc54 100644 --- a/src/net/http/responsecontroller_test.go +++ b/src/net/http/responsecontroller_test.go @@ -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) |
