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

Function TestCheckReplicaMultiUser

pkg/ha/ha_tracker_test.go:530–570  ·  view source on GitHub ↗

Test that writes only happen every write timeout.

(t *testing.T)

Source from the content-addressed store, hash-verified

528
529// Test that writes only happen every write timeout.
530func TestCheckReplicaMultiUser(t *testing.T) {
531 t.Parallel()
532 replica := "r1"
533 replicaGroup := "c1"
534
535 codec := GetReplicaDescCodec()
536 kvStore, closer := consul.NewInMemoryClient(codec, log.NewNopLogger(), nil)
537 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
538
539 mock := kv.PrefixClient(kvStore, "prefix")
540 c, err := NewHATracker(HATrackerConfig{
541 EnableHATracker: true,
542 KVStore: kv.Config{Mock: mock},
543 UpdateTimeout: 100 * time.Millisecond,
544 UpdateTimeoutJitterMax: 0,
545 FailoverTimeout: time.Second,
546 }, trackerLimits{maxReplicaGroups: 100}, haTrackerStatusConfig, nil, "test-ha-tracker", log.NewNopLogger())
547 require.NoError(t, err)
548 require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))
549 defer services.StopAndAwaitTerminated(context.Background(), c) //nolint:errcheck
550
551 now := time.Now()
552
553 // Write the first time for user 1.
554 err = c.CheckReplica(context.Background(), "user1", replicaGroup, replica, now)
555 assert.NoError(t, err)
556 checkReplicaTimestamp(t, time.Second, c, "user1", replicaGroup, replica, now)
557
558 // Write the first time for user 2.
559 err = c.CheckReplica(context.Background(), "user2", replicaGroup, replica, now)
560 assert.NoError(t, err)
561 checkReplicaTimestamp(t, time.Second, c, "user2", replicaGroup, replica, now)
562
563 // Now we've waited > 1s, so the timestamp should update.
564 updated := now.Add(1100 * time.Millisecond)
565 err = c.CheckReplica(context.Background(), "user1", replicaGroup, replica, updated)
566 assert.NoError(t, err)
567 checkReplicaTimestamp(t, time.Second, c, "user1", replicaGroup, replica, updated)
568 // No update for user2.
569 checkReplicaTimestamp(t, time.Second, c, "user2", replicaGroup, replica, now)
570}
571
572func TestCheckReplicaUpdateTimeoutJitter(t *testing.T) {
573 t.Parallel()

Callers

nothing calls this directly

Calls 10

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
AddMethod · 0.45

Tested by

no test coverage detected