@@ -1535,3 +1535,71 @@ func TestMultiPoolWithFuncGeneric(t *testing.T) {
15351535
15361536 mp .Tune (10 )
15371537}
1538+
1539+ func TestRebootNewPoolCalc (t * testing.T ) {
1540+ atomic .StoreInt32 (& sum , 0 )
1541+ runTimes := 1000
1542+ wg .Add (runTimes )
1543+
1544+ pool , err := ants .NewPool (10 )
1545+ require .NoError (t , err )
1546+ defer pool .Release ()
1547+ // Use the default pool.
1548+ for i := 0 ; i < runTimes ; i ++ {
1549+ j := i
1550+ _ = pool .Submit (func () {
1551+ incSumInt (int32 (j ))
1552+ })
1553+ }
1554+ wg .Wait ()
1555+ require .EqualValues (t , 499500 , sum , "The result should be 499500" )
1556+
1557+ atomic .StoreInt32 (& sum , 0 )
1558+ wg .Add (runTimes )
1559+ err = pool .ReleaseTimeout (time .Second ) // use both Release and ReleaseTimeout will occur panic
1560+ require .NoError (t , err )
1561+ pool .Reboot ()
1562+
1563+ for i := 0 ; i < runTimes ; i ++ {
1564+ j := i
1565+ _ = pool .Submit (func () {
1566+ incSumInt (int32 (j ))
1567+ })
1568+ }
1569+ wg .Wait ()
1570+ require .EqualValues (t , 499500 , sum , "The result should be 499500" )
1571+ }
1572+
1573+ func TestRebootNewPoolWithPreAllocCalc (t * testing.T ) {
1574+ atomic .StoreInt32 (& sum , 0 )
1575+ runTimes := 1000
1576+ wg .Add (runTimes )
1577+
1578+ pool , err := ants .NewPool (10 , ants .WithPreAlloc (true ))
1579+ require .NoError (t , err )
1580+ defer pool .Release ()
1581+ // Use the default pool.
1582+ for i := 0 ; i < runTimes ; i ++ {
1583+ j := i
1584+ _ = pool .Submit (func () {
1585+ incSumInt (int32 (j ))
1586+ })
1587+ }
1588+ wg .Wait ()
1589+ require .EqualValues (t , 499500 , sum , "The result should be 499500" )
1590+
1591+ atomic .StoreInt32 (& sum , 0 )
1592+ err = pool .ReleaseTimeout (time .Second )
1593+ require .NoError (t , err )
1594+ pool .Reboot ()
1595+
1596+ wg .Add (runTimes )
1597+ for i := 0 ; i < runTimes ; i ++ {
1598+ j := i
1599+ _ = pool .Submit (func () {
1600+ incSumInt (int32 (j ))
1601+ })
1602+ }
1603+ wg .Wait ()
1604+ require .EqualValues (t , 499500 , sum , "The result should be 499500" )
1605+ }
0 commit comments