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

Function TestPartitionRing_ShuffleShard_Stability

ring/partition_ring_test.go:222–252  ·  view source on GitHub ↗

This test asserts on shard stability across multiple invocations and given the same input ring.

(t *testing.T)

Source from the content-addressed store, hash-verified

220
221// This test asserts on shard stability across multiple invocations and given the same input ring.
222func TestPartitionRing_ShuffleShard_Stability(t *testing.T) {
223 var (
224 numTenants = 100
225 numActivePartitions = 50
226 numInactivePartitions = 10
227 numPendingPartitions = 5
228 numInvocations = 10
229 shardSizes = []int{3, 6, 9, 12, 15}
230 )
231
232 // Initialise the ring.
233 ring := createPartitionRingWithPartitions(DefaultPartitionRingOptions(), numActivePartitions, numInactivePartitions, numPendingPartitions)
234
235 for i := 1; i <= numTenants; i++ {
236 tenantID := fmt.Sprintf("%d", i)
237
238 for _, size := range shardSizes {
239 expectedSubring, err := ring.ShuffleShard(tenantID, size)
240 require.NoError(t, err)
241
242 assert.Equal(t, expectedSubring.PartitionsCount(), ring.ShuffleShardSize(size))
243
244 // Assert that multiple invocations generate the same exact shard.
245 for n := 0; n < numInvocations; n++ {
246 actualSubring, err := ring.ShuffleShard(tenantID, size)
247 require.NoError(t, err)
248 assert.Equal(t, expectedSubring.desc, actualSubring.desc)
249 }
250 }
251 }
252}
253
254func TestPartitionRing_ShuffleShard_Shuffling(t *testing.T) {
255 var (

Callers

nothing calls this directly

Calls 6

PartitionsCountMethod · 0.80
ShuffleShardSizeMethod · 0.80
ShuffleShardMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected