From 1bd55973c30b21e2446c181a8caf680ad5b66a66 Mon Sep 17 00:00:00 2001 From: Bartlomiej Plotka Date: Thu, 23 Apr 2020 14:14:44 +0100 Subject: [PATCH] Fixed flakty pool test. Signed-off-by: Bartlomiej Plotka --- pkg/pool/pool_test.go | 52 ++++++++++--------------------------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/pkg/pool/pool_test.go b/pkg/pool/pool_test.go index 2dad08353..caa0bdac5 100644 --- a/pkg/pool/pool_test.go +++ b/pkg/pool/pool_test.go @@ -20,59 +20,31 @@ import ( ) func makeFunc(size int) interface{} { - return size + return make([]int, 0, size) } -func TestGet(t *testing.T) { +func TestPool(t *testing.T) { testPool := New(1, 8, 2, makeFunc) cases := []struct { - size int - expected int + size int + expectedCap int }{ { - size: -1, - expected: 1, + size: -1, + expectedCap: 1, }, { - size: 3, - expected: 4, + size: 3, + expectedCap: 4, }, { - size: 10, - expected: 10, + size: 10, + expectedCap: 10, }, } for _, c := range cases { ret := testPool.Get(c.size) - testutil.Equals(t, c.expected, ret) - } -} - -func TestPut(t *testing.T) { - testPool := New(1, 8, 2, makeFunc) - cases := []struct { - slice []int - size int - expected interface{} - }{ - { - slice: make([]int, 1), - size: 1, - expected: []int{}, - }, - { - slice: make([]int, 8), - size: 8, - expected: []int{}, - }, - { - slice: nil, - size: 2, - expected: 2, - }, - } - for _, c := range cases { - testPool.Put(c.slice) - testutil.Equals(t, c.expected, testPool.Get(c.size)) + testutil.Equals(t, c.expectedCap, cap(ret.([]int))) + testPool.Put(ret) } }