This test asserts that for some randomly generated history of shuffleShard (without lookback) results, every subsequent ShuffleShardWithLookback will be a superset of all previously recorded shuffleShards.
(t *testing.T)
| 2807 | // This test asserts that for some randomly generated history of shuffleShard (without lookback) results, |
| 2808 | // every subsequent ShuffleShardWithLookback will be a superset of all previously recorded shuffleShards. |
| 2809 | func TestRing_ShuffleShardWithLookback_CorrectnessWithFuzzy(t *testing.T) { |
| 2810 | // The goal of this test is NOT to ensure that the minimum required number of instances |
| 2811 | // are returned at any given time, BUT at least all required instances are returned. |
| 2812 | var ( |
| 2813 | numInitialInstances = []int{9, 30, 60, 90} |
| 2814 | numInitialZones = []int{1, 3} |
| 2815 | numEvents = 100 |
| 2816 | lookbackPeriod = time.Hour |
| 2817 | delayBetweenEvents = 5 * time.Minute // 12 events / hour |
| 2818 | userID = "user-1" |
| 2819 | ) |
| 2820 | |
| 2821 | for _, updateOldestRegisteredTimestamp := range []bool{false, true} { |
| 2822 | updateOldestRegisteredTimestamp := updateOldestRegisteredTimestamp |
| 2823 | |
| 2824 | for _, updateReadOnlyInstances := range []bool{false, true} { |
| 2825 | updateReadOnlyInstances := updateReadOnlyInstances |
| 2826 | |
| 2827 | for _, numInstances := range numInitialInstances { |
| 2828 | numInstances := numInstances |
| 2829 | |
| 2830 | for _, numZones := range numInitialZones { |
| 2831 | numZones := numZones |
| 2832 | |
| 2833 | testName := fmt.Sprintf("num instances = %d, num zones = %d, update oldest registered timestamp = %v, update read only instances = %v", numInstances, numZones, updateOldestRegisteredTimestamp, updateReadOnlyInstances) |
| 2834 | |
| 2835 | t.Run(testName, func(t *testing.T) { |
| 2836 | t.Parallel() |
| 2837 | |
| 2838 | // Randomise the seed but log it in case we need to reproduce the test on failure. |
| 2839 | seed := time.Now().UnixNano() |
| 2840 | rnd := rand.New(rand.NewSource(seed)) |
| 2841 | t.Log("random generator seed:", seed) |
| 2842 | gen := NewRandomTokenGeneratorWithSeed(seed) |
| 2843 | |
| 2844 | // Initialise the ring. |
| 2845 | ringDesc := &Desc{Ingesters: generateRingInstances(gen, numInstances, numZones, 128)} |
| 2846 | ring := newRingForTesting(Config{ |
| 2847 | HeartbeatTimeout: time.Hour, |
| 2848 | ZoneAwarenessEnabled: true, |
| 2849 | ReplicationFactor: 3, |
| 2850 | }, false) |
| 2851 | |
| 2852 | updateRing := func() { |
| 2853 | ring.setRingStateFromDesc(ringDesc, false, updateOldestRegisteredTimestamp, updateReadOnlyInstances) |
| 2854 | |
| 2855 | if len(ring.ringZones) != numZones { |
| 2856 | t.Fatalf("number of zones changed, original=%d, current zones=%v", numZones, ring.ringZones) |
| 2857 | } |
| 2858 | } |
| 2859 | updateRing() |
| 2860 | |
| 2861 | // The simulation starts with the minimum shard size. Random events can later increase it. |
| 2862 | shardSize := numZones |
| 2863 | |
| 2864 | // The simulation assumes the initial ring contains instances registered |
| 2865 | // since more than the lookback period. |
| 2866 | currTime := time.Now().Add(lookbackPeriod).Add(time.Minute) |
nothing calls this directly
no test coverage detected