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

Function TestRing_Zones

ring/ring_test.go:4586–4640  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

4584}
4585
4586func TestRing_Zones(t *testing.T) {
4587 tests := map[string]struct {
4588 ringInstances map[string]InstanceDesc
4589 expectedZones []string
4590 }{
4591 "empty ring": {
4592 ringInstances: nil,
4593 expectedZones: nil,
4594 },
4595 "single zone": {
4596 ringInstances: map[string]InstanceDesc{
4597 "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE},
4598 "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: LEAVING},
4599 },
4600 expectedZones: []string{"zone-a"},
4601 },
4602 "multiple zones in alphabetical order": {
4603 ringInstances: map[string]InstanceDesc{
4604 "instance-1": {Addr: "127.0.0.1", Zone: "zone-c", State: ACTIVE},
4605 "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE},
4606 "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: ACTIVE},
4607 },
4608 expectedZones: []string{"zone-a", "zone-b", "zone-c"},
4609 },
4610 "zones with different instance states": {
4611 ringInstances: map[string]InstanceDesc{
4612 "instance-1": {Addr: "127.0.0.1", Zone: "zone-b", State: ACTIVE},
4613 "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: LEAVING},
4614 "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", State: PENDING},
4615 "instance-4": {Addr: "127.0.0.4", Zone: "zone-d", State: JOINING},
4616 },
4617 expectedZones: []string{"zone-a", "zone-b", "zone-c", "zone-d"},
4618 },
4619 }
4620
4621 for testName, testData := range tests {
4622 t.Run(testName, func(t *testing.T) {
4623 // Init the ring.
4624 ringDesc := &Desc{Ingesters: testData.ringInstances}
4625 for id, instance := range ringDesc.Ingesters {
4626 instance.Timestamp = time.Now().Unix()
4627 ringDesc.Ingesters[id] = instance
4628 }
4629
4630 ring := newRingForTesting(Config{
4631 HeartbeatTimeout: time.Hour,
4632 ZoneAwarenessEnabled: true,
4633 }, false)
4634 ring.setRingStateFromDesc(ringDesc, false, false, false)
4635
4636 assert.Equal(t, testData.expectedZones, ring.Zones())
4637 assert.Equal(t, len(testData.expectedZones), ring.ZonesCount())
4638 })
4639 }
4640}

Callers

nothing calls this directly

Calls 6

newRingForTestingFunction · 0.85
RunMethod · 0.80
setRingStateFromDescMethod · 0.80
ZonesMethod · 0.65
ZonesCountMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected