diff options
| author | Changkun Ou <hi@changkun.us> | 2020-02-28 21:53:38 +0100 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2020-03-19 21:07:59 +0000 |
| commit | 93a9561b23b782244a7c5d77efe71f57dee8c4a5 (patch) | |
| tree | 90838211cd89c3a19b7020435a389b05d899a905 /src/testing | |
| parent | a4c48d61f59177e1b6de1efd6a232fac7e8e112f (diff) | |
| download | go-93a9561b23b782244a7c5d77efe71f57dee8c4a5.tar.xz | |
testing: fix data race between parallel subtests
This CL fixes a race condition if there are two subtests, and
one finishing but the other is panicking.
Fixes #37551
Change-Id: Ic33963eb338aec228964b95f7c34a0d207b91e00
Reviewed-on: https://go-review.googlesource.com/c/go/+/221322
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/testing')
| -rw-r--r-- | src/testing/testing.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 5c78d9b741..85a92c9384 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -928,16 +928,15 @@ func tRunner(t *T, fn func(t *T)) { t.Logf("cleanup panicked with %v", r) } // Flush the output log up to the root before dying. - t.mu.Lock() - root := &t.common - for ; root.parent != nil; root = root.parent { + for root := &t.common; root.parent != nil; root = root.parent { + root.mu.Lock() root.duration += time.Since(root.start) - fmt.Fprintf(root.parent.w, "--- FAIL: %s (%s)\n", root.name, fmtDuration(root.duration)) + d := root.duration + root.mu.Unlock() + root.flushToParent("--- FAIL: %s (%s)\n", root.name, fmtDuration(d)) if r := root.parent.runCleanup(recoverAndReturnPanic); r != nil { fmt.Fprintf(root.parent.w, "cleanup panicked with %v", r) } - root.parent.mu.Lock() - io.Copy(root.parent.w, bytes.NewReader(root.output)) } panic(err) } |
