From 221541ec8c4ec1b0ed0c6f26f5e13ca128e2a3cd Mon Sep 17 00:00:00 2001 From: Caleb Spare Date: Thu, 6 Apr 2017 18:47:01 -0700 Subject: [PATCH] testing: consider a test failed after race errors Fixes #19851. Change-Id: I5ee9533406542be7d5418df154f6134139e75892 Reviewed-on: https://go-review.googlesource.com/39890 Run-TryBot: Caleb Spare TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/runtime/race/output_test.go | 2 ++ src/testing/testing.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/runtime/race/output_test.go b/src/runtime/race/output_test.go index 587540f5e8..e73e6b3bfc 100644 --- a/src/runtime/race/output_test.go +++ b/src/runtime/race/output_test.go @@ -181,10 +181,12 @@ func TestFail(t *testing.T) { }() x = 43 <-done + t.Log(t.Failed()) } `, ` ================== --- FAIL: TestFail \(0...s\) +.*main_test.go:13: true .*testing.go:.*: race detected during execution of test FAIL`}, diff --git a/src/testing/testing.go b/src/testing/testing.go index d63d5d85a7..130977f106 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -450,8 +450,9 @@ func (c *common) Fail() { // Failed reports whether the function has failed. func (c *common) Failed() bool { c.mu.RLock() - defer c.mu.RUnlock() - return c.failed + failed := c.failed + c.mu.RUnlock() + return failed || c.raceErrors+race.Errors() > 0 } // FailNow marks the function as having failed and stops its execution. -- 2.48.1