"crypto/tls"
"fmt"
"hash"
- "internal/synctest"
"io"
"log"
"maps"
"sync"
"sync/atomic"
"testing"
+ "testing/synctest"
"time"
)
}
}
-// 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...)
}
}, 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
}
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")
}
// 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")
}
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")
}
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")
}