]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: remove TestTransportDialCancelRace
authorDamien Neil <dneil@google.com>
Thu, 23 May 2024 16:05:04 +0000 (09:05 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 23 May 2024 16:36:03 +0000 (16:36 +0000)
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 <austin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>

src/net/http/transport_test.go

index 25876e8d16879d13ad8035f70a92dd76c4abd150..aa877b57c796dde87e9fb5411dc36d3151175bc3 100644 (file)
@@ -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})