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

Function TestNonblockingSubmitWithFunc

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

Source from the content-addressed store, hash-verified

586}
587
588func TestNonblockingSubmitWithFunc(t *testing.T) {
589 poolSize := 10
590 ch := make(chan struct{})
591 var wg sync.WaitGroup
592 p, err := ants.NewPoolWithFunc(poolSize, func(i any) {
593 longRunningPoolFunc(i)
594 wg.Done()
595 }, ants.WithNonblocking(true))
596 require.NoError(t, err, "create TimingPool failed: %v", err)
597 defer p.Release()
598 wg.Add(poolSize)
599 for i := 0; i < poolSize-1; i++ {
600 require.NoError(t, p.Invoke(ch), "nonblocking submit when pool is not full shouldn't return error")
601 }
602 // p is full now.
603 require.NoError(t, p.Invoke(ch), "nonblocking submit when pool is not full shouldn't return error")
604 require.ErrorIsf(t, p.Invoke(nil), ants.ErrPoolOverload,
605 "nonblocking submit when pool is full should get an ants.ErrPoolOverload")
606 // interrupt f to get an available worker
607 close(ch)
608 wg.Wait()
609 wg.Add(1)
610 require.NoError(t, p.Invoke(ch), "nonblocking submit when pool is not full shouldn't return error")
611 wg.Wait()
612}
613
614func TestNonblockingSubmitWithFuncGeneric(t *testing.T) {
615 poolSize := 10

Callers

nothing calls this directly

Calls 3

InvokeMethod · 0.95
longRunningPoolFuncFunction · 0.85
ReleaseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…