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

Function TestRing_GetInstanceDescsForOperation

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

Source from the content-addressed store, hash-verified

999}
1000
1001func TestRing_GetInstanceDescsForOperation(t *testing.T) {
1002 now := time.Now().Unix()
1003 twoMinutesAgo := time.Now().Add(-2 * time.Minute).Unix()
1004
1005 ringDesc := &Desc{Ingesters: map[string]InstanceDesc{
1006 "instance-1": {Addr: "127.0.0.1", Tokens: []uint32{1}, State: ACTIVE, Timestamp: now},
1007 "instance-2": {Addr: "127.0.0.2", Tokens: []uint32{2}, State: LEAVING, Timestamp: now}, // not healthy state
1008 "instance-3": {Addr: "127.0.0.3", Tokens: []uint32{3}, State: ACTIVE, Timestamp: twoMinutesAgo}, // heartbeat timed out
1009 }}
1010
1011 ring := Ring{
1012 cfg: Config{HeartbeatTimeout: time.Minute},
1013 ringDesc: ringDesc,
1014 ringTokens: ringDesc.GetTokens(),
1015 ringTokensByZone: ringDesc.getTokensByZone(),
1016 ringInstanceByToken: ringDesc.getTokensInfo(),
1017 ringZones: getZones(ringDesc.getTokensByZone()),
1018 strategy: NewDefaultReplicationStrategy(),
1019 KVClient: &MockClient{},
1020 }
1021
1022 testOp := NewOp([]InstanceState{ACTIVE}, nil)
1023
1024 instanceDescs, err := ring.GetInstanceDescsForOperation(testOp)
1025 require.NoError(t, err)
1026 require.EqualValues(t, map[string]InstanceDesc{
1027 "instance-1": {Addr: "127.0.0.1", Tokens: []uint32{1}, State: ACTIVE, Timestamp: now},
1028 }, instanceDescs)
1029}
1030
1031func TestRing_GetAllInstanceDescs(t *testing.T) {
1032 now := time.Now().Unix()

Callers

nothing calls this directly

Calls 8

GetTokensMethod · 0.95
getTokensByZoneMethod · 0.95
getTokensInfoMethod · 0.95
getZonesFunction · 0.85
NewOpFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected