| 913 | } |
| 914 | |
| 915 | func TestInfinitePoolWithFunc(t *testing.T) { |
| 916 | c := make(chan struct{}) |
| 917 | p, err := ants.NewPoolWithFunc(-1, func(i any) { |
| 918 | demoPoolFunc(i) |
| 919 | <-c |
| 920 | }) |
| 921 | require.NoErrorf(t, err, "create pool with func failed: %v", err) |
| 922 | defer p.Release() |
| 923 | _ = p.Invoke(10) |
| 924 | _ = p.Invoke(10) |
| 925 | c <- struct{}{} |
| 926 | c <- struct{}{} |
| 927 | if n := p.Running(); n != 2 { |
| 928 | t.Errorf("expect 2 workers running, but got %d", n) |
| 929 | } |
| 930 | if n := p.Free(); n != -1 { |
| 931 | t.Errorf("expect -1 of free workers by unlimited pool, but got %d", n) |
| 932 | } |
| 933 | p.Tune(10) |
| 934 | if capacity := p.Cap(); capacity != -1 { |
| 935 | t.Fatalf("expect capacity: -1 but got %d", capacity) |
| 936 | } |
| 937 | _, err = ants.NewPoolWithFunc(-1, demoPoolFunc, ants.WithPreAlloc(true)) |
| 938 | require.ErrorIsf(t, err, ants.ErrInvalidPreAllocSize, "expect ErrInvalidPreAllocSize but got %v", err) |
| 939 | } |
| 940 | |
| 941 | func TestInfinitePoolWithFuncGeneric(t *testing.T) { |
| 942 | c := make(chan struct{}) |