Skip to content

Commit

Permalink
testing: use debug.SetTraceback("all") to show all goroutines at test…
Browse files Browse the repository at this point in the history
… timeout

Fixes golang#13681.

Change-Id: I308930f4d9200fbe0f09cd08c38392ca1bb0db67
Reviewed-on: https://go-review.googlesource.com/18044
Reviewed-by: Brad Fitzpatrick <[email protected]>
Reviewed-by: Austin Clements <[email protected]>
  • Loading branch information
rsc committed Dec 18, 2015
1 parent bb0567b commit 57337da
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/go/build/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var pkgDeps = map[string][]string{
"runtime/trace": {"L0"},
"text/tabwriter": {"L2"},

"testing": {"L2", "flag", "fmt", "os", "runtime/pprof", "runtime/trace", "time"},
"testing": {"L2", "flag", "fmt", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
"testing/iotest": {"L2", "log"},
"testing/quick": {"L2", "flag", "fmt", "reflect"},
"internal/testenv": {"L2", "os", "testing"},
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/debug/garbage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package debug
package debug_test

import (
"runtime"
. "runtime/debug"
"testing"
"time"
)
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/debug/heapdump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package debug
package debug_test

import (
"io/ioutil"
"os"
"runtime"
. "runtime/debug"
"testing"
)

Expand Down
9 changes: 5 additions & 4 deletions src/runtime/debug/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package debug
package debug_test

import (
. "runtime/debug"
"strings"
"testing"
)
Expand Down Expand Up @@ -51,9 +52,9 @@ func TestStack(t *testing.T) {
}
n++
frame("src/runtime/debug/stack.go", "runtime/debug.Stack")
frame("src/runtime/debug/stack_test.go", "runtime/debug.(*T).ptrmethod")
frame("src/runtime/debug/stack_test.go", "runtime/debug.T.method")
frame("src/runtime/debug/stack_test.go", "runtime/debug.TestStack")
frame("src/runtime/debug/stack_test.go", "runtime/debug_test.(*T).ptrmethod")
frame("src/runtime/debug/stack_test.go", "runtime/debug_test.T.method")
frame("src/runtime/debug/stack_test.go", "runtime/debug_test.TestStack")
frame("src/testing/testing.go", "")
}

Expand Down
2 changes: 2 additions & 0 deletions src/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ import (
"fmt"
"os"
"runtime"
"runtime/debug"
"runtime/pprof"
"runtime/trace"
"strconv"
Expand Down Expand Up @@ -714,6 +715,7 @@ var timer *time.Timer
func startAlarm() {
if *timeout > 0 {
timer = time.AfterFunc(*timeout, func() {
debug.SetTraceback("all")
panic(fmt.Sprintf("test timed out after %v", *timeout))
})
}
Expand Down

0 comments on commit 57337da

Please sign in to comment.