From 182c335275ec5443157ff43b9143580f5b5a7439 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 27 Jan 2019 05:30:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=A9=20Unit=20tests=20improvement:=20mo?= =?UTF-8?q?re=20functions=20to=20cover=20more=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ants_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ants_test.go b/ants_test.go index 36b546f..6d7729a 100644 --- a/ants_test.go +++ b/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