MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestGenerateTokens

Function TestGenerateTokens

pkg/ring/token_generator_test.go:14–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestGenerateTokens(t *testing.T) {
15 testCase := map[string]struct {
16 tg TokenGenerator
17 }{
18 "random": {
19 tg: NewRandomTokenGenerator(),
20 },
21 "minimizeSpread": {
22 tg: NewMinimizeSpreadTokenGenerator(),
23 },
24 }
25
26 for name, tc := range testCase {
27 t.Run(name, func(t *testing.T) {
28 tokens := tc.tg.GenerateTokens(NewDesc(), "", "", 1000000, true)
29
30 dups := make(map[uint32]int)
31
32 for ix, v := range tokens {
33 if ox, ok := dups[v]; ok {
34 t.Errorf("Found duplicate token %d, tokens[%d]=%d, tokens[%d]=%d", v, ix, tokens[ix], ox, tokens[ox])
35 } else {
36 dups[v] = ix
37 }
38 }
39 })
40 }
41}
42
43func TestGenerateTokens_IgnoresOldTokens(t *testing.T) {
44 testCase := map[string]struct {

Callers

nothing calls this directly

Calls 5

NewRandomTokenGeneratorFunction · 0.85
NewDescFunction · 0.85
RunMethod · 0.65
GenerateTokensMethod · 0.65

Tested by

no test coverage detected