(t *testing.T)
| 839 | } |
| 840 | |
| 841 | func TestCheckReplicaCleanup(t *testing.T) { |
| 842 | t.Parallel() |
| 843 | replica := "r1" |
| 844 | replicaGroup := "c1" |
| 845 | userID := "userCheckReplicaCleanup" |
| 846 | ctx := user.InjectOrgID(context.Background(), userID) |
| 847 | |
| 848 | reg := prometheus.NewPedanticRegistry() |
| 849 | |
| 850 | kvStore, closer := consul.NewInMemoryClient(GetReplicaDescCodec(), log.NewNopLogger(), nil) |
| 851 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 852 | |
| 853 | mock := kv.PrefixClient(kvStore, "prefix") |
| 854 | c, err := NewHATracker(HATrackerConfig{ |
| 855 | EnableHATracker: true, |
| 856 | KVStore: kv.Config{Mock: mock}, |
| 857 | UpdateTimeout: 1 * time.Second, |
| 858 | UpdateTimeoutJitterMax: 0, |
| 859 | FailoverTimeout: time.Second, |
| 860 | }, trackerLimits{maxReplicaGroups: 100}, haTrackerStatusConfig, prometheus.WrapRegistererWithPrefix("cortex_", reg), "test-ha-tracker", util_log.Logger) |
| 861 | require.NoError(t, err) |
| 862 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), c)) |
| 863 | defer services.StopAndAwaitTerminated(context.Background(), c) //nolint:errcheck |
| 864 | |
| 865 | now := time.Now() |
| 866 | |
| 867 | err = c.CheckReplica(context.Background(), userID, replicaGroup, replica, now) |
| 868 | assert.NoError(t, err) |
| 869 | checkReplicaTimestamp(t, time.Second, c, userID, replicaGroup, replica, now) |
| 870 | |
| 871 | // Replica is not marked for deletion yet. |
| 872 | checkReplicaDeletionState(t, time.Second, c, userID, replicaGroup, true, true, false) |
| 873 | checkUserReplicaGroups(t, time.Second, c, userID, 1) |
| 874 | |
| 875 | // This will mark replica for deletion (with time.Now()) |
| 876 | c.cleanupOldReplicas(ctx, now.Add(1*time.Second)) |
| 877 | |
| 878 | // Verify marking for deletion. |
| 879 | checkReplicaDeletionState(t, time.Second, c, userID, replicaGroup, false, true, true) |
| 880 | checkUserReplicaGroups(t, time.Second, c, userID, 0) |
| 881 | |
| 882 | // This will "revive" the replica. |
| 883 | now = time.Now() |
| 884 | err = c.CheckReplica(context.Background(), userID, replicaGroup, replica, now) |
| 885 | assert.NoError(t, err) |
| 886 | checkReplicaTimestamp(t, time.Second, c, userID, replicaGroup, replica, now) // This also checks that entry is not marked for deletion. |
| 887 | checkUserReplicaGroups(t, time.Second, c, userID, 1) |
| 888 | |
| 889 | // This will mark replica for deletion again (with new time.Now()) |
| 890 | c.cleanupOldReplicas(ctx, now.Add(1*time.Second)) |
| 891 | checkReplicaDeletionState(t, time.Second, c, userID, replicaGroup, false, true, true) |
| 892 | checkUserReplicaGroups(t, time.Second, c, userID, 0) |
| 893 | |
| 894 | // Delete entry marked for deletion completely. |
| 895 | c.cleanupOldReplicas(ctx, time.Now().Add(5*time.Second)) |
| 896 | checkReplicaDeletionState(t, time.Second, c, userID, replicaGroup, false, false, false) |
| 897 | checkUserReplicaGroups(t, time.Second, c, userID, 0) |
| 898 |
nothing calls this directly
no test coverage detected