Skip to content

Commit e90d6d0

Browse files
committed
http2: fix flaky TestTransportResPattern_* tests
The test's server was replying with the stream closure before reading the test client's request body. This should in theory be handled better (and golang/go#16029 will be kept open to track it), but that's not what this test was trying to test anyway. Instead, make the test do things in the expected order so it can continue to test its original subject reliably. (It was trying to test all the orders of optional & optionally fragmented headers in responses.) Updates golang/go#16029 (flaky http2 TestTransportResPattern_*) Updates golang/go#11811 (subrepos need to be green) Change-Id: I631730fce5dad598120bb2d1ea8895e39255d711 Reviewed-on: https://go-review.googlesource.com/24970 Reviewed-by: Andrew Gerrand <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a728288 commit e90d6d0

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

http2/transport_test.go

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,41 +1017,38 @@ func testTransportResPattern(t *testing.T, expect100Continue, resHeader headerTy
10171017
if err != nil {
10181018
return err
10191019
}
1020+
endStream := false
1021+
send := func(mode headerType) {
1022+
hbf := buf.Bytes()
1023+
switch mode {
1024+
case oneHeader:
1025+
ct.fr.WriteHeaders(HeadersFrameParam{
1026+
StreamID: f.Header().StreamID,
1027+
EndHeaders: true,
1028+
EndStream: endStream,
1029+
BlockFragment: hbf,
1030+
})
1031+
case splitHeader:
1032+
if len(hbf) < 2 {
1033+
panic("too small")
1034+
}
1035+
ct.fr.WriteHeaders(HeadersFrameParam{
1036+
StreamID: f.Header().StreamID,
1037+
EndHeaders: false,
1038+
EndStream: endStream,
1039+
BlockFragment: hbf[:1],
1040+
})
1041+
ct.fr.WriteContinuation(f.Header().StreamID, true, hbf[1:])
1042+
default:
1043+
panic("bogus mode")
1044+
}
1045+
}
10201046
switch f := f.(type) {
10211047
case *WindowUpdateFrame, *SettingsFrame:
10221048
case *DataFrame:
1023-
// ignore for now.
1024-
case *HeadersFrame:
1025-
endStream := false
1026-
send := func(mode headerType) {
1027-
hbf := buf.Bytes()
1028-
switch mode {
1029-
case oneHeader:
1030-
ct.fr.WriteHeaders(HeadersFrameParam{
1031-
StreamID: f.StreamID,
1032-
EndHeaders: true,
1033-
EndStream: endStream,
1034-
BlockFragment: hbf,
1035-
})
1036-
case splitHeader:
1037-
if len(hbf) < 2 {
1038-
panic("too small")
1039-
}
1040-
ct.fr.WriteHeaders(HeadersFrameParam{
1041-
StreamID: f.StreamID,
1042-
EndHeaders: false,
1043-
EndStream: endStream,
1044-
BlockFragment: hbf[:1],
1045-
})
1046-
ct.fr.WriteContinuation(f.StreamID, true, hbf[1:])
1047-
default:
1048-
panic("bogus mode")
1049-
}
1050-
}
1051-
if expect100Continue != noHeader {
1052-
buf.Reset()
1053-
enc.WriteField(hpack.HeaderField{Name: ":status", Value: "100"})
1054-
send(expect100Continue)
1049+
if !f.StreamEnded() {
1050+
// No need to send flow control tokens. The test request body is tiny.
1051+
continue
10551052
}
10561053
// Response headers (1+ frames; 1 or 2 in this test, but never 0)
10571054
{
@@ -1075,7 +1072,15 @@ func testTransportResPattern(t *testing.T, expect100Continue, resHeader headerTy
10751072
enc.WriteField(hpack.HeaderField{Name: "some-trailer", Value: "some-value"})
10761073
send(trailers)
10771074
}
1078-
return nil
1075+
if endStream {
1076+
return nil
1077+
}
1078+
case *HeadersFrame:
1079+
if expect100Continue != noHeader {
1080+
buf.Reset()
1081+
enc.WriteField(hpack.HeaderField{Name: ":status", Value: "100"})
1082+
send(expect100Continue)
1083+
}
10791084
}
10801085
}
10811086
}

0 commit comments

Comments
 (0)