diff options
| author | Damien Neil <dneil@google.com> | 2024-06-11 13:44:43 -0700 |
|---|---|---|
| committer | Damien Neil <dneil@google.com> | 2024-11-25 22:02:07 +0000 |
| commit | 592da0ba474b94b6eceee62b5613f1c9c1ed9c89 (patch) | |
| tree | cd80e8f0a46b41b2906eab94f8e45226fea8b52e /src/net/http/clientserver_test.go | |
| parent | fb5fa2a839ef0ea9952e47f6d0e05b51a5a51a8d (diff) | |
| download | go-592da0ba474b94b6eceee62b5613f1c9c1ed9c89.tar.xz | |
net/http: run TestServerShutdownStateNew in a synctest bubble
Took ~12s previously, ~0s now.
Change-Id: I72580fbde73482a40142cf84cd3d78a50afb9f44
Reviewed-on: https://go-review.googlesource.com/c/go/+/630382
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'src/net/http/clientserver_test.go')
| -rw-r--r-- | src/net/http/clientserver_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/net/http/clientserver_test.go b/src/net/http/clientserver_test.go index 606715a25c..0873038757 100644 --- a/src/net/http/clientserver_test.go +++ b/src/net/http/clientserver_test.go @@ -15,6 +15,7 @@ import ( "crypto/tls" "fmt" "hash" + "internal/synctest" "io" "log" "maps" @@ -93,6 +94,37 @@ 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) { + run(t, func(t *testing.T, mode testMode) { + synctest.Run(func() { + ct := &cleanupT{T: t} + defer ct.done() + f(ct, mode) + }) + }, opts...) +} + type clientServerTest struct { t testing.TB h2 bool |
