MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestRing_GetReplicationSetForOperation

Function TestRing_GetReplicationSetForOperation

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

Source from the content-addressed store, hash-verified

1064}
1065
1066func TestRing_GetReplicationSetForOperation(t *testing.T) {
1067 now := time.Now()
1068 g := NewRandomTokenGenerator()
1069
1070 tests := map[string]struct {
1071 ringInstances map[string]InstanceDesc
1072 ringHeartbeatTimeout time.Duration
1073 ringReplicationFactor int
1074 expectedErrForRead error
1075 expectedSetForRead []string
1076 expectedErrForWrite error
1077 expectedSetForWrite []string
1078 expectedErrForReporting error
1079 expectedSetForReporting []string
1080 }{
1081 "should return error on empty ring": {
1082 ringInstances: nil,
1083 ringHeartbeatTimeout: time.Minute,
1084 ringReplicationFactor: 1,
1085 expectedErrForRead: ErrEmptyRing,
1086 expectedErrForWrite: ErrEmptyRing,
1087 expectedErrForReporting: ErrEmptyRing,
1088 },
1089 "should succeed on all healthy instances and RF=1": {
1090 ringInstances: map[string]InstanceDesc{
1091 "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-1", "", 128, true)},
1092 "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-2", "", 128, true)},
1093 "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-3", "", 128, true)},
1094 "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-4", "", 128, true)},
1095 "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-40 * time.Second).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-5", "", 128, true)},
1096 },
1097 ringHeartbeatTimeout: time.Minute,
1098 ringReplicationFactor: 1,
1099 expectedSetForRead: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"},
1100 expectedSetForWrite: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"},
1101 expectedSetForReporting: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"},
1102 },
1103 "should succeed on instances with old timestamps but heartbeat timeout disabled": {
1104 ringInstances: map[string]InstanceDesc{
1105 "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-1", "", 128, true)},
1106 "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-2", "", 128, true)},
1107 "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-3", "", 128, true)},
1108 "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-4", "", 128, true)},
1109 "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-5", "", 128, true)},
1110 },
1111 ringHeartbeatTimeout: 0,
1112 ringReplicationFactor: 1,
1113 expectedSetForRead: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"},
1114 expectedSetForWrite: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"},
1115 expectedSetForReporting: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"},
1116 },
1117 "should fail on 1 unhealthy instance and RF=1": {
1118 ringInstances: map[string]InstanceDesc{
1119 "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-1", "", 128, true)},
1120 "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-2", "", 128, true)},
1121 "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-3", "", 128, true)},
1122 "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-4", "", 128, true)},
1123 "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: g.GenerateTokens(NewDesc(), "instance-5", "", 128, true)},

Callers

nothing calls this directly

Calls 13

GenerateTokensMethod · 0.95
GetTokensMethod · 0.95
getTokensByZoneMethod · 0.95
getTokensInfoMethod · 0.95
NewRandomTokenGeneratorFunction · 0.85
NewDescFunction · 0.85
getZonesFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected