http2: simplify TestServerWindowUpdateOnBodyClose This test closes a handler's request mid-test by poking into the server internals. There's no reason I can see to do this, when the handler can just call req.Body.Close to achieve the same effect. Change the test to use the public API. Change-Id: I4f14939e951c4d8f07abd9d3c2f30c2004f87dad Reviewed-on: https://go-review.googlesource.com/c/net/+/701001 Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <nsh@golang.org> Auto-Submit: Nicholas Husin <nsh@golang.org>
diff --git a/http2/server_test.go b/http2/server_test.go index ec5b305..cd6e771 100644 --- a/http2/server_test.go +++ b/http2/server_test.go
@@ -4290,8 +4290,7 @@ func testServerWindowUpdateOnBodyClose(t testing.TB) { const windowSize = 65535 * 2 content := make([]byte, windowSize) - blockCh := make(chan bool) - errc := make(chan error, 1) + errc := make(chan error) st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) { buf := make([]byte, 4) n, err := io.ReadFull(r.Body, buf) @@ -4303,8 +4302,7 @@ errc <- fmt.Errorf("too few bytes read: %d", n) return } - blockCh <- true - <-blockCh + r.Body.Close() errc <- nil }, func(s *Server) { s.MaxUploadBufferPerConnection = windowSize @@ -4323,9 +4321,9 @@ EndHeaders: true, }) st.writeData(1, false, content[:windowSize/2]) - <-blockCh - st.stream(1).body.CloseWithError(io.EOF) - blockCh <- true + if err := <-errc; err != nil { + t.Fatal(err) + } // Wait for flow control credit for the portion of the request written so far. increments := windowSize / 2 @@ -4345,10 +4343,6 @@ // Writing data after the stream is reset immediately returns flow control credit. st.writeData(1, false, content[windowSize/2:]) st.wantWindowUpdate(0, windowSize/2) - - if err := <-errc; err != nil { - t.Error(err) - } } func TestNoErrorLoggedOnPostAfterGOAWAY(t *testing.T) {