@@ -886,6 +886,22 @@ async fn record_to_node(
886
886
. conflict
887
887
}
888
888
889
+ async fn record_to_node_get_version (
890
+ connect : & mut ProtocolClient < Channel > ,
891
+ propose_id : ProposeId ,
892
+ command : Vec < u8 > ,
893
+ ) -> u64 {
894
+ connect
895
+ . record ( tonic:: Request :: new ( RecordRequest {
896
+ propose_id : Some ( propose_id) ,
897
+ command,
898
+ } ) )
899
+ . await
900
+ . unwrap ( )
901
+ . into_inner ( )
902
+ . sp_version
903
+ }
904
+
889
905
#[ tokio:: test( flavor = "multi_thread" ) ]
890
906
async fn curp_server_spec_pool_gc_ok ( ) {
891
907
init_logger ( ) ;
@@ -1000,3 +1016,55 @@ async fn curp_server_spec_pool_gc_should_not_remove_leader_entry() {
1000
1016
. await ;
1001
1017
assert ! ( conflict) ;
1002
1018
}
1019
+
1020
+ #[ tokio:: test( flavor = "multi_thread" ) ]
1021
+ async fn curp_server_spec_pool_gc_should_update_version ( ) {
1022
+ init_logger ( ) ;
1023
+ // sets the initail sync interval to a relatively long duration
1024
+ let group = CurpGroup :: new_with_custom_sp_sync_interval ( 5 , Duration :: from_secs ( 1 ) ) . await ;
1025
+ let client = group. new_client ( ) . await ;
1026
+
1027
+ let leader = client. fetch_leader_id ( true ) . await . unwrap ( ) ;
1028
+ let follower_id = group. nodes . keys ( ) . find ( |& id| & leader != id) . unwrap ( ) ;
1029
+ let mut follower_connect = group. get_connect ( follower_id) . await ;
1030
+ let cmd0 = bincode:: serialize ( & TestCommand :: new_put ( vec ! [ 0 ] , 0 ) ) . unwrap ( ) ;
1031
+ let mut ticker = tokio:: time:: interval ( Duration :: from_millis ( 1100 ) ) ;
1032
+ ticker. tick ( ) . await ;
1033
+
1034
+ let version0 = record_to_node_get_version (
1035
+ & mut follower_connect,
1036
+ ProposeId {
1037
+ client_id : 0 ,
1038
+ seq_num : 0 ,
1039
+ } ,
1040
+ cmd0. clone ( ) ,
1041
+ )
1042
+ . await ;
1043
+ assert_eq ! ( version0, 0 ) ;
1044
+
1045
+ ticker. tick ( ) . await ;
1046
+
1047
+ let version1 = record_to_node_get_version (
1048
+ & mut follower_connect,
1049
+ ProposeId {
1050
+ client_id : 1 ,
1051
+ seq_num : 0 ,
1052
+ } ,
1053
+ cmd0. clone ( ) ,
1054
+ )
1055
+ . await ;
1056
+ assert_eq ! ( version1, 1 ) ;
1057
+
1058
+ ticker. tick ( ) . await ;
1059
+
1060
+ let version2 = record_to_node_get_version (
1061
+ & mut follower_connect,
1062
+ ProposeId {
1063
+ client_id : 2 ,
1064
+ seq_num : 0 ,
1065
+ } ,
1066
+ cmd0. clone ( ) ,
1067
+ )
1068
+ . await ;
1069
+ assert_eq ! ( version2, 2 ) ;
1070
+ }
0 commit comments