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 <nsh@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
This commit is contained in:
Damien Neil
2025-09-05 15:35:15 -07:00
committed by Gopher Robot
parent b9acd777f1
commit 30b0e78859

View File

@@ -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)