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

Function checkReplicaTimestamp

pkg/ha/ha_tracker_test.go:39–63  ·  view source on GitHub ↗
(t *testing.T, duration time.Duration, c *HATracker, user, replicaGroup, replica string, expected time.Time)

Source from the content-addressed store, hash-verified

37}
38
39func checkReplicaTimestamp(t *testing.T, duration time.Duration, c *HATracker, user, replicaGroup, replica string, expected time.Time) {
40 key := fmt.Sprintf("%s/%s", user, replicaGroup)
41
42 // Round the expected timestamp with milliseconds precision
43 // to match "received at" precision
44 expected = expected.Truncate(time.Millisecond)
45
46 test.Poll(t, duration, nil, func() any {
47 c.electedLock.RLock()
48 r := c.elected[key]
49 c.electedLock.RUnlock()
50
51 if r.GetReplica() != replica {
52 return fmt.Errorf("replicas did not match: %s != %s", r.GetReplica(), replica)
53 }
54 if r.GetDeletedAt() > 0 {
55 return fmt.Errorf("replica is marked for deletion")
56 }
57 if !timestamp.Time(r.GetReceivedAt()).Equal(expected) {
58 return fmt.Errorf("timestamps did not match: %+v != %+v", timestamp.Time(r.GetReceivedAt()), expected)
59 }
60
61 return nil
62 })
63}
64
65func TestHATrackerConfig_Validate(t *testing.T) {
66 t.Parallel()

Calls 5

PollFunction · 0.92
GetReplicaMethod · 0.80
GetDeletedAtMethod · 0.80
GetReceivedAtMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected