...
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 defer os.Exit(m.Run())
20
21
22
23
24
25 if runtime.GOOS == "js" {
26
27
28 return
29 }
30 start := time.Now()
31 warned := false
32 for {
33 buf := make([]byte, 2<<20)
34 buf = buf[:runtime.Stack(buf, true)]
35 leaked := false
36 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 leaked = true
43 }
44 if !leaked {
45 break
46 }
47 if !warned && time.Since(start) > 1*time.Second {
48
49
50 fmt.Printf("Tests seem to have leaked some goroutines, still waiting.\n\n")
51 fmt.Print(string(buf))
52 warned = true
53 }
54
55 time.Sleep(1 * time.Millisecond)
56 }
57 }
58
View as plain text