Skip to content

Commit a130fcc

Browse files
committed
quic: don't consider goroutines running when tests start as leaked
Change-Id: I138e284ee74c9402402f564d25e50ab753c51e9e Reviewed-on: https://go-review.googlesource.com/c/net/+/576536 Reviewed-by: Chressie Himpel <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 7bbe320 commit a130fcc

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Diff for: quic/main_test.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ import (
1616
)
1717

1818
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+
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

Comments
 (0)