From 3ed007d754b685cd8f6011a8e96a3c9303c785db Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Thu, 23 May 2024 09:05:04 -0700 Subject: [PATCH] net/http: remove TestTransportDialCancelRace This test was added to cover a specific race condition in request cancellation, applying only to the deprecated Transport.CancelRequest cancellation path. The test assumes that canceling a request at the moment persistConn.RoundTrip begins guarantees that it will be canceled before being sent. This does not apply to the newer forms of canceling a request: Request.Cancel and context-based cancellation both send the cancel signal on a channel, and do not check for cancellation before sending a request. A recent refactoring unified the implementation of cancellation, so the Transport.CancelRequest path now translates into context-based cancellation internally. This makes this test flaky, since sometimes the request completes before we read from the context's done channel. Drop the test entirely. It's verifying the fix for a bug in a code path which no longer exists, and the property that it's testing for (canceling a request at a very specific point in the internal request flow) is not interesting. Fixes #67533 Change-Id: I8d71540f1b44a64e0621d31a1c545c9351ae897c Reviewed-on: https://go-review.googlesource.com/c/go/+/587935 Reviewed-by: Austin Clements LUCI-TryBot-Result: Go LUCI Auto-Submit: Damien Neil --- src/net/http/transport_test.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 25876e8d16..aa877b57c7 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -4279,30 +4279,6 @@ func testTransportContentEncodingCaseInsensitive(t *testing.T, mode testMode) { } } -func TestTransportDialCancelRace(t *testing.T) { - run(t, testTransportDialCancelRace, testNotParallel, []testMode{http1Mode}) -} -func testTransportDialCancelRace(t *testing.T, mode testMode) { - ts := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {})).ts - tr := ts.Client().Transport.(*Transport) - - req, err := NewRequest("GET", ts.URL, nil) - if err != nil { - t.Fatal(err) - } - SetEnterRoundTripHook(func() { - tr.CancelRequest(req) - }) - defer SetEnterRoundTripHook(nil) - res, err := tr.RoundTrip(req) - if err != ExportErrRequestCanceled { - t.Errorf("expected canceled request error; got %v", err) - if err == nil { - res.Body.Close() - } - } -} - // https://go.dev/issue/49621 func TestConnClosedBeforeRequestIsWritten(t *testing.T) { run(t, testConnClosedBeforeRequestIsWritten, testNotParallel, []testMode{http1Mode}) -- 2.48.1