MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestRingUpdates

Function TestRingUpdates

pkg/ring/ring_test.go:2950–3029  ·  view source on GitHub ↗

This test verifies that ring is getting updates, even after extending check in the loop method.

(t *testing.T)

Source from the content-addressed store, hash-verified

2948
2949// This test verifies that ring is getting updates, even after extending check in the loop method.
2950func TestRingUpdates(t *testing.T) {
2951 const (
2952 numInstances = 3
2953 numZones = 3
2954 )
2955
2956 tests := map[string]struct {
2957 excludedZones []string
2958 expectedInstances int
2959 }{
2960 "without excluded zones": {
2961 expectedInstances: 3,
2962 },
2963 "with excluded zones": {
2964 excludedZones: []string{"zone-0"},
2965 expectedInstances: 2,
2966 },
2967 }
2968
2969 for testName, testData := range tests {
2970 t.Run(testName, func(t *testing.T) {
2971 inmem, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil)
2972 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
2973
2974 cfg := Config{
2975 KVStore: kv.Config{Mock: inmem},
2976 HeartbeatTimeout: 1 * time.Minute,
2977 ReplicationFactor: 3,
2978 ExcludedZones: flagext.StringSliceCSV(testData.excludedZones),
2979 }
2980
2981 ring, err := New(cfg, "test", "test", log.NewNopLogger(), nil)
2982 require.NoError(t, err)
2983 require.NoError(t, services.StartAndAwaitRunning(context.Background(), ring))
2984 t.Cleanup(func() {
2985 _ = services.StopAndAwaitTerminated(context.Background(), ring)
2986 })
2987
2988 require.Equal(t, 0, ring.InstancesCount())
2989
2990 // Start 1 lifecycler for each instance we want to register in the ring.
2991 var lifecyclers []*Lifecycler
2992 for instanceID := 1; instanceID <= numInstances; instanceID++ {
2993 lifecyclers = append(lifecyclers, startLifecycler(t, cfg, 100*time.Millisecond, instanceID, numZones))
2994 }
2995
2996 // Ensure the ring client got updated.
2997 test.Poll(t, 1*time.Second, testData.expectedInstances, func() any {
2998 return ring.InstancesCount()
2999 })
3000
3001 // Sleep for a few seconds (ring timestamp resolution is 1 second, so to verify that ring is updated in the background,
3002 // sleep for 2 seconds)
3003 time.Sleep(2 * time.Second)
3004
3005 rs, err := ring.GetAllHealthy(Read)
3006 require.NoError(t, err)
3007

Callers

nothing calls this directly

Calls 13

NewInMemoryClientFunction · 0.92
StringSliceCSVTypeAlias · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
GetCodecFunction · 0.85
startLifecyclerFunction · 0.85
NewFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.65
InstancesCountMethod · 0.65

Tested by

no test coverage detected