From 747e1961e95c2eb3df62e045b90b111c2ceea337 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Mon, 3 Oct 2022 16:07:48 -0700 Subject: net/http: refactor tests to run most in HTTP/1 and HTTP/2 modes Replace the ad-hoc approach to running tests in HTTP/1 and HTTP/2 modes with a 'run' function that executes a test in various modes. By default, these modes are HTTP/1 and HTTP/2, but tests can opt-in to HTTPS/1 as well. The 'run' function also takes care of post-test cleanup (running the afterTest function). The 'run' function runs tests in parallel by default. Tests which can't run in parallel (generally because they use global test hooks) pass a testNotParallel option to disable parallelism. Update clientServerTest to use t.Cleanup to clean up after itself, rather than leaving this up to tests to handle. Drop an unnecessary mutex in SetReadLoopBeforeNextReadHook. Test hooks can't be set in parallel, and we want the race detector to notify us if two simultaneous tests try to set a hook. Fixes #56032 Change-Id: I16be64913c426fc93d84abc6ad85dbd3bc191224 Reviewed-on: https://go-review.googlesource.com/c/go/+/438137 TryBot-Result: Gopher Robot Run-TryBot: Damien Neil Reviewed-by: Brad Fitzpatrick Reviewed-by: David Chase --- src/net/http/export_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/net/http/export_test.go') diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go index 205ca83f40..fb5ab9396a 100644 --- a/src/net/http/export_test.go +++ b/src/net/http/export_test.go @@ -60,7 +60,7 @@ func init() { } } -func CondSkipHTTP2(t *testing.T) { +func CondSkipHTTP2(t testing.TB) { if omitBundledHTTP2 { t.Skip("skipping HTTP/2 test when nethttpomithttp2 build tag in use") } @@ -72,8 +72,6 @@ var ( ) func SetReadLoopBeforeNextReadHook(f func()) { - testHookMu.Lock() - defer testHookMu.Unlock() unnilTestHook(&f) testHookReadLoopBeforeNextRead = f } -- cgit v1.3