mirror of https://github.com/panjf2000/ants.git
Fix the timing issue in the TestNonblockingSubmitWithFunc (#172)
On some machines this unit would fail due to a timing issue. Since the Invoke in the loop was using nil as the param, it would (depending on timing) lead to the workers finishing the (w *goWorkerWithFunc) run() in the range loop over w.args as args would == nil and return. If an explicit time.Sleep(1 * time.Second) is added before the " assert.EqualError(t, p.Invoke(nil), ErrPoolOverload.Error()," it is easily reproducible. Co-authored-by: Jeffrey Damick <jdamick@amazon.com>
This commit is contained in:
parent
4b16a81116
commit
63489606ef
13
ants_test.go
13
ants_test.go
|
@ -427,24 +427,25 @@ func TestMaxBlockingSubmit(t *testing.T) {
|
|||
|
||||
func TestNonblockingSubmitWithFunc(t *testing.T) {
|
||||
poolSize := 10
|
||||
ch1 := make(chan struct{})
|
||||
var wg sync.WaitGroup
|
||||
p, err := NewPoolWithFunc(poolSize, func(i interface{}) {
|
||||
longRunningPoolFunc(i)
|
||||
close(ch1)
|
||||
wg.Done()
|
||||
}, WithNonblocking(true))
|
||||
assert.NoError(t, err, "create TimingPool failed: %v", err)
|
||||
defer p.Release()
|
||||
for i := 0; i < poolSize-1; i++ {
|
||||
assert.NoError(t, p.Invoke(nil), "nonblocking submit when pool is not full shouldn't return error")
|
||||
}
|
||||
ch := make(chan struct{})
|
||||
wg.Add(poolSize)
|
||||
for i := 0; i < poolSize-1; i++ {
|
||||
assert.NoError(t, p.Invoke(ch), "nonblocking submit when pool is not full shouldn't return error")
|
||||
}
|
||||
// p is full now.
|
||||
assert.NoError(t, p.Invoke(ch), "nonblocking submit when pool is not full shouldn't return error")
|
||||
assert.EqualError(t, p.Invoke(nil), ErrPoolOverload.Error(),
|
||||
"nonblocking submit when pool is full should get an ErrPoolOverload")
|
||||
// interrupt f to get an available worker
|
||||
close(ch)
|
||||
<-ch1
|
||||
wg.Wait()
|
||||
assert.NoError(t, p.Invoke(nil), "nonblocking submit when pool is not full shouldn't return error")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue