1
2
3
4
5
12 package main
13
14 import (
15 "math/rand"
16 "os"
17 "runtime"
18 "runtime/pprof"
19 )
20
21 func init() {
22 register("Grpc660", Grpc660)
23 }
24
25 type benchmarkClient_grpc660 struct {
26 stop chan bool
27 }
28
29 func (bc *benchmarkClient_grpc660) doCloseLoopUnary() {
30 for {
31 done := make(chan bool)
32 go func() {
33 if rand.Intn(10) > 7 {
34 done <- false
35 return
36 }
37 done <- true
38 }()
39 select {
40 case <-bc.stop:
41 return
42 case <-done:
43 }
44 }
45 }
46
47 func Grpc660() {
48 prof := pprof.Lookup("goroutineleak")
49 defer func() {
50
51 for i := 0; i < yieldCount; i++ {
52 runtime.Gosched()
53 }
54 prof.WriteTo(os.Stdout, 2)
55 }()
56 go func() {
57 bc := &benchmarkClient_grpc660{
58 stop: make(chan bool),
59 }
60 go bc.doCloseLoopUnary()
61 go func() {
62 bc.stop <- true
63 }()
64 }()
65 }
66
View as plain text