-
Notifications
You must be signed in to change notification settings - Fork 2
/
hang.go
38 lines (27 loc) · 862 Bytes
/
hang.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Include:
import (
_ "github.com/TyeMcQueen/go-tutl/hang" // ^C gives stack dumps.
)
in just one of your *_test.go files (per module) so that you can interrupt
(such as via typing Ctrl-C) an infinite loop or otherwise hanging test run
and be shown, in response, the stack traces of everything that is running.
If you have your own TestMain() function, then just call:
go tutl.ShowStackOnInterrupt()
from it rather than loading this module (which would fail).
Note that loading this module does nothing useful in non-test code.
*/
package hang
import (
"fmt"
"os"
"testing"
"github.com/TyeMcQueen/go-tutl"
)
// If your tests hang, interrupt them (Ctrl-C) to get stack dumps of what is
// running.
func TestMain(m *testing.M) {
go tutl.ShowStackOnInterrupt()
fmt.Fprintln(os.Stderr, "Will show stack traces on Ctrl-C.")
os.Exit(m.Run())
}