diff --git a/memmetrics/counter_test.go b/memmetrics/counter_test.go index 5218358..b694fb1 100644 --- a/memmetrics/counter_test.go +++ b/memmetrics/counter_test.go @@ -1,6 +1,7 @@ package memmetrics import ( + "math" "testing" "github.com/stretchr/testify/assert" @@ -28,21 +29,24 @@ func TestCloneExpired(t *testing.T) { assert.EqualValues(t, 2, out.Count()) } -func TestCleanup(t *testing.T) { +func Test_cleanup(t *testing.T) { clock.Freeze(clock.Date(2012, 3, 4, 5, 6, 7, 0, clock.UTC)) cnt, err := NewCounter(10, clock.Second) require.NoError(t, err) cnt.Inc(1) + for i := 0; i < 9; i++ { clock.Advance(clock.Second) - cnt.Inc(1) + cnt.Inc(int(math.Pow10(i + 1))) } - // cnt will be [1 1 1 1 1 1 1 1 1 1] + + assert.EqualValues(t, 1111111111, cnt.Count()) + assert.Equal(t, []int{1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 1, 10, 100}, cnt.values) clock.Advance(9 * clock.Second) - assert.EqualValues(t, 1, cnt.Count()) - // cnt will be [0 0 0 0 0 0 1 0 0 0] - // old behavior [1 1 0 1 0 0 1 1 1 0] + + assert.EqualValues(t, 1000000000, cnt.Count()) + assert.EqualValues(t, []int{0, 0, 0, 0, 0, 0, 1000000000, 0, 0, 0}, cnt.values) }