(t *testing.T)
| 1697 | } |
| 1698 | |
| 1699 | func TestMultiPoolWithFuncGenericReleaseContext(t *testing.T) { |
| 1700 | ch := make(chan struct{}) |
| 1701 | mp, err := ants.NewMultiPoolWithFuncGeneric(10, 5, longRunningPoolFuncCh, ants.RoundRobin) |
| 1702 | require.NoError(t, err) |
| 1703 | |
| 1704 | for i := 0; i < 50; i++ { |
| 1705 | err = mp.Invoke(ch) |
| 1706 | require.NoError(t, err) |
| 1707 | } |
| 1708 | require.EqualValues(t, 50, mp.Running()) |
| 1709 | |
| 1710 | close(ch) |
| 1711 | err = mp.ReleaseContext(context.Background()) |
| 1712 | require.NoError(t, err) |
| 1713 | require.Zero(t, mp.Running()) |
| 1714 | require.True(t, mp.IsClosed()) |
| 1715 | |
| 1716 | // Calling ReleaseContext on a closed pool should return ErrPoolClosed. |
| 1717 | require.ErrorIs(t, mp.ReleaseContext(context.Background()), ants.ErrPoolClosed) |
| 1718 | |
| 1719 | // Test with LeastTasks strategy. |
| 1720 | ch = make(chan struct{}) |
| 1721 | mp, err = ants.NewMultiPoolWithFuncGeneric(10, 5, longRunningPoolFuncCh, ants.LeastTasks) |
| 1722 | require.NoError(t, err) |
| 1723 | for i := 0; i < 50; i++ { |
| 1724 | err = mp.Invoke(ch) |
| 1725 | require.NoError(t, err) |
| 1726 | } |
| 1727 | close(ch) |
| 1728 | err = mp.ReleaseContext(context.Background()) |
| 1729 | require.NoError(t, err) |
| 1730 | require.Zero(t, mp.Running()) |
| 1731 | require.True(t, mp.IsClosed()) |
| 1732 | |
| 1733 | // Test that a cancelled context returns an error. |
| 1734 | ch = make(chan struct{}) |
| 1735 | mp, err = ants.NewMultiPoolWithFuncGeneric(10, 5, longRunningPoolFuncCh, ants.RoundRobin) |
| 1736 | require.NoError(t, err) |
| 1737 | for i := 0; i < 50; i++ { |
| 1738 | err = mp.Invoke(ch) |
| 1739 | require.NoError(t, err) |
| 1740 | } |
| 1741 | ctx, cancel := context.WithCancel(context.Background()) |
| 1742 | cancel() |
| 1743 | err = mp.ReleaseContext(ctx) |
| 1744 | require.Error(t, err) |
| 1745 | close(ch) |
| 1746 | require.Eventually(t, func() bool { |
| 1747 | return mp.Running() == 0 |
| 1748 | }, 3*time.Second, 100*time.Millisecond) |
| 1749 | } |
| 1750 | |
| 1751 | func TestRebootNewPoolCalc(t *testing.T) { |
| 1752 | atomic.StoreInt32(&sum, 0) |
nothing calls this directly
no test coverage detected
searching dependent graphs…