Skip to content

Commit 30b0e78

Browse files
neildgopherbot
authored andcommitted
http2: modernize TestRoundTripDoesntConsumeRequestBodyEarly
Use a testClientConn with its fake network connection configured to encounter an error, rather than an http2.Client with its internals tweaked into a closed state. Change-Id: I0e9415ca3fdf50b9d6cdaccb24d7c4939b3b6ebd Reviewed-on: https://go-review.googlesource.com/c/net/+/701003 Reviewed-by: Nicholas Husin <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Nicholas Husin <[email protected]> Reviewed-by: Nicholas Husin <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent b9acd77 commit 30b0e78

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

http2/transport_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,17 +2904,20 @@ func TestTransportRequestPathPseudo(t *testing.T) {
29042904
// golang.org/issue/17071 -- don't sniff the first byte of the request body
29052905
// before we've determined that the ClientConn is usable.
29062906
func TestRoundTripDoesntConsumeRequestBodyEarly(t *testing.T) {
2907+
synctestTest(t, testRoundTripDoesntConsumeRequestBodyEarly)
2908+
}
2909+
func testRoundTripDoesntConsumeRequestBodyEarly(t testing.TB) {
2910+
tc := newTestClientConn(t)
2911+
tc.greet()
2912+
tc.closeWrite()
2913+
29072914
const body = "foo"
29082915
req, _ := http.NewRequest("POST", "http://foo.com/", io.NopCloser(strings.NewReader(body)))
2909-
cc := &ClientConn{
2910-
closed: true,
2911-
reqHeaderMu: make(chan struct{}, 1),
2912-
t: &Transport{},
2913-
}
2914-
_, err := cc.RoundTrip(req)
2915-
if err != errClientConnUnusable {
2916-
t.Fatalf("RoundTrip = %v; want errClientConnUnusable", err)
2916+
rt := tc.roundTrip(req)
2917+
if err := rt.err(); err != errClientConnNotEstablished {
2918+
t.Fatalf("RoundTrip = %v; want errClientConnNotEstablished", err)
29172919
}
2920+
29182921
slurp, err := io.ReadAll(req.Body)
29192922
if err != nil {
29202923
t.Errorf("ReadAll = %v", err)

0 commit comments

Comments
 (0)