]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: use synctest.Test rather than Run
authorDamien Neil <dneil@google.com>
Wed, 21 May 2025 20:24:49 +0000 (13:24 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 21 May 2025 23:06:11 +0000 (16:06 -0700)
Use the non-experimental Test function.
As a bonus, this lets us drop the hacks we were doing to support
t.Cleanup inside bubbles.

Change-Id: I070624e1384494e9d5fcfee594cfbb7680c1beda
Reviewed-on: https://go-review.googlesource.com/c/go/+/675315
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
src/net/http/clientserver_test.go
src/net/http/serve_test.go
src/net/http/transport_test.go

index 208c6509fac75892fabbecc785173b105b883e0c..c3cf3984ef1f6a8e5dfc0d624a327048a69f12ac 100644 (file)
@@ -15,7 +15,6 @@ import (
        "crypto/tls"
        "fmt"
        "hash"
-       "internal/synctest"
        "io"
        "log"
        "maps"
@@ -34,6 +33,7 @@ import (
        "sync"
        "sync/atomic"
        "testing"
+       "testing/synctest"
        "time"
 )
 
@@ -95,33 +95,13 @@ func run[T TBRun[T]](t T, f func(t T, mode testMode), opts ...any) {
        }
 }
 
-// cleanupT wraps a testing.T and adds its own Cleanup method.
-// Used to execute cleanup functions within a synctest bubble.
-type cleanupT struct {
-       *testing.T
-       cleanups []func()
-}
-
-// Cleanup replaces T.Cleanup.
-func (t *cleanupT) Cleanup(f func()) {
-       t.cleanups = append(t.cleanups, f)
-}
-
-func (t *cleanupT) done() {
-       for _, f := range slices.Backward(t.cleanups) {
-               f()
-       }
-}
-
 // runSynctest is run combined with synctest.Run.
 //
 // The TB passed to f arranges for cleanup functions to be run in the synctest bubble.
-func runSynctest(t *testing.T, f func(t testing.TB, mode testMode), opts ...any) {
+func runSynctest(t *testing.T, f func(t *testing.T, mode testMode), opts ...any) {
        run(t, func(t *testing.T, mode testMode) {
-               synctest.Run(func() {
-                       ct := &cleanupT{T: t}
-                       defer ct.done()
-                       f(ct, mode)
+               synctest.Test(t, func(t *testing.T) {
+                       f(t, mode)
                })
        }, opts...)
 }
@@ -292,12 +272,12 @@ func TestNewClientServerTest(t *testing.T) {
                }, modes)
        })
        t.Run("synctest", func(t *testing.T) {
-               runSynctest(t, func(t testing.TB, mode testMode) {
+               runSynctest(t, func(t *testing.T, mode testMode) {
                        testNewClientServerTest(t, mode, optFakeNet)
                }, modes)
        })
 }
-func testNewClientServerTest(t testing.TB, mode testMode, opts ...any) {
+func testNewClientServerTest(t *testing.T, mode testMode, opts ...any) {
        var got struct {
                sync.Mutex
                proto  string
index 84d383ccfa2171fd65561be4dd089bcffbd4f1f2..7e3e490af32679c5730f19f03b8860bc5cedd221 100644 (file)
@@ -5855,7 +5855,7 @@ func testServerShutdown(t *testing.T, mode testMode) {
 }
 
 func TestServerShutdownStateNew(t *testing.T) { runSynctest(t, testServerShutdownStateNew) }
-func testServerShutdownStateNew(t testing.TB, mode testMode) {
+func testServerShutdownStateNew(t *testing.T, mode testMode) {
        if testing.Short() {
                t.Skip("test takes 5-6 seconds; skipping in short mode")
        }
index 431dc4ee20ca4409af2b016f671f24b0698f4fd1..9762f058867dc17a6ece731a6d7f913af3acf98b 100644 (file)
@@ -4230,7 +4230,7 @@ func TestTransportIdleConnRacesRequest(t *testing.T) {
        // block the connection closing.
        runSynctest(t, testTransportIdleConnRacesRequest, []testMode{http1Mode, http2UnencryptedMode})
 }
-func testTransportIdleConnRacesRequest(t testing.TB, mode testMode) {
+func testTransportIdleConnRacesRequest(t *testing.T, mode testMode) {
        if mode == http2UnencryptedMode {
                t.Skip("remove skip when #70515 is fixed")
        }
@@ -4305,7 +4305,7 @@ func testTransportIdleConnRacesRequest(t testing.TB, mode testMode) {
 func TestTransportRemovesConnsAfterIdle(t *testing.T) {
        runSynctest(t, testTransportRemovesConnsAfterIdle)
 }
-func testTransportRemovesConnsAfterIdle(t testing.TB, mode testMode) {
+func testTransportRemovesConnsAfterIdle(t *testing.T, mode testMode) {
        if testing.Short() {
                t.Skip("skipping in short mode")
        }
@@ -4351,7 +4351,7 @@ func testTransportRemovesConnsAfterIdle(t testing.TB, mode testMode) {
 func TestTransportRemovesConnsAfterBroken(t *testing.T) {
        runSynctest(t, testTransportRemovesConnsAfterBroken)
 }
-func testTransportRemovesConnsAfterBroken(t testing.TB, mode testMode) {
+func testTransportRemovesConnsAfterBroken(t *testing.T, mode testMode) {
        if testing.Short() {
                t.Skip("skipping in short mode")
        }