From 603f64f292cc8ac240cf5458a2622dbd95cd16b7 Mon Sep 17 00:00:00 2001 From: arraykeys Date: Fri, 5 Jan 2024 11:31:09 +0800 Subject: [PATCH] gpool --- util/gpool/gpool.go | 4 ++-- util/gpool/gpool_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/util/gpool/gpool.go b/util/gpool/gpool.go index 75865055..54d62e6f 100644 --- a/util/gpool/gpool.go +++ b/util/gpool/gpool.go @@ -305,8 +305,8 @@ func (s *Pool) Stop() { s.workers.Clear() } -// RunningWorkCount returns the count of running workers -func (s *Pool) RunningWorkCount() (workerCount int) { +// RunningWorkerCount returns the count of running workers +func (s *Pool) RunningWorkerCount() (workerCount int) { return int(atomic.LoadInt64(s.runningWorkerCounter)) } diff --git a/util/gpool/gpool_test.go b/util/gpool/gpool_test.go index 7cb78abb..7179a234 100644 --- a/util/gpool/gpool_test.go +++ b/util/gpool/gpool_test.go @@ -223,7 +223,7 @@ func TestRunning(t *testing.T) { time.Sleep(time.Second) }) time.Sleep(time.Millisecond * 40) - if p.RunningWorkCount() == 3 { + if p.RunningWorkerCount() == 3 { t.Log("Running is okay") } else { t.Fatalf("Running is failed") @@ -247,7 +247,7 @@ func TestIncrease(t *testing.T) { }) } time.Sleep(time.Second) - assert.Equal(6, p.RunningWorkCount()) + assert.Equal(6, p.RunningWorkerCount()) p.Stop() } @@ -261,10 +261,10 @@ func TestDecrease(t *testing.T) { }) } time.Sleep(time.Millisecond * 30) - assert.Equal(2, p.RunningWorkCount()) + assert.Equal(2, p.RunningWorkerCount()) p.Decrease(1) time.Sleep(time.Second) - assert.Equal(1, p.RunningWorkCount()) + assert.Equal(1, p.RunningWorkerCount()) p.Stop() } @@ -333,7 +333,7 @@ func TestGPool_MaxWaitCount(t *testing.T) { time.Sleep(time.Millisecond * 40) assert.Equal(0, p.IdleWorkerCount()) - assert.Equal(1, p.RunningWorkCount()) + assert.Equal(1, p.RunningWorkerCount()) p.Stop() }