forked from mirror/ants
🍩 Unit tests improvement: more functions to cover more code
This commit is contained in:
parent
91377c898b
commit
182c335275
23
ants_test.go
23
ants_test.go
|
@ -53,6 +53,27 @@ const (
|
|||
|
||||
var curMem uint64
|
||||
|
||||
// TestAntsPoolWaitToGetWorker is used to test waiting to get worker.
|
||||
func TestAntsPoolWaitToGetWorker(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
p, _ := ants.NewPool(AntsSize)
|
||||
defer p.Release()
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
wg.Add(1)
|
||||
p.Submit(func() {
|
||||
demoPoolFunc(Param)
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
t.Logf("pool, running workers number:%d", p.Running())
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
curMem = mem.TotalAlloc/MiB - curMem
|
||||
t.Logf("memory usage:%d MB", curMem)
|
||||
}
|
||||
|
||||
// TestAntsPoolWithFuncWaitToGetWorker is used to test waiting to get worker.
|
||||
func TestAntsPoolWithFuncWaitToGetWorker(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
|
@ -102,7 +123,7 @@ func TestAntsPoolWithFuncGetWorkerFromCache(t *testing.T) {
|
|||
}
|
||||
time.Sleep(2 * ants.DefaultCleanIntervalTime * time.Second)
|
||||
p.Serve(dur)
|
||||
t.Logf("pool, running workers number:%d", p.Running())
|
||||
t.Logf("pool with func, running workers number:%d", p.Running())
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
curMem = mem.TotalAlloc/MiB - curMem
|
||||
|
|
Loading…
Reference in New Issue