This test asserts on shard stability across multiple invocations and given the same input ring.
(t *testing.T)
| 1996 | |
| 1997 | // This test asserts on shard stability across multiple invocations and given the same input ring. |
| 1998 | func TestRing_ShuffleShard_Stability(t *testing.T) { |
| 1999 | var ( |
| 2000 | numTenants = 100 |
| 2001 | numInstances = 50 |
| 2002 | numZones = 3 |
| 2003 | numInvocations = 10 |
| 2004 | shardSizes = []int{3, 6, 9, 12, 15} |
| 2005 | ) |
| 2006 | |
| 2007 | // Initialise the ring. |
| 2008 | ringDesc := &Desc{Ingesters: generateRingInstances(initTokenGenerator(t), numInstances, numZones, 128)} |
| 2009 | ring := newRingForTesting(Config{ |
| 2010 | HeartbeatTimeout: time.Hour, |
| 2011 | ZoneAwarenessEnabled: true, |
| 2012 | }, false) |
| 2013 | ring.setRingStateFromDesc(ringDesc, false, false, false) |
| 2014 | |
| 2015 | for i := 1; i <= numTenants; i++ { |
| 2016 | tenantID := fmt.Sprintf("%d", i) |
| 2017 | |
| 2018 | for _, size := range shardSizes { |
| 2019 | r := ring.ShuffleShard(tenantID, size) |
| 2020 | expected, err := r.GetAllHealthy(Read) |
| 2021 | require.NoError(t, err) |
| 2022 | |
| 2023 | // Assert that multiple invocations generate the same exact shard. |
| 2024 | for n := 0; n < numInvocations; n++ { |
| 2025 | r := ring.ShuffleShard(tenantID, size) |
| 2026 | actual, err := r.GetAllHealthy(Read) |
| 2027 | require.NoError(t, err) |
| 2028 | assert.ElementsMatch(t, expected.Instances, actual.Instances) |
| 2029 | } |
| 2030 | } |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | func initTokenGenerator(t testing.TB) TokenGenerator { |
| 2035 | seed := time.Now().UnixNano() |
nothing calls this directly
no test coverage detected