@@ -16,6 +16,20 @@ import (
16
16
)
17
17
18
18
func TestMain (m * testing.M ) {
19
+ // Add all goroutines running at the start of the test to the set
20
+ // of not-leaked goroutines. This includes TestMain, and anything else
21
+ // that might have been started by test infrastructure.
22
+ skip := [][]byte {
23
+ []byte ("created by os/signal.Notify" ),
24
+ []byte ("gotraceback_test.go" ),
25
+ }
26
+ buf := make ([]byte , 2 << 20 )
27
+ buf = buf [:runtime .Stack (buf , true )]
28
+ for _ , g := range bytes .Split (buf , []byte ("\n \n " )) {
29
+ id , _ , _ := bytes .Cut (g , []byte ("[" ))
30
+ skip = append (skip , id )
31
+ }
32
+
19
33
defer os .Exit (m .Run ())
20
34
21
35
// Look for leaked goroutines.
@@ -34,12 +48,13 @@ func TestMain(m *testing.M) {
34
48
buf = buf [:runtime .Stack (buf , true )]
35
49
leaked := false
36
50
for _ , g := range bytes .Split (buf , []byte ("\n \n " )) {
37
- if bytes .Contains (g , []byte ("quic.TestMain" )) ||
38
- bytes .Contains (g , []byte ("created by os/signal.Notify" )) ||
39
- bytes .Contains (g , []byte ("gotraceback_test.go" )) {
40
- continue
41
- }
42
51
leaked = true
52
+ for _ , s := range skip {
53
+ if bytes .Contains (g , s ) {
54
+ leaked = false
55
+ break
56
+ }
57
+ }
43
58
}
44
59
if ! leaked {
45
60
break
0 commit comments