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

Function TestRing_Get_Stability

pkg/ring/ring_test.go:508–574  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

506}
507
508func TestRing_Get_Stability(t *testing.T) {
509 const numOfInvocations = 10
510 const numOfTokensToTest = 10
511 g := NewRandomTokenGenerator()
512
513 tests := map[string]struct {
514 numOfZones int
515 replicationFactor int
516 }{
517 "should return same set for same operation when zone awareness is disabled": {
518 numOfZones: 0,
519 replicationFactor: 3,
520 },
521 "should return same set when RF is equal to number of zones": {
522 numOfZones: 3,
523 replicationFactor: 3,
524 },
525 "should return same set when RF is less than number of zones": {
526 numOfZones: 3,
527 replicationFactor: 2,
528 },
529 "should return same set when RF is greater than number of zones": {
530 numOfZones: 3,
531 replicationFactor: 9,
532 },
533 "should return same set when number of instances in each zone is inconsistent": {
534 numOfZones: 3,
535 replicationFactor: 8,
536 },
537 }
538
539 for testName, testData := range tests {
540 t.Run(testName, func(t *testing.T) {
541 testValues := g.GenerateTokens(NewDesc(), "", "", numOfInvocations, true)
542 bufDescs, bufHosts, bufZones := MakeBuffersForGet()
543
544 ringDesc := &Desc{Ingesters: generateRingInstances(16, testData.numOfZones, 128)}
545 ring := Ring{
546 cfg: Config{
547 HeartbeatTimeout: time.Hour,
548 ZoneAwarenessEnabled: testData.numOfZones > 0,
549 ReplicationFactor: testData.replicationFactor,
550 },
551 ringDesc: ringDesc,
552 ringTokens: ringDesc.GetTokens(),
553 ringTokensByZone: ringDesc.getTokensByZone(),
554 ringInstanceByToken: ringDesc.getTokensInfo(),
555 ringZones: getZones(ringDesc.getTokensByZone()),
556 strategy: NewDefaultReplicationStrategy(),
557 KVClient: &MockClient{},
558 }
559
560 for i := range numOfTokensToTest {
561 expectedSet, err := ring.Get(testValues[i], Write, bufDescs, bufHosts, bufZones)
562 assert.NoError(t, err)
563 assert.Equal(t, testData.replicationFactor, len(expectedSet.Instances))
564
565 for range numOfInvocations {

Callers

nothing calls this directly

Calls 13

GenerateTokensMethod · 0.95
GetTokensMethod · 0.95
getTokensByZoneMethod · 0.95
getTokensInfoMethod · 0.95
GetMethod · 0.95
NewRandomTokenGeneratorFunction · 0.85
NewDescFunction · 0.85
MakeBuffersForGetFunction · 0.85
generateRingInstancesFunction · 0.85
getZonesFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected