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)