]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/tls: make -update only regenerate transcripts for failing tests
authorFilippo Valsorda <filippo@golang.org>
Wed, 30 Oct 2019 22:02:09 +0000 (18:02 -0400)
committerFilippo Valsorda <filippo@golang.org>
Mon, 4 Nov 2019 20:39:53 +0000 (20:39 +0000)
Change-Id: Ie68fd4fe2879e6b5417a1a4240971e3d837bf115
Reviewed-on: https://go-review.googlesource.com/c/go/+/204377
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/crypto/tls/handshake_client_test.go
src/crypto/tls/handshake_server_test.go
src/crypto/tls/handshake_test.go

index 1b6b9a1074dab7aa80becadb9d24dfe814b03aaf..d7b2db9347b07c271294ad6d0f02905a7394e789 100644 (file)
@@ -499,21 +499,15 @@ func peekError(conn net.Conn) error {
 }
 
 func runClientTestForVersion(t *testing.T, template *clientTest, version, option string) {
-       t.Run(version, func(t *testing.T) {
-               // Make a deep copy of the template before going parallel.
-               test := *template
-               if template.config != nil {
-                       test.config = template.config.Clone()
-               }
-
-               if !*update {
-                       t.Parallel()
-               }
+       // Make a deep copy of the template before going parallel.
+       test := *template
+       if template.config != nil {
+               test.config = template.config.Clone()
+       }
+       test.name = version + "-" + test.name
+       test.args = append([]string{option}, test.args...)
 
-               test.name = version + "-" + test.name
-               test.args = append([]string{option}, test.args...)
-               test.run(t, *update)
-       })
+       runTestAndUpdateIfNeeded(t, version, test.run, false)
 }
 
 func runClientTestTLS10(t *testing.T, template *clientTest) {
index e794ab856035793e97c0480ad13f4d4c127703a7..df1b2fa11799439a0c00a1bba5981ef53d60fd79 100644 (file)
@@ -729,25 +729,19 @@ func (test *serverTest) run(t *testing.T, write bool) {
 }
 
 func runServerTestForVersion(t *testing.T, template *serverTest, version, option string) {
-       t.Run(version, func(t *testing.T) {
-               // Make a deep copy of the template before going parallel.
-               test := *template
-               if template.config != nil {
-                       test.config = template.config.Clone()
-               }
-
-               if !*update && !template.wait {
-                       t.Parallel()
-               }
+       // Make a deep copy of the template before going parallel.
+       test := *template
+       if template.config != nil {
+               test.config = template.config.Clone()
+       }
+       test.name = version + "-" + test.name
+       if len(test.command) == 0 {
+               test.command = defaultClientCommand
+       }
+       test.command = append([]string(nil), test.command...)
+       test.command = append(test.command, option)
 
-               test.name = version + "-" + test.name
-               if len(test.command) == 0 {
-                       test.command = defaultClientCommand
-               }
-               test.command = append([]string(nil), test.command...)
-               test.command = append(test.command, option)
-               test.run(t, *update)
-       })
+       runTestAndUpdateIfNeeded(t, version, test.run, test.wait)
 }
 
 func runServerTestTLS10(t *testing.T, template *serverTest) {
index 01c234e60624cc62bb46cf9cf6cff92c77952dc8..baf8adb16d70dfe551c5ee1209bf789fda1ec74d 100644 (file)
@@ -37,17 +37,31 @@ import (
 // implementation.
 //
 // Tests can be updated by running them with the -update flag. This will cause
-// the test files to be regenerated. Generally one should combine the -update
-// flag with -test.run to updated a specific test. Since the reference
-// implementation will always generate fresh random numbers, large parts of
-// the reference connection will always change.
+// the test files for failing tests to be regenerated. Since the reference
+// implementation will always generate fresh random numbers, large parts of the
+// reference connection will always change.
 
 var (
-       update  = flag.Bool("update", false, "update golden files on disk")
+       update  = flag.Bool("update", false, "update golden files on failure")
        fast    = flag.Bool("fast", false, "impose a quick, possibly flaky timeout on recorded tests")
        keyFile = flag.String("keylog", "", "destination file for KeyLogWriter")
 )
 
+func runTestAndUpdateIfNeeded(t *testing.T, name string, run func(t *testing.T, update bool), wait bool) {
+       success := t.Run(name, func(t *testing.T) {
+               if !*update && !wait {
+                       t.Parallel()
+               }
+               run(t, false)
+       })
+
+       if !success && *update {
+               t.Run(name+"#update", func(t *testing.T) {
+                       run(t, true)
+               })
+       }
+}
+
 // checkOpenSSLVersion ensures that the version of OpenSSL looks reasonable
 // before updating the test data.
 func checkOpenSSLVersion() error {