Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions ants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 0 additions & 2 deletions worker_loop_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ retry:
w.finish()
goto retry
}
wq.items = wq.items[:0]
wq.size = 0
wq.head = 0
wq.tail = 0
}
Loading