File tree Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Expand file tree Collapse file tree 2 files changed +25
-13
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -9,21 +9,33 @@ import (
99
1010func 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}
You can’t perform that action at this time.
0 commit comments