Skip to content

Commit f452b03

Browse files
committed
fix
1 parent 594fb26 commit f452b03

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

internal/xtest/leak.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99
)
1010

11-
func checkGoroutinesLeak(onLeak func(stacks []string)) {
11+
func checkGoroutinesLeak(onLeak func(goroutines []string)) {
1212
var (
1313
bb = make([]byte, 2<<32)
1414
currentGoroutine string

internal/xtest/leak_test.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,33 @@ import (
99

1010
func TestCheckGoroutinesLeak(t *testing.T) {
1111
t.Run("Leak", func(t *testing.T) {
12-
require.Panics(t, func() {
13-
defer checkGoroutinesLeak(func(stacks []string) {
14-
panic("panic")
12+
TestManyTimes(t, func(t testing.TB) {
13+
ch := make(chan struct{})
14+
require.Panics(t, func() {
15+
defer checkGoroutinesLeak(func(goroutines []string) {
16+
panic("panic")
17+
})
18+
go func() {
19+
<-ch
20+
}()
1521
})
16-
go func() {
17-
time.Sleep(time.Second)
18-
}()
19-
})
22+
close(ch)
23+
}, StopAfter(13*time.Second))
2024
})
2125
t.Run("NoLeak", func(t *testing.T) {
22-
require.NotPanics(t, func() {
23-
defer checkGoroutinesLeak(func(stacks []string) {
24-
panic("panic")
26+
TestManyTimes(t, func(t testing.TB) {
27+
ch := make(chan struct{})
28+
require.NotPanics(t, func() {
29+
defer checkGoroutinesLeak(func(goroutines []string) {
30+
panic("panic")
31+
})
32+
defer func() {
33+
<-ch
34+
}()
35+
go func() {
36+
close(ch)
37+
}()
2538
})
26-
time.Sleep(time.Second)
27-
})
39+
}, StopAfter(13*time.Second))
2840
})
2941
}

0 commit comments

Comments
 (0)