From 3dc6b2757e018fd67d44368f4c169fca75565f59 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 4 Nov 2016 05:28:01 +0000 Subject: [PATCH] all: sprinkle t.Parallel on some slow tests I used the slowtests.go tool as described in https://golang.org/cl/32684 on packages that stood out. go test -short std drops from ~56 to ~52 seconds. This isn't a huge win, but it was mostly an exercise. Updates #17751 Change-Id: I9f3402e36a038d71e662d06ce2c1d52f6c4b674d Reviewed-on: https://go-review.googlesource.com/32751 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- handshake_client_test.go | 21 +++++++++++++++++++++ handshake_server_test.go | 2 ++ tls_test.go | 1 + 3 files changed, 24 insertions(+) diff --git a/handshake_client_test.go b/handshake_client_test.go index d603915..69ac15b 100644 --- a/handshake_client_test.go +++ b/handshake_client_test.go @@ -22,6 +22,7 @@ import ( "path/filepath" "strconv" "strings" + "sync" "testing" "time" ) @@ -420,7 +421,26 @@ func (test *clientTest) run(t *testing.T, write bool) { } } +var ( + didParMu sync.Mutex + didPar = map[*testing.T]bool{} +) + +// setParallel calls t.Parallel once. If you call it twice, it would +// panic. +func setParallel(t *testing.T) { + didParMu.Lock() + v := didPar[t] + didPar[t] = true + didParMu.Unlock() + if !v { + t.Parallel() + } +} + func runClientTestForVersion(t *testing.T, template *clientTest, prefix, option string) { + setParallel(t) + test := *template test.name = prefix + test.name if len(test.command) == 0 { @@ -1356,6 +1376,7 @@ func TestAlertFlushing(t *testing.T) { } func TestHandshakeRace(t *testing.T) { + t.Parallel() // This test races a Read and Write to try and complete a handshake in // order to provide some evidence that there are no races or deadlocks // in the handshake locking. diff --git a/handshake_server_test.go b/handshake_server_test.go index 765a974..fa93c8a 100644 --- a/handshake_server_test.go +++ b/handshake_server_test.go @@ -660,6 +660,7 @@ func (test *serverTest) run(t *testing.T, write bool) { } func runServerTestForVersion(t *testing.T, template *serverTest, prefix, option string) { + setParallel(t) test := *template test.name = prefix + test.name if len(test.command) == 0 { @@ -1054,6 +1055,7 @@ FMBexFe01MNvja5oHt1vzobhfm6ySD6B5U7ixohLZNz1MLvT/2XMW/TdtWo+PtAd -----END EC PRIVATE KEY-----` func TestClientAuth(t *testing.T) { + setParallel(t) var certPath, keyPath, ecdsaCertPath, ecdsaKeyPath string if *update { diff --git a/tls_test.go b/tls_test.go index a0c0908..83b1f4c 100644 --- a/tls_test.go +++ b/tls_test.go @@ -99,6 +99,7 @@ var keyPairTests = []struct { } func TestX509KeyPair(t *testing.T) { + t.Parallel() var pem []byte for _, test := range keyPairTests { pem = []byte(test.cert + test.key)