MCPcopy Create free account
hub / github.com/dc0d/workerpool / TestTimeoutNoGoroutineLeak

Function TestTimeoutNoGoroutineLeak

workerpool_usage_test.go:120–154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestTimeoutNoGoroutineLeak(t *testing.T) {
121 initialWorkers := 10
122 extraWorkers := 1000
123
124 pool := workerpool.New(initialWorkers, 2)
125
126 before := runtime.NumGoroutine()
127
128 pool.Expand(extraWorkers, time.Millisecond*100, nil)
129
130 go func() { // A
131 for i := 0; i < extraWorkers; i++ {
132 assert.True(t, pool.Queue(func() {
133 time.Sleep(time.Millisecond * 10)
134 }, 0))
135 }
136 }()
137
138 <-time.After(time.Millisecond * 500)
139 go func() {
140 for i := 0; i < initialWorkers*2; i++ {
141 assert.True(t, pool.Queue(func() {
142 time.Sleep(time.Millisecond * 10)
143 }, 0))
144 }
145 }()
146
147 <-time.After(time.Millisecond * 500)
148 after := runtime.NumGoroutine()
149 if (after - before) > (initialWorkers * 2) {
150 t.Fatal()
151 }
152
153 assert.NoError(t, waitFunc(pool.Stop, _timeout))
154}
155
156func ExampleWorkerPool() {
157 pool := workerpool.New(-1, 0)

Callers

nothing calls this directly

Calls 3

waitFuncFunction · 0.85
ExpandMethod · 0.80
QueueMethod · 0.80

Tested by

no test coverage detected