MCPcopy
hub / github.com/panjf2000/ants / TestInfinitePoolWithFunc

Function TestInfinitePoolWithFunc

ants_test.go:915–939  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

913}
914
915func 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
941func TestInfinitePoolWithFuncGeneric(t *testing.T) {
942 c := make(chan struct{})

Callers

nothing calls this directly

Calls 7

InvokeMethod · 0.95
demoPoolFuncFunction · 0.85
ReleaseMethod · 0.80
RunningMethod · 0.45
FreeMethod · 0.45
TuneMethod · 0.45
CapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…