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

Function TestWatchPrefixAssignment

pkg/ha/ha_tracker_test.go:287–316  ·  view source on GitHub ↗

Test that values are set in the HATracker after WatchPrefix has found it in the KVStore.

(t *testing.T)

Source from the content-addressed store, hash-verified

285
286// Test that values are set in the HATracker after WatchPrefix has found it in the KVStore.
287func TestWatchPrefixAssignment(t *testing.T) {
288 t.Parallel()
289 replicaGroup := "c1"
290 replica := "r1"
291
292 codec := GetReplicaDescCodec()
293 kvStore, closer := consul.NewInMemoryClient(codec, log.NewNopLogger(), nil)
294 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
295
296 mock := kv.PrefixClient(kvStore, "prefix")
297 c, err := NewHATracker(HATrackerConfig{
298 EnableHATracker: true,
299 KVStore: kv.Config{Mock: mock},
300 UpdateTimeout: time.Millisecond,
301 UpdateTimeoutJitterMax: 0,
302 FailoverTimeout: time.Millisecond * 2,
303 }, trackerLimits{maxReplicaGroups: 100}, haTrackerStatusConfig, nil, "test-ha-tracker", log.NewNopLogger())
304 require.NoError(t, err)
305 require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))
306 defer services.StopAndAwaitTerminated(context.Background(), c) //nolint:errcheck
307
308 // Write the first time.
309 now := time.Now()
310
311 err = c.CheckReplica(context.Background(), "user", replicaGroup, replica, now)
312 assert.NoError(t, err)
313
314 // Check to see if the value in the trackers cache is correct.
315 checkReplicaTimestamp(t, time.Second, c, "user", replicaGroup, replica, now)
316}
317
318func TestCheckReplicaOverwriteTimeout(t *testing.T) {
319 t.Parallel()

Callers

nothing calls this directly

Calls 9

CheckReplicaMethod · 0.95
NewInMemoryClientFunction · 0.92
PrefixClientFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
GetReplicaDescCodecFunction · 0.85
NewHATrackerFunction · 0.85
checkReplicaTimestampFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected