From eb0cbf58a8ce49370f238aa42672154583d2ee8a Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Jul 2020 12:02:55 +0200 Subject: [PATCH] Rename Cnt() to Size() and split up tests From PR Review https://github.com/safing/portbase/pull/57 --- utils/stablepool.go | 4 ++-- utils/stablepool_test.go | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/stablepool.go b/utils/stablepool.go index 68fb605..d253d65 100644 --- a/utils/stablepool.go +++ b/utils/stablepool.go @@ -104,8 +104,8 @@ func (p *StablePool) Get() interface{} { return nil } -// Cnt returns the amount of items the pool currently holds. -func (p *StablePool) Cnt() int { +// Size returns the amount of items the pool currently holds. +func (p *StablePool) Size() int { p.lock.Lock() defer p.lock.Unlock() diff --git a/utils/stablepool_test.go b/utils/stablepool_test.go index c3ffb7e..32d69d1 100644 --- a/utils/stablepool_test.go +++ b/utils/stablepool_test.go @@ -9,8 +9,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestStablePool(t *testing.T) { - +func TestStablePoolRealWorld(t *testing.T) { // "real world" simulation cnt := 0 @@ -55,7 +54,7 @@ func TestStablePool(t *testing.T) { // wait for round to finish testWorkerWg.Wait() } - t.Logf("real world simulation: cnt=%d p.cnt=%d p.max=%d\n", cnt, testPool.Cnt(), testPool.Max()) + t.Logf("real world simulation: cnt=%d p.cnt=%d p.max=%d\n", cnt, testPool.Size(), testPool.Max()) assert.GreaterOrEqual(t, 200, cnt, "should not use more than 200 values") assert.GreaterOrEqual(t, 100, testPool.Max(), "pool should have at most this max size") @@ -71,7 +70,9 @@ func TestStablePool(t *testing.T) { } } assert.Equal(t, 100, optPool.Max(), "pool should have exactly this max size") +} +func TestStablePoolFuzzing(t *testing.T) { // fuzzing test fuzzPool := &StablePool{} @@ -97,7 +98,9 @@ func TestStablePool(t *testing.T) { fuzzWg.Done() // wait for all to finish fuzzWorkerWg.Wait() +} +func TestStablePoolBreaking(t *testing.T) { // try to break it breakPool := &StablePool{}