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

Function TestRing_ShuffleShard_Consistency

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

Source from the content-addressed store, hash-verified

2129}
2130
2131func TestRing_ShuffleShard_Consistency(t *testing.T) {
2132 type change string
2133
2134 type scenario struct {
2135 name string
2136 numInstances int
2137 numZones int
2138 shardSize int
2139 ringChange change
2140 }
2141
2142 const (
2143 numTenants = 100
2144 add = change("add-instance")
2145 remove = change("remove-instance")
2146 enableReadOnly = change("enable-read-only")
2147 disableReadOnly = change("disable-read-only")
2148 )
2149
2150 rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
2151
2152 // Generate all test scenarios.
2153 var scenarios []scenario
2154 for _, numInstances := range []int{20, 30, 40, 50} {
2155 for _, shardSize := range []int{3, 6, 9, 12, 15} {
2156 for _, c := range []change{add, remove, enableReadOnly, disableReadOnly} {
2157 scenarios = append(scenarios, scenario{
2158 name: fmt.Sprintf("instances = %d, shard size = %d, ring operation = %s", numInstances, shardSize, c),
2159 numInstances: numInstances,
2160 numZones: 3,
2161 shardSize: shardSize,
2162 ringChange: c,
2163 })
2164 }
2165 }
2166 }
2167
2168 for _, s := range scenarios {
2169 t.Run(s.name, func(t *testing.T) {
2170 gen := initTokenGenerator(t)
2171 // Initialise the ring.
2172 ringDesc := &Desc{Ingesters: generateRingInstances(gen, s.numInstances, s.numZones, 128)}
2173
2174 // Mark some instances as read only
2175 for i := 0; i < len(ringDesc.Ingesters); i += 8 {
2176 instanceID := getRandomInstanceID(ringDesc.Ingesters, rnd)
2177 inst := ringDesc.Ingesters[instanceID]
2178 inst.ReadOnly = true
2179 inst.ReadOnlyUpdatedTimestamp = time.Now().Unix()
2180 ringDesc.Ingesters[instanceID] = inst
2181 }
2182
2183 ring := newRingForTesting(Config{
2184 HeartbeatTimeout: time.Hour,
2185 ZoneAwarenessEnabled: true,
2186 }, false)
2187 ring.setRingStateFromDesc(ringDesc, false, false, false)
2188

Callers

nothing calls this directly

Calls 11

initTokenGeneratorFunction · 0.85
generateRingInstancesFunction · 0.85
getRandomInstanceIDFunction · 0.85
newRingForTestingFunction · 0.85
generateRingInstanceFunction · 0.85
compareReplicationSetsFunction · 0.85
RunMethod · 0.80
setRingStateFromDescMethod · 0.80
changeTypeAlias · 0.70
GetAllHealthyMethod · 0.65
ShuffleShardMethod · 0.65

Tested by

no test coverage detected