mirror of
https://github.com/golang/net.git
synced 2026-03-31 10:27:08 +09:00
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>
This commit is contained in:
committed by
Gopher Robot
parent
22a8c02e92
commit
162ad308ad
@@ -4290,8 +4290,7 @@ func TestServerWindowUpdateOnBodyClose(t *testing.T) {
|
||||
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 @@ func testServerWindowUpdateOnBodyClose(t testing.TB) {
|
||||
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 @@ func testServerWindowUpdateOnBodyClose(t testing.TB) {
|
||||
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 @@ func testServerWindowUpdateOnBodyClose(t testing.TB) {
|
||||
// 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) {
|
||||
|
||||
Reference in New Issue
Block a user