Merge pull request #361 from panjf2000/dev

patch: v2.11.2
This commit is contained in:
Andy Pan 2025-03-07 23:27:59 +08:00 committed by GitHub
commit 711d58609b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 68 additions and 2 deletions

View File

@ -1535,3 +1535,71 @@ func TestMultiPoolWithFuncGeneric(t *testing.T) {
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")
}

View File

@ -170,8 +170,6 @@ retry:
w.finish()
goto retry
}
wq.items = wq.items[:0]
wq.size = 0
wq.head = 0
wq.tail = 0
}