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

Function TestRing_ShuffleShard_Stability

pkg/ring/ring_test.go:1745–1787  ·  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

1743
1744// This test asserts on shard stability across multiple invocations and given the same input ring.
1745func TestRing_ShuffleShard_Stability(t *testing.T) {
1746 var (
1747 numTenants = 100
1748 numInstances = 50
1749 numZones = 3
1750 numInvocations = 10
1751 shardSizes = []int{3, 6, 9, 12, 15}
1752 )
1753
1754 // Initialise the ring.
1755 ringDesc := &Desc{Ingesters: generateRingInstances(numInstances, numZones, 128)}
1756 ring := Ring{
1757 cfg: Config{
1758 HeartbeatTimeout: time.Hour,
1759 ZoneAwarenessEnabled: true,
1760 },
1761 ringDesc: ringDesc,
1762 ringTokens: ringDesc.GetTokens(),
1763 ringTokensByZone: ringDesc.getTokensByZone(),
1764 ringInstanceByToken: ringDesc.getTokensInfo(),
1765 ringZones: getZones(ringDesc.getTokensByZone()),
1766 strategy: NewDefaultReplicationStrategy(),
1767 KVClient: &MockClient{},
1768 }
1769
1770 for i := 1; i <= numTenants; i++ {
1771 tenantID := fmt.Sprintf("%d", i)
1772
1773 for _, size := range shardSizes {
1774 r := ring.ShuffleShard(tenantID, size)
1775 expected, err := r.GetAllHealthy(Read)
1776 require.NoError(t, err)
1777
1778 // Assert that multiple invocations generate the same exact shard.
1779 for range numInvocations {
1780 r := ring.ShuffleShard(tenantID, size)
1781 actual, err := r.GetAllHealthy(Read)
1782 require.NoError(t, err)
1783 assert.ElementsMatch(t, expected.Instances, actual.Instances)
1784 }
1785 }
1786 }
1787}
1788
1789func TestRing_ShuffleShard_Shuffling(t *testing.T) {
1790 var (

Callers

nothing calls this directly

Calls 8

GetTokensMethod · 0.95
getTokensByZoneMethod · 0.95
getTokensInfoMethod · 0.95
ShuffleShardMethod · 0.95
generateRingInstancesFunction · 0.85
getZonesFunction · 0.85
GetAllHealthyMethod · 0.65

Tested by

no test coverage detected