aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-01-11 14:06:45 -0800
committerIan Lance Taylor <iant@golang.org>2019-01-17 01:28:22 +0000
commit006a5e7d00992cfae6ac406959512d680025f75c (patch)
tree4737806d7e24c2ac7ec3632c85510e00e60a182c /src/testing/testing.go
parent0456036e28b718d215f49abe83d3c49101f8a4c7 (diff)
downloadgo-006a5e7d00992cfae6ac406959512d680025f75c.tar.xz
testing: report the failing test in a late log panic
Updates #29388 Change-Id: Icb0e6048d05fde7a5486b923ff62147edb5c8dac Reviewed-on: https://go-review.googlesource.com/c/157617 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 0ac51b6fe5..3068630e8a 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -618,17 +618,20 @@ func (c *common) log(s string) {
func (c *common) logDepth(s string, depth int) {
c.mu.Lock()
defer c.mu.Unlock()
- // If this test has already finished try and log this message with our parent
- // with this test name tagged so we know where it came from.
- // If we don't have a parent panic.
- if c.done {
- if c.parent != nil {
- c.parent.logDepth(s, depth+1)
- } else {
- panic("Log in goroutine after " + c.name + " has completed")
- }
- } else {
+ if !c.done {
c.output = append(c.output, c.decorate(s, depth+1)...)
+ } else {
+ // This test has already finished. Try and log this message
+ // with our parent. If we don't have a parent, panic.
+ for parent := c.parent; parent != nil; parent = parent.parent {
+ parent.mu.Lock()
+ defer parent.mu.Unlock()
+ if !parent.done {
+ parent.output = append(parent.output, parent.decorate(s, depth+1)...)
+ return
+ }
+ }
+ panic("Log in goroutine after " + c.name + " has completed")
}
}