From 30b0e78859f03d66b2e275870d5d37455d2f0fb0 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Fri, 5 Sep 2025 15:35:15 -0700 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Auto-Submit: Nicholas Husin Reviewed-by: Nicholas Husin Auto-Submit: Damien Neil --- http2/transport_test.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/http2/transport_test.go b/http2/transport_test.go index fa867f20..c46750ac 100644 --- a/http2/transport_test.go +++ b/http2/transport_test.go @@ -2904,17 +2904,20 @@ func TestTransportRequestPathPseudo(t *testing.T) { // golang.org/issue/17071 -- don't sniff the first byte of the request body // before we've determined that the ClientConn is usable. func TestRoundTripDoesntConsumeRequestBodyEarly(t *testing.T) { + synctestTest(t, testRoundTripDoesntConsumeRequestBodyEarly) +} +func testRoundTripDoesntConsumeRequestBodyEarly(t testing.TB) { + tc := newTestClientConn(t) + tc.greet() + tc.closeWrite() + const body = "foo" req, _ := http.NewRequest("POST", "http://foo.com/", io.NopCloser(strings.NewReader(body))) - cc := &ClientConn{ - closed: true, - reqHeaderMu: make(chan struct{}, 1), - t: &Transport{}, - } - _, err := cc.RoundTrip(req) - if err != errClientConnUnusable { - t.Fatalf("RoundTrip = %v; want errClientConnUnusable", err) + rt := tc.roundTrip(req) + if err := rt.err(); err != errClientConnNotEstablished { + t.Fatalf("RoundTrip = %v; want errClientConnNotEstablished", err) } + slurp, err := io.ReadAll(req.Body) if err != nil { t.Errorf("ReadAll = %v", err)