Skip to content

Commit

Permalink
UsageTracker: tenantshard: TestMapValues (#10177)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Zaytsev <[email protected]>
  • Loading branch information
colega authored Dec 9, 2024
1 parent e4621a0 commit 2616fad
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/usagetracker/tenantshard/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package tenantshard

import (
"math/rand"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -94,5 +95,26 @@ func TestMap(t *testing.T) {
// It's unsafe to check m.count() after Cleanup event.
require.Equal(t, expectedSeries, int(series.Load()))
}
}

func TestMapValues(t *testing.T) {
const count = 10e3
stored := map[uint64]clock.Minutes{}
m := New(100, 0)
total := atomic.NewUint64(0)
for i := 0; i < count; i++ {
key := rand.Uint64() &^ valueMask // we can only store values of this shard.
val := clock.Minutes(i) % valueMask
stored[key] = val
m.put(key, val, total, 0, false)
}
require.Equal(t, len(stored), m.count())
require.Equal(t, len(stored), int(total.Load()))

got := map[uint64]clock.Minutes{}
m.cloner()(
func(c int) { require.Equal(t, len(stored), c) },
func(key uint64, value clock.Minutes) { got[key] = value },
)
require.Equal(t, stored, got)
}

0 comments on commit 2616fad

Please sign in to comment.