]> Cypherpunks repositories - gostls13.git/commitdiff
testing: don't fail all tests after racy test failure
authorIan Lance Taylor <iant@golang.org>
Tue, 8 Aug 2017 22:50:43 +0000 (15:50 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 15 Aug 2017 22:59:26 +0000 (22:59 +0000)
The code was adding race.Errors to t.raceErrors before checking
Failed, but Failed was using t.raceErrors+race.Errors. We don't want
to change Failed, since that would affect tests themselves, so modify
the harness to not unnecessarily change t.raceErrors.

Updates #19851
Fixes #21338
Change-Id: I7bfdf281f90e045146c92444f1370d55c45221d4
Reviewed-on: https://go-review.googlesource.com/54050
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/race/output_test.go
src/testing/testing.go

index e73e6b3bfc14c204edc406131cca3af71a8f7fea..13dfc33b477b0cee05cc9eab13cda38e0ac885d1 100644 (file)
@@ -259,4 +259,25 @@ Goroutine [0-9] \(running\) created at:
   runtime\.newextram\(\)
       .*/runtime/proc.go:[0-9]+ \+0x[0-9,a-f]+
 ==================`},
+       {"second_test_passes", "test", "", "atexit_sleep_ms=0", `
+package main_test
+import "testing"
+func TestFail(t *testing.T) {
+       done := make(chan bool)
+       x := 0
+       go func() {
+               x = 42
+               done <- true
+       }()
+       x = 43
+       <-done
+}
+
+func TestPass(t *testing.T) {
+}
+`, `
+==================
+--- FAIL: TestFail \(0...s\)
+.*testing.go:.*: race detected during execution of test
+FAIL`},
 }
index 02b2d730eb5408874e9582decb326cc08b55d3bb..93297b2dca432f6c73f87164d8901d15bad00791 100644 (file)
@@ -697,8 +697,7 @@ func tRunner(t *T, fn func(t *T)) {
        // a call to runtime.Goexit, record the duration and send
        // a signal saying that the test is done.
        defer func() {
-               t.raceErrors += race.Errors()
-               if t.raceErrors > 0 {
+               if t.raceErrors+race.Errors() > 0 {
                        t.Errorf("race detected during execution of test")
                }