Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
review
Browse files Browse the repository at this point in the history
ldez committed Nov 14, 2024
1 parent 904997d commit d5c9e8b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions memmetrics/counter_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d5c9e8b

Please sign in to comment.