MCPcopy
hub / github.com/grafana/dskit / TestRing_Get_ZoneAwarenessWithIngesterLeaving

Function TestRing_Get_ZoneAwarenessWithIngesterLeaving

ring/ring_test.go:549–619  ·  ring/ring_test.go::TestRing_Get_ZoneAwarenessWithIngesterLeaving
(t *testing.T)

Source from the content-addressed store, hash-verified

547}
548
549func TestRing_Get_ZoneAwarenessWithIngesterLeaving(t *testing.T) {
550 const testCount = 10000
551
552 tests := map[string]struct {
553 replicationFactor int
554 expectedInstances int
555 expectedZones int
556 }{
557 "should succeed if there are enough instances per zone on RF = 3": {
558 replicationFactor: 3,
559 expectedInstances: 3,
560 expectedZones: 3,
561 },
562 "should succeed if there are enough instances per zone on RF = 2": {
563 replicationFactor: 2,
564 expectedInstances: 2,
565 expectedZones: 2,
566 },
567 }
568
569 for testName, testData := range tests {
570 t.Run(testName, func(t *testing.T) {
571 gen := initTokenGenerator(t)
572
573 r := NewDesc()
574 instances := map[string]InstanceDesc{
575 "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE},
576 "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE},
577 "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: ACTIVE},
578 "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: ACTIVE},
579 "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: LEAVING},
580 "instance-6": {Addr: "127.0.0.6", Zone: "zone-c", State: ACTIVE},
581 }
582 var prevTokens []uint32
583 for id, instance := range instances {
584 ingTokens := gen.GenerateTokens(128, prevTokens)
585 r.AddIngester(id, instance.Addr, instance.Zone, ingTokens, instance.State, time.Now(), false, time.Time{}, nil)
586 prevTokens = append(prevTokens, ingTokens...)
587 }
588 instancesList := make([]InstanceDesc, 0, len(r.GetIngesters()))
589 for _, v := range r.GetIngesters() {
590 instancesList = append(instancesList, v)
591 }
592
593 ring := newRingForTesting(Config{
594 HeartbeatTimeout: time.Hour,
595 ReplicationFactor: testData.replicationFactor,
596 ZoneAwarenessEnabled: true,
597 }, false)
598 ring.setRingStateFromDesc(r, false, false, false)
599
600 _, bufHosts, bufZones := MakeBuffersForGet()
601
602 // Use the GenerateTokens to get an array of random uint32 values.
603 testValues := gen.GenerateTokens(testCount, nil)
604
605 for i := 0; i < testCount; i++ {
606 set, err := ring.Get(testValues[i], Write, instancesList, bufHosts, bufZones)

Callers

nothing calls this directly

Calls 11

AddIngesterMethod · 0.95
GetIngestersMethod · 0.95
initTokenGeneratorFunction · 0.85
NewDescFunction · 0.85
newRingForTestingFunction · 0.85
MakeBuffersForGetFunction · 0.85
RunMethod · 0.80
setRingStateFromDescMethod · 0.80
GenerateTokensMethod · 0.65
GetMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected