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

Function TestCheckReplicaUpdateTimeoutJitter

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

Source from the content-addressed store, hash-verified

570}
571
572func TestCheckReplicaUpdateTimeoutJitter(t *testing.T) {
573 t.Parallel()
574
575 tests := map[string]struct {
576 updateTimeout time.Duration
577 updateJitter time.Duration
578 startTime time.Time
579 updateTime time.Time
580 expectedTimestamp time.Time
581 }{
582 "should not refresh the replica if the update timeout is not expired yet (without jitter)": {
583 updateTimeout: 10 * time.Second,
584 updateJitter: 0,
585 startTime: time.Unix(5, 0),
586 updateTime: time.Unix(14, 0),
587 expectedTimestamp: time.Unix(5, 0),
588 },
589 "should refresh the replica if the update timeout is expired (without jitter)": {
590 updateTimeout: 10 * time.Second,
591 updateJitter: 0,
592 startTime: time.Unix(5, 0),
593 updateTime: time.Unix(15, 0),
594 expectedTimestamp: time.Unix(15, 0),
595 },
596 "should not refresh the replica if the update timeout is not expired yet (with jitter)": {
597 updateTimeout: 10 * time.Second,
598 updateJitter: 2 * time.Second,
599 startTime: time.Unix(5, 0),
600 updateTime: time.Unix(16, 0),
601 expectedTimestamp: time.Unix(5, 0),
602 },
603 "should refresh the replica if the update timeout is expired (with jitter)": {
604 updateTimeout: 10 * time.Second,
605 updateJitter: 2 * time.Second,
606 startTime: time.Unix(5, 0),
607 updateTime: time.Unix(17, 0),
608 expectedTimestamp: time.Unix(17, 0),
609 },
610 }
611
612 for testName, testData := range tests {
613 t.Run(testName, func(t *testing.T) {
614 t.Parallel()
615 // Init HA tracker
616 codec := GetReplicaDescCodec()
617 kvStore, closer := consul.NewInMemoryClient(codec, log.NewNopLogger(), nil)
618 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
619
620 mock := kv.PrefixClient(kvStore, "prefix")
621 c, err := NewHATracker(HATrackerConfig{
622 EnableHATracker: true,
623 KVStore: kv.Config{Mock: mock},
624 UpdateTimeout: testData.updateTimeout,
625 UpdateTimeoutJitterMax: 0,
626 FailoverTimeout: time.Second,
627 }, trackerLimits{maxReplicaGroups: 100}, haTrackerStatusConfig, nil, "test-ha-tracker", log.NewNopLogger())
628 require.NoError(t, err)
629 require.NoError(t, services.StartAndAwaitRunning(context.Background(), c))

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
RunMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected