This test asserts on shard stability across multiple invocations and given the same input ring.
(t *testing.T)
| 220 | |
| 221 | // This test asserts on shard stability across multiple invocations and given the same input ring. |
| 222 | func 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 | |
| 254 | func TestPartitionRing_ShuffleShard_Shuffling(t *testing.T) { |
| 255 | var ( |
nothing calls this directly
no test coverage detected