@@ -307,7 +307,8 @@ func TestHaTrackerWithMemberList(t *testing.T) {
307
307
// Update KVStore - this should elect replica 2.
308
308
tracker .updateKVStoreAll (context .Background (), now )
309
309
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 )
311
312
312
313
// Now we should accept from replica 2.
313
314
err = tracker .checkReplica (context .Background (), "user" , cluster , replica2 , now )
@@ -477,7 +478,7 @@ func TestHATrackerWatchPrefixAssignment(t *testing.T) {
477
478
assert .NoError (t , err )
478
479
479
480
// 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 )
481
482
}
482
483
483
484
func TestHATrackerCheckReplicaOverwriteTimeout (t * testing.T ) {
@@ -515,7 +516,7 @@ func TestHATrackerCheckReplicaOverwriteTimeout(t *testing.T) {
515
516
// Update KVStore - this should elect replica 2.
516
517
c .updateKVStoreAll (context .Background (), now )
517
518
518
- checkReplicaTimestamp (t , time .Second , c , "user" , "test" , replica2 , now , now )
519
+ checkReplicaTimestamp (t , 2 * time .Second , c , "user" , "test" , replica2 , now , now )
519
520
520
521
// Now we should accept from replica 2.
521
522
err = c .checkReplica (context .Background (), "user" , "test" , replica2 , now )
@@ -624,7 +625,7 @@ func TestHATrackerCheckReplicaMultiClusterTimeout(t *testing.T) {
624
625
err = c .checkReplica (context .Background (), "user" , "c1" , replica2 , now )
625
626
assert .Error (t , err )
626
627
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 )
628
629
629
630
// Accept a sample from c1/replica2.
630
631
err = c .checkReplica (context .Background (), "user" , "c1" , replica2 , now )
@@ -677,21 +678,21 @@ func TestHATrackerCheckReplicaUpdateTimeout(t *testing.T) {
677
678
err = c .checkReplica (context .Background (), user , cluster , replica , startTime )
678
679
assert .NoError (t , err )
679
680
680
- checkReplicaTimestamp (t , time .Second , c , user , cluster , replica , startTime , startTime )
681
+ checkReplicaTimestamp (t , 2 * time .Second , c , user , cluster , replica , startTime , startTime )
681
682
682
683
// Timestamp should not update here, since time has not advanced.
683
684
err = c .checkReplica (context .Background (), user , cluster , replica , startTime )
684
685
assert .NoError (t , err )
685
686
686
- checkReplicaTimestamp (t , time .Second , c , user , cluster , replica , startTime , startTime )
687
+ checkReplicaTimestamp (t , 2 * time .Second , c , user , cluster , replica , startTime , startTime )
687
688
688
689
// Wait 500ms and the timestamp should still not update.
689
690
updateTime := time .Unix (0 , startTime .UnixNano ()).Add (500 * time .Millisecond )
690
691
c .updateKVStoreAll (context .Background (), updateTime )
691
692
692
693
err = c .checkReplica (context .Background (), user , cluster , replica , updateTime )
693
694
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 )
695
696
696
697
receivedAt := updateTime
697
698
@@ -700,7 +701,7 @@ func TestHATrackerCheckReplicaUpdateTimeout(t *testing.T) {
700
701
c .updateKVStoreAll (context .Background (), updateTime )
701
702
702
703
// 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 )
704
705
705
706
err = c .checkReplica (context .Background (), user , cluster , replica , updateTime )
706
707
assert .NoError (t , err )
@@ -732,22 +733,22 @@ func TestHATrackerCheckReplicaMultiUser(t *testing.T) {
732
733
// Write the first time for user 1.
733
734
err = c .checkReplica (context .Background (), "user1" , cluster , replica , now )
734
735
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 )
736
737
737
738
// Write the first time for user 2.
738
739
err = c .checkReplica (context .Background (), "user2" , cluster , replica , now )
739
740
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 )
741
742
742
743
// Now we've waited > 1s, so the timestamp should update.
743
744
updated := now .Add (1100 * time .Millisecond )
744
745
err = c .checkReplica (context .Background (), "user1" , cluster , replica , updated )
745
746
assert .NoError (t , err )
746
747
c .updateKVStoreAll (context .Background (), updated )
747
748
748
- checkReplicaTimestamp (t , time .Second , c , "user1" , cluster , replica , updated , updated )
749
+ checkReplicaTimestamp (t , 2 * time .Second , c , "user1" , cluster , replica , updated , updated )
749
750
// 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 )
751
752
}
752
753
753
754
func TestHATrackerCheckReplicaUpdateTimeoutJitter (t * testing.T ) {
@@ -820,15 +821,15 @@ func TestHATrackerCheckReplicaUpdateTimeoutJitter(t *testing.T) {
820
821
// Init the replica in the KV Store
821
822
err = c .checkReplica (ctx , "user1" , "cluster" , "replica-1" , testData .startTime )
822
823
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 )
824
825
825
826
// Refresh the replica in the KV Store
826
827
err = c .checkReplica (ctx , "user1" , "cluster" , "replica-1" , testData .updateTime )
827
828
require .NoError (t , err )
828
829
c .updateKVStoreAll (context .Background (), testData .updateTime )
829
830
830
831
// 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 )
832
833
})
833
834
}
834
835
}
@@ -931,7 +932,7 @@ func TestHATrackerClustersLimit(t *testing.T) {
931
932
assert .Error (t , err )
932
933
// Update KVStore.
933
934
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 )
935
936
936
937
assert .NoError (t , t1 .checkReplica (context .Background (), userID , "b" , "b2" , now ))
937
938
waitForClustersUpdate (t , 2 , t1 , userID )
@@ -1077,7 +1078,7 @@ func TestHATrackerCheckReplicaCleanup(t *testing.T) {
1077
1078
1078
1079
err = c .checkReplica (context .Background (), userID , cluster , replica , now )
1079
1080
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 )
1081
1082
1082
1083
// Replica is not marked for deletion yet.
1083
1084
checkReplicaDeletionState (t , time .Second , c , userID , cluster , true , true , false )
@@ -1094,7 +1095,7 @@ func TestHATrackerCheckReplicaCleanup(t *testing.T) {
1094
1095
now = time .Now ()
1095
1096
err = c .checkReplica (context .Background (), userID , cluster , replica , now )
1096
1097
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.
1098
1099
checkUserClusters (t , time .Second , c , userID , 1 )
1099
1100
1100
1101
// This will mark replica for deletion again (with new time.Now())
@@ -1246,8 +1247,8 @@ func TestHATrackerChangeInElectedReplicaClearsLastSeenTimestamp(t *testing.T) {
1246
1247
1247
1248
assert .NoError (t , t1 .checkReplica (context .Background (), userID , cluster , firstReplica , now ))
1248
1249
// 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 )
1251
1252
1252
1253
// Ten seconds later, t1 receives request from first replica again
1253
1254
now = now .Add (10 * time .Second )
@@ -1261,7 +1262,7 @@ func TestHATrackerChangeInElectedReplicaClearsLastSeenTimestamp(t *testing.T) {
1261
1262
t2 .updateKVStoreAll (context .Background (), now )
1262
1263
1263
1264
// 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 )
1265
1266
1266
1267
// Furthermore, t1 has never seen "second" replica, so it should not have "electedLastSeenTimestamp" set.
1267
1268
{
@@ -1285,7 +1286,7 @@ func TestHATrackerChangeInElectedReplicaClearsLastSeenTimestamp(t *testing.T) {
1285
1286
t1 .updateKVStoreAll (context .Background (), now )
1286
1287
1287
1288
// 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 )
1289
1290
1290
1291
// Since t2 has seen new elected replica too, we should have non-zero "electedLastSeenTimestamp".
1291
1292
{
0 commit comments