(t *testing.T)
| 1504 | } |
| 1505 | |
| 1506 | func TestMultiPoolWithFuncGeneric(t *testing.T) { |
| 1507 | _, err := ants.NewMultiPoolWithFuncGeneric(-1, 10, longRunningPoolFuncCh, 8) |
| 1508 | require.ErrorIs(t, err, ants.ErrInvalidMultiPoolSize) |
| 1509 | _, err = ants.NewMultiPoolWithFuncGeneric(10, -1, longRunningPoolFuncCh, 8) |
| 1510 | require.ErrorIs(t, err, ants.ErrInvalidLoadBalancingStrategy) |
| 1511 | _, err = ants.NewMultiPoolWithFuncGeneric(10, 10, longRunningPoolFuncCh, ants.RoundRobin, ants.WithExpiryDuration(-1)) |
| 1512 | require.ErrorIs(t, err, ants.ErrInvalidPoolExpiry) |
| 1513 | |
| 1514 | ch := make(chan struct{}) |
| 1515 | mp, err := ants.NewMultiPoolWithFuncGeneric(10, 5, longRunningPoolFuncCh, ants.RoundRobin) |
| 1516 | testFn := func() { |
| 1517 | for i := 0; i < 50; i++ { |
| 1518 | err = mp.Invoke(ch) |
| 1519 | require.NoError(t, err) |
| 1520 | } |
| 1521 | require.EqualValues(t, mp.Waiting(), 0) |
| 1522 | _, err = mp.WaitingByIndex(-1) |
| 1523 | require.ErrorIs(t, err, ants.ErrInvalidPoolIndex) |
| 1524 | _, err = mp.WaitingByIndex(11) |
| 1525 | require.ErrorIs(t, err, ants.ErrInvalidPoolIndex) |
| 1526 | require.EqualValues(t, 50, mp.Running()) |
| 1527 | _, err = mp.RunningByIndex(-1) |
| 1528 | require.ErrorIs(t, err, ants.ErrInvalidPoolIndex) |
| 1529 | _, err = mp.RunningByIndex(11) |
| 1530 | require.ErrorIs(t, err, ants.ErrInvalidPoolIndex) |
| 1531 | require.EqualValues(t, 0, mp.Free()) |
| 1532 | _, err = mp.FreeByIndex(-1) |
| 1533 | require.ErrorIs(t, err, ants.ErrInvalidPoolIndex) |
| 1534 | _, err = mp.FreeByIndex(11) |
| 1535 | require.ErrorIs(t, err, ants.ErrInvalidPoolIndex) |
| 1536 | require.EqualValues(t, 50, mp.Cap()) |
| 1537 | require.False(t, mp.IsClosed()) |
| 1538 | for i := 0; i < 10; i++ { |
| 1539 | n, _ := mp.WaitingByIndex(i) |
| 1540 | require.EqualValues(t, 0, n) |
| 1541 | n, _ = mp.RunningByIndex(i) |
| 1542 | require.EqualValues(t, 5, n) |
| 1543 | n, _ = mp.FreeByIndex(i) |
| 1544 | require.EqualValues(t, 0, n) |
| 1545 | } |
| 1546 | close(ch) |
| 1547 | require.NoError(t, mp.ReleaseTimeout(3*time.Second)) |
| 1548 | require.ErrorIs(t, mp.ReleaseTimeout(3*time.Second), ants.ErrPoolClosed) |
| 1549 | require.ErrorIs(t, mp.Invoke(nil), ants.ErrPoolClosed) |
| 1550 | require.Zero(t, mp.Running()) |
| 1551 | require.True(t, mp.IsClosed()) |
| 1552 | ch = make(chan struct{}) |
| 1553 | } |
| 1554 | testFn() |
| 1555 | |
| 1556 | mp.Reboot() |
| 1557 | testFn() |
| 1558 | |
| 1559 | mp, err = ants.NewMultiPoolWithFuncGeneric(10, 5, longRunningPoolFuncCh, ants.LeastTasks) |
| 1560 | testFn() |
| 1561 | |
| 1562 | mp.Reboot() |
| 1563 | testFn() |
nothing calls this directly
no test coverage detected
searching dependent graphs…