...
1
2
3
4
5
6
7 package quic
8
9 import (
10 "bytes"
11 "fmt"
12 "os"
13 "runtime"
14 "testing"
15 "time"
16 )
17
18 func TestMain(m *testing.M) {
19
20
21
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
33 defer os.Exit(m.Run())
34
35
36
37
38
39 if runtime.GOOS == "js" {
40
41
42 return
43 }
44 start := time.Now()
45 warned := false
46 for {
47 buf := make([]byte, 2<<20)
48 buf = buf[:runtime.Stack(buf, true)]
49 leaked := false
50 for _, g := range bytes.Split(buf, []byte("\n\n")) {
51 leaked = true
52 for _, s := range skip {
53 if bytes.Contains(g, s) {
54 leaked = false
55 break
56 }
57 }
58 }
59 if !leaked {
60 break
61 }
62 if !warned && time.Since(start) > 1*time.Second {
63
64
65 fmt.Printf("Tests seem to have leaked some goroutines, still waiting.\n\n")
66 fmt.Print(string(buf))
67 warned = true
68 }
69
70 time.Sleep(1 * time.Millisecond)
71 }
72 }
73
View as plain text