Skip to content

Commit 33ca7b5

Browse files
authored
distributor: Increase test polling duration to allow the cache suffic… (#10364)
1 parent ce6871c commit 33ca7b5

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

pkg/distributor/ha_tracker_test.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ func TestHaTrackerWithMemberList(t *testing.T) {
307307
// Update KVStore - this should elect replica 2.
308308
tracker.updateKVStoreAll(context.Background(), now)
309309

310-
checkReplicaTimestamp(t, time.Second, tracker, "user", cluster, replica2, now, now)
310+
// Evaluate up to 2 seconds to verify whether the tracker’s cache replica has been updated to r2.
311+
checkReplicaTimestamp(t, 2*time.Second, tracker, "user", cluster, replica2, now, now)
311312

312313
// Now we should accept from replica 2.
313314
err = tracker.checkReplica(context.Background(), "user", cluster, replica2, now)
@@ -477,7 +478,7 @@ func TestHATrackerWatchPrefixAssignment(t *testing.T) {
477478
assert.NoError(t, err)
478479

479480
// Check to see if the value in the trackers cache is correct.
480-
checkReplicaTimestamp(t, time.Second, c, "user", cluster, replica, now, now)
481+
checkReplicaTimestamp(t, 2*time.Second, c, "user", cluster, replica, now, now)
481482
}
482483

483484
func TestHATrackerCheckReplicaOverwriteTimeout(t *testing.T) {
@@ -515,7 +516,7 @@ func TestHATrackerCheckReplicaOverwriteTimeout(t *testing.T) {
515516
// Update KVStore - this should elect replica 2.
516517
c.updateKVStoreAll(context.Background(), now)
517518

518-
checkReplicaTimestamp(t, time.Second, c, "user", "test", replica2, now, now)
519+
checkReplicaTimestamp(t, 2*time.Second, c, "user", "test", replica2, now, now)
519520

520521
// Now we should accept from replica 2.
521522
err = c.checkReplica(context.Background(), "user", "test", replica2, now)
@@ -624,7 +625,7 @@ func TestHATrackerCheckReplicaMultiClusterTimeout(t *testing.T) {
624625
err = c.checkReplica(context.Background(), "user", "c1", replica2, now)
625626
assert.Error(t, err)
626627
c.updateKVStoreAll(context.Background(), now)
627-
checkReplicaTimestamp(t, time.Second, c, "user", "c1", replica2, now, now)
628+
checkReplicaTimestamp(t, 2*time.Second, c, "user", "c1", replica2, now, now)
628629

629630
// Accept a sample from c1/replica2.
630631
err = c.checkReplica(context.Background(), "user", "c1", replica2, now)
@@ -677,21 +678,21 @@ func TestHATrackerCheckReplicaUpdateTimeout(t *testing.T) {
677678
err = c.checkReplica(context.Background(), user, cluster, replica, startTime)
678679
assert.NoError(t, err)
679680

680-
checkReplicaTimestamp(t, time.Second, c, user, cluster, replica, startTime, startTime)
681+
checkReplicaTimestamp(t, 2*time.Second, c, user, cluster, replica, startTime, startTime)
681682

682683
// Timestamp should not update here, since time has not advanced.
683684
err = c.checkReplica(context.Background(), user, cluster, replica, startTime)
684685
assert.NoError(t, err)
685686

686-
checkReplicaTimestamp(t, time.Second, c, user, cluster, replica, startTime, startTime)
687+
checkReplicaTimestamp(t, 2*time.Second, c, user, cluster, replica, startTime, startTime)
687688

688689
// Wait 500ms and the timestamp should still not update.
689690
updateTime := time.Unix(0, startTime.UnixNano()).Add(500 * time.Millisecond)
690691
c.updateKVStoreAll(context.Background(), updateTime)
691692

692693
err = c.checkReplica(context.Background(), user, cluster, replica, updateTime)
693694
assert.NoError(t, err)
694-
checkReplicaTimestamp(t, time.Second, c, user, cluster, replica, startTime, startTime)
695+
checkReplicaTimestamp(t, 2*time.Second, c, user, cluster, replica, startTime, startTime)
695696

696697
receivedAt := updateTime
697698

@@ -700,7 +701,7 @@ func TestHATrackerCheckReplicaUpdateTimeout(t *testing.T) {
700701
c.updateKVStoreAll(context.Background(), updateTime)
701702

702703
// Timestamp stored in KV should be time when we have received a request (called "checkReplica"), not current time (updateTime).
703-
checkReplicaTimestamp(t, time.Second, c, user, cluster, replica, receivedAt, receivedAt)
704+
checkReplicaTimestamp(t, 2*time.Second, c, user, cluster, replica, receivedAt, receivedAt)
704705

705706
err = c.checkReplica(context.Background(), user, cluster, replica, updateTime)
706707
assert.NoError(t, err)
@@ -732,22 +733,22 @@ func TestHATrackerCheckReplicaMultiUser(t *testing.T) {
732733
// Write the first time for user 1.
733734
err = c.checkReplica(context.Background(), "user1", cluster, replica, now)
734735
assert.NoError(t, err)
735-
checkReplicaTimestamp(t, time.Second, c, "user1", cluster, replica, now, now)
736+
checkReplicaTimestamp(t, 2*time.Second, c, "user1", cluster, replica, now, now)
736737

737738
// Write the first time for user 2.
738739
err = c.checkReplica(context.Background(), "user2", cluster, replica, now)
739740
assert.NoError(t, err)
740-
checkReplicaTimestamp(t, time.Second, c, "user2", cluster, replica, now, now)
741+
checkReplicaTimestamp(t, 2*time.Second, c, "user2", cluster, replica, now, now)
741742

742743
// Now we've waited > 1s, so the timestamp should update.
743744
updated := now.Add(1100 * time.Millisecond)
744745
err = c.checkReplica(context.Background(), "user1", cluster, replica, updated)
745746
assert.NoError(t, err)
746747
c.updateKVStoreAll(context.Background(), updated)
747748

748-
checkReplicaTimestamp(t, time.Second, c, "user1", cluster, replica, updated, updated)
749+
checkReplicaTimestamp(t, 2*time.Second, c, "user1", cluster, replica, updated, updated)
749750
// No update for user2.
750-
checkReplicaTimestamp(t, time.Second, c, "user2", cluster, replica, now, now)
751+
checkReplicaTimestamp(t, 2*time.Second, c, "user2", cluster, replica, now, now)
751752
}
752753

753754
func TestHATrackerCheckReplicaUpdateTimeoutJitter(t *testing.T) {
@@ -820,15 +821,15 @@ func TestHATrackerCheckReplicaUpdateTimeoutJitter(t *testing.T) {
820821
// Init the replica in the KV Store
821822
err = c.checkReplica(ctx, "user1", "cluster", "replica-1", testData.startTime)
822823
require.NoError(t, err)
823-
checkReplicaTimestamp(t, time.Second, c, "user1", "cluster", "replica-1", testData.startTime, testData.startTime)
824+
checkReplicaTimestamp(t, 2*time.Second, c, "user1", "cluster", "replica-1", testData.startTime, testData.startTime)
824825

825826
// Refresh the replica in the KV Store
826827
err = c.checkReplica(ctx, "user1", "cluster", "replica-1", testData.updateTime)
827828
require.NoError(t, err)
828829
c.updateKVStoreAll(context.Background(), testData.updateTime)
829830

830831
// Assert on the received timestamp
831-
checkReplicaTimestamp(t, time.Second, c, "user1", "cluster", "replica-1", testData.expectedTimestamp, testData.expectedTimestamp)
832+
checkReplicaTimestamp(t, 2*time.Second, c, "user1", "cluster", "replica-1", testData.expectedTimestamp, testData.expectedTimestamp)
832833
})
833834
}
834835
}
@@ -931,7 +932,7 @@ func TestHATrackerClustersLimit(t *testing.T) {
931932
assert.Error(t, err)
932933
// Update KVStore.
933934
t1.updateKVStoreAll(context.Background(), now)
934-
checkReplicaTimestamp(t, time.Second, t1, userID, "b", "b2", now, now)
935+
checkReplicaTimestamp(t, 2*time.Second, t1, userID, "b", "b2", now, now)
935936

936937
assert.NoError(t, t1.checkReplica(context.Background(), userID, "b", "b2", now))
937938
waitForClustersUpdate(t, 2, t1, userID)
@@ -1077,7 +1078,7 @@ func TestHATrackerCheckReplicaCleanup(t *testing.T) {
10771078

10781079
err = c.checkReplica(context.Background(), userID, cluster, replica, now)
10791080
assert.NoError(t, err)
1080-
checkReplicaTimestamp(t, time.Second, c, userID, cluster, replica, now, now)
1081+
checkReplicaTimestamp(t, 2*time.Second, c, userID, cluster, replica, now, now)
10811082

10821083
// Replica is not marked for deletion yet.
10831084
checkReplicaDeletionState(t, time.Second, c, userID, cluster, true, true, false)
@@ -1094,7 +1095,7 @@ func TestHATrackerCheckReplicaCleanup(t *testing.T) {
10941095
now = time.Now()
10951096
err = c.checkReplica(context.Background(), userID, cluster, replica, now)
10961097
assert.NoError(t, err)
1097-
checkReplicaTimestamp(t, time.Second, c, userID, cluster, replica, now, now) // This also checks that entry is not marked for deletion.
1098+
checkReplicaTimestamp(t, 2*time.Second, c, userID, cluster, replica, now, now) // This also checks that entry is not marked for deletion.
10981099
checkUserClusters(t, time.Second, c, userID, 1)
10991100

11001101
// This will mark replica for deletion again (with new time.Now())
@@ -1246,8 +1247,8 @@ func TestHATrackerChangeInElectedReplicaClearsLastSeenTimestamp(t *testing.T) {
12461247

12471248
assert.NoError(t, t1.checkReplica(context.Background(), userID, cluster, firstReplica, now))
12481249
// Both trackers will see "first" replica as current.
1249-
checkReplicaTimestamp(t, time.Second, t1, userID, cluster, firstReplica, now, now)
1250-
checkReplicaTimestamp(t, time.Second, t2, userID, cluster, firstReplica, now, now)
1250+
checkReplicaTimestamp(t, 2*time.Second, t1, userID, cluster, firstReplica, now, now)
1251+
checkReplicaTimestamp(t, 2*time.Second, t2, userID, cluster, firstReplica, now, now)
12511252

12521253
// Ten seconds later, t1 receives request from first replica again
12531254
now = now.Add(10 * time.Second)
@@ -1261,7 +1262,7 @@ func TestHATrackerChangeInElectedReplicaClearsLastSeenTimestamp(t *testing.T) {
12611262
t2.updateKVStoreAll(context.Background(), now)
12621263

12631264
// t1 is reading updates from KV store, and should see second replica being the elected one.
1264-
checkReplicaTimestamp(t, time.Second, t1, userID, cluster, secondReplica, secondReplicaReceivedAtT2, secondReplicaReceivedAtT2)
1265+
checkReplicaTimestamp(t, 2*time.Second, t1, userID, cluster, secondReplica, secondReplicaReceivedAtT2, secondReplicaReceivedAtT2)
12651266

12661267
// Furthermore, t1 has never seen "second" replica, so it should not have "electedLastSeenTimestamp" set.
12671268
{
@@ -1285,7 +1286,7 @@ func TestHATrackerChangeInElectedReplicaClearsLastSeenTimestamp(t *testing.T) {
12851286
t1.updateKVStoreAll(context.Background(), now)
12861287

12871288
// t2 is reading updates from KV store, and should see "second" replica being the elected one.
1288-
checkReplicaTimestamp(t, time.Second, t2, userID, cluster, firstReplica, firstReceivedAtT1, firstReceivedAtT1)
1289+
checkReplicaTimestamp(t, 2*time.Second, t2, userID, cluster, firstReplica, firstReceivedAtT1, firstReceivedAtT1)
12891290

12901291
// Since t2 has seen new elected replica too, we should have non-zero "electedLastSeenTimestamp".
12911292
{

0 commit comments

Comments
 (0)