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

Function TestCheckReplicaOverwriteTimeout

pkg/ha/ha_tracker_test.go:318–354  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

316}
317
318func TestCheckReplicaOverwriteTimeout(t *testing.T) {
319 t.Parallel()
320 replica1 := "replica1"
321 replica2 := "replica2"
322
323 c, err := NewHATracker(HATrackerConfig{
324 EnableHATracker: true,
325 KVStore: kv.Config{Store: "inmemory"},
326 UpdateTimeout: 100 * time.Millisecond,
327 UpdateTimeoutJitterMax: 0,
328 FailoverTimeout: time.Second,
329 }, trackerLimits{maxReplicaGroups: 100}, haTrackerStatusConfig, nil, "test-ha-tracker", log.NewNopLogger())
330 require.NoError(t, err)
331 require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))
332 defer services.StopAndAwaitTerminated(context.Background(), c) //nolint:errcheck
333
334 now := time.Now()
335
336 // Write the first time.
337 err = c.CheckReplica(context.Background(), "user", "test", replica1, now)
338 assert.NoError(t, err)
339
340 // Throw away a sample from replica2.
341 err = c.CheckReplica(context.Background(), "user", "test", replica2, now)
342 assert.Error(t, err)
343
344 // Wait more than the overwrite timeout.
345 now = now.Add(1100 * time.Millisecond)
346
347 // Accept from replica 2, this should overwrite the saved replica of replica 1.
348 err = c.CheckReplica(context.Background(), "user", "test", replica2, now)
349 assert.NoError(t, err)
350
351 // We timed out accepting samples from replica 1 and should now reject them.
352 err = c.CheckReplica(context.Background(), "user", "test", replica1, now)
353 assert.Error(t, err)
354}
355
356func TestCheckReplicaMultiCluster(t *testing.T) {
357 t.Parallel()

Callers

nothing calls this directly

Calls 6

CheckReplicaMethod · 0.95
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
NewHATrackerFunction · 0.85
ErrorMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected