forked from mirror/ants
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) {
|
func TestNonblockingSubmitWithFunc(t *testing.T) {
|
||||||
poolSize := 10
|
poolSize := 10
|
||||||
ch1 := make(chan struct{})
|
var wg sync.WaitGroup
|
||||||
p, err := NewPoolWithFunc(poolSize, func(i interface{}) {
|
p, err := NewPoolWithFunc(poolSize, func(i interface{}) {
|
||||||
longRunningPoolFunc(i)
|
longRunningPoolFunc(i)
|
||||||
close(ch1)
|
wg.Done()
|
||||||
}, WithNonblocking(true))
|
}, WithNonblocking(true))
|
||||||
assert.NoError(t, err, "create TimingPool failed: %v", err)
|
assert.NoError(t, err, "create TimingPool failed: %v", err)
|
||||||
defer p.Release()
|
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{})
|
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.
|
// p is full now.
|
||||||
assert.NoError(t, p.Invoke(ch), "nonblocking submit when pool is not full shouldn't return error")
|
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(),
|
assert.EqualError(t, p.Invoke(nil), ErrPoolOverload.Error(),
|
||||||
"nonblocking submit when pool is full should get an ErrPoolOverload")
|
"nonblocking submit when pool is full should get an ErrPoolOverload")
|
||||||
// interrupt f to get an available worker
|
// interrupt f to get an available worker
|
||||||
close(ch)
|
close(ch)
|
||||||
<-ch1
|
wg.Wait()
|
||||||
assert.NoError(t, p.Invoke(nil), "nonblocking submit when pool is not full shouldn't return error")
|
assert.NoError(t, p.Invoke(nil), "nonblocking submit when pool is not full shouldn't return error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue