100% code coverage test

This commit is contained in:
Andy Pan 2018-07-21 19:36:42 +08:00
commit d844682bd4
2 changed files with 5 additions and 3 deletions

View File

@ -45,6 +45,7 @@ const (
RunTimes = 10000000 RunTimes = 10000000
Param = 100 Param = 100
AntsSize = 500 AntsSize = 500
TestSize = 10000
) )
func demoFunc() error { func demoFunc() error {

View File

@ -28,6 +28,7 @@ import (
"testing" "testing"
"github.com/panjf2000/ants" "github.com/panjf2000/ants"
"time"
) )
var n = 100000 var n = 100000
@ -46,7 +47,6 @@ func TestAntsPoolWithFunc(t *testing.T) {
p.Serve(Param) p.Serve(Param)
} }
wg.Wait() wg.Wait()
t.Logf("pool with func, running workers number:%d", p.Running()) t.Logf("pool with func, running workers number:%d", p.Running())
mem := runtime.MemStats{} mem := runtime.MemStats{}
runtime.ReadMemStats(&mem) runtime.ReadMemStats(&mem)
@ -114,17 +114,18 @@ func TestCodeCov(t *testing.T) {
p0.ReSize(AntsSize / 2) p0.ReSize(AntsSize / 2)
t.Logf("pool, after resize, capacity:%d, running:%d", p0.Cap(), p0.Running()) t.Logf("pool, after resize, capacity:%d, running:%d", p0.Cap(), p0.Running())
p, _ := ants.NewPoolWithFunc(AntsSize, demoPoolFunc) p, _ := ants.NewPoolWithFunc(TestSize, demoPoolFunc)
defer p.Serve(Param) defer p.Serve(Param)
defer p.Release() defer p.Release()
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
p.Serve(Param) p.Serve(Param)
} }
time.Sleep(ants.DefaultCleanIntervalTime * time.Second)
t.Logf("pool with func, capacity:%d", p.Cap()) t.Logf("pool with func, capacity:%d", p.Cap())
t.Logf("pool with func, running workers number:%d", p.Running()) t.Logf("pool with func, running workers number:%d", p.Running())
t.Logf("pool with func, free workers number:%d", p.Free()) t.Logf("pool with func, free workers number:%d", p.Free())
p.ReSize(TestSize)
p.ReSize(AntsSize) p.ReSize(AntsSize)
p.ReSize(AntsSize / 2)
t.Logf("pool with func, after resize, capacity:%d, running:%d", p.Cap(), p.Running()) t.Logf("pool with func, after resize, capacity:%d, running:%d", p.Cap(), p.Running())
} }