@@ -16,6 +16,20 @@ import (
1616)
1717
1818func 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+
1933 defer os .Exit (m .Run ())
2034
2135 // Look for leaked goroutines.
@@ -34,12 +48,13 @@ func TestMain(m *testing.M) {
3448 buf = buf [:runtime .Stack (buf , true )]
3549 leaked := false
3650 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- }
4251 leaked = true
52+ for _ , s := range skip {
53+ if bytes .Contains (g , s ) {
54+ leaked = false
55+ break
56+ }
57+ }
4358 }
4459 if ! leaked {
4560 break
0 commit comments