git » go-net » commit c9a3c54

http2: fix flaky TestTransportReqBodyAfterResponse_403

author Brad Fitzpatrick
2016-07-13 17:36:29 UTC
committer Brad Fitzpatrick
2016-07-13 19:45:06 UTC
parent f841c39de738b1d0df95b5a7187744f0e03d8112

http2: fix flaky TestTransportReqBodyAfterResponse_403

Removes a time.Sleep from a test.

Fixes golang/go#16102

Change-Id: Ic1079ad3312d2dcfde4cc16dd0ee9661e1e509f2
Reviewed-on: https://go-review.googlesource.com/24903
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>

http2/transport_test.go +11 -9

diff --git a/http2/transport_test.go b/http2/transport_test.go
index 39abde2..ec7d7e0 100644
--- a/http2/transport_test.go
+++ b/http2/transport_test.go
@@ -755,18 +755,18 @@ func testTransportReqBodyAfterResponse(t *testing.T, status int) {
 				if f.StreamEnded() {
 					return fmt.Errorf("headers contains END_STREAM unexpectedly: %v", f)
 				}
-				time.Sleep(50 * time.Millisecond) // let client send body
-				enc.WriteField(hpack.HeaderField{Name: ":status", Value: strconv.Itoa(status)})
-				ct.fr.WriteHeaders(HeadersFrameParam{
-					StreamID:      f.StreamID,
-					EndHeaders:    true,
-					EndStream:     false,
-					BlockFragment: buf.Bytes(),
-				})
 			case *DataFrame:
 				dataLen := len(f.Data())
-				dataRecv += int64(dataLen)
 				if dataLen > 0 {
+					if dataRecv == 0 {
+						enc.WriteField(hpack.HeaderField{Name: ":status", Value: strconv.Itoa(status)})
+						ct.fr.WriteHeaders(HeadersFrameParam{
+							StreamID:      f.StreamID,
+							EndHeaders:    true,
+							EndStream:     false,
+							BlockFragment: buf.Bytes(),
+						})
+					}
 					if err := ct.fr.WriteWindowUpdate(0, uint32(dataLen)); err != nil {
 						return err
 					}
@@ -774,6 +774,8 @@ func testTransportReqBodyAfterResponse(t *testing.T, status int) {
 						return err
 					}
 				}
+				dataRecv += int64(dataLen)
+
 				if !closed && ((status != 200 && dataRecv > 0) ||
 					(status == 200 && dataRecv == bodySize)) {
 					closed = true