mirror of
https://github.com/panjf2000/ants.git
synced 2025-12-16 09:51:02 +00:00
bug: don't reset the worker queue when rebooting preallocated pool (#360)
Fixes #358
This commit is contained in:
parent
1bf9cfdd1b
commit
a44594205e
68
ants_test.go
68
ants_test.go
@ -1535,3 +1535,71 @@ func TestMultiPoolWithFuncGeneric(t *testing.T) {
|
|||||||
|
|
||||||
mp.Tune(10)
|
mp.Tune(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRebootNewPoolCalc(t *testing.T) {
|
||||||
|
atomic.StoreInt32(&sum, 0)
|
||||||
|
runTimes := 1000
|
||||||
|
wg.Add(runTimes)
|
||||||
|
|
||||||
|
pool, err := ants.NewPool(10)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer pool.Release()
|
||||||
|
// Use the default pool.
|
||||||
|
for i := 0; i < runTimes; i++ {
|
||||||
|
j := i
|
||||||
|
_ = pool.Submit(func() {
|
||||||
|
incSumInt(int32(j))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
require.EqualValues(t, 499500, sum, "The result should be 499500")
|
||||||
|
|
||||||
|
atomic.StoreInt32(&sum, 0)
|
||||||
|
wg.Add(runTimes)
|
||||||
|
err = pool.ReleaseTimeout(time.Second) // use both Release and ReleaseTimeout will occur panic
|
||||||
|
require.NoError(t, err)
|
||||||
|
pool.Reboot()
|
||||||
|
|
||||||
|
for i := 0; i < runTimes; i++ {
|
||||||
|
j := i
|
||||||
|
_ = pool.Submit(func() {
|
||||||
|
incSumInt(int32(j))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
require.EqualValues(t, 499500, sum, "The result should be 499500")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRebootNewPoolWithPreAllocCalc(t *testing.T) {
|
||||||
|
atomic.StoreInt32(&sum, 0)
|
||||||
|
runTimes := 1000
|
||||||
|
wg.Add(runTimes)
|
||||||
|
|
||||||
|
pool, err := ants.NewPool(10, ants.WithPreAlloc(true))
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer pool.Release()
|
||||||
|
// Use the default pool.
|
||||||
|
for i := 0; i < runTimes; i++ {
|
||||||
|
j := i
|
||||||
|
_ = pool.Submit(func() {
|
||||||
|
incSumInt(int32(j))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
require.EqualValues(t, 499500, sum, "The result should be 499500")
|
||||||
|
|
||||||
|
atomic.StoreInt32(&sum, 0)
|
||||||
|
err = pool.ReleaseTimeout(time.Second)
|
||||||
|
require.NoError(t, err)
|
||||||
|
pool.Reboot()
|
||||||
|
|
||||||
|
wg.Add(runTimes)
|
||||||
|
for i := 0; i < runTimes; i++ {
|
||||||
|
j := i
|
||||||
|
_ = pool.Submit(func() {
|
||||||
|
incSumInt(int32(j))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
require.EqualValues(t, 499500, sum, "The result should be 499500")
|
||||||
|
}
|
||||||
|
|||||||
@ -170,8 +170,6 @@ retry:
|
|||||||
w.finish()
|
w.finish()
|
||||||
goto retry
|
goto retry
|
||||||
}
|
}
|
||||||
wq.items = wq.items[:0]
|
|
||||||
wq.size = 0
|
|
||||||
wq.head = 0
|
wq.head = 0
|
||||||
wq.tail = 0
|
wq.tail = 0
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user