1- /// Cache config should be injected to the handler!
2- /// This is to enable client to configure things dynamically.
3-
4- /// if the value of dir is /tmp, then the expected response to CONFIG GET dir is:
5- /// *2\r\n$3\r\ndir\r\n$4\r\n/tmp\r\n
6- mod common;
7- use crate :: common:: array;
8- use common:: ServerEnv ;
9- use common:: spawn_server_process;
1+ use crate :: common:: { ServerEnv , array, spawn_server_process} ;
2+
103use duva:: clients:: ClientStreamHandler ;
114use duva:: domains:: query_parsers:: query_io:: QueryIO ;
125use std:: time:: SystemTime ;
136use std:: time:: UNIX_EPOCH ;
147
158// TODO response cannot be deterministic!
169#[ tokio:: test]
17- async fn test_save_read_snapshot ( ) {
10+ async fn test_snapshot_persists_and_recovers_state ( ) {
1811 // GIVEN
1912 let env = ServerEnv :: default ( ) . with_file_name ( create_unique_file_name ( "test_save_dump" ) ) ;
2013 let leader_process = spawn_server_process ( & env) ;
@@ -38,39 +31,31 @@ async fn test_save_read_snapshot() {
3831 // check replication info
3932 let res = h. send_and_get ( & array ( vec ! [ "INFO" , "replication" ] ) ) . await ;
4033 let info: Vec < & str > = res. split ( "\r \n " ) . collect ( ) ;
41- let prev_leader_repl_id = info[ 3 ] . split ( ":" ) . collect :: < Vec < & str > > ( ) [ 1 ] ;
42- let prev_leader_repl_offset = info[ 4 ] . split ( ":" ) . collect :: < Vec < & str > > ( ) [ 1 ] ;
4334
44- // THEN
35+ // WHEN
4536 assert_eq ! ( h. send_and_get( & array( vec![ "SAVE" ] ) ) . await , QueryIO :: Null . serialize( ) ) ;
4637
4738 // wait for the file to be created
4839 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 1 ) ) . await ;
49-
50- // THEN
5140 // kill leader process
5241 drop ( leader_process) ;
5342
5443 // run server with the same file name
55- let leader_process = spawn_server_process ( & env) ;
44+ let new_process = spawn_server_process ( & env) ;
5645
5746 // wait for the server to start
5847 tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 1 ) ) . await ;
5948
60- let mut h = ClientStreamHandler :: new ( leader_process . bind_addr ( ) ) . await ;
49+ let mut client = ClientStreamHandler :: new ( new_process . bind_addr ( ) ) . await ;
6150
62- // keys
63- assert_eq ! ( h. send_and_get( & array( vec![ "KEYS" , "*" ] ) ) . await , array( vec![ "foo2" , "foo" ] ) ) ;
51+ assert_eq ! ( client. send_and_get( & array( vec![ "KEYS" , "*" ] ) ) . await , array( vec![ "foo2" , "foo" ] ) ) ;
6452
6553 // replication info
66- let res = h. send_and_get ( & array ( vec ! [ "INFO" , "replication" ] ) ) . await ;
67- let info: Vec < & str > = res. split ( "\r \n " ) . collect ( ) ;
68- let leader_repl_id = info[ 3 ] . split ( ":" ) . collect :: < Vec < & str > > ( ) [ 1 ] ;
69- let leader_repl_offset = info[ 4 ] . split ( ":" ) . collect :: < Vec < & str > > ( ) [ 1 ] ;
54+ let res = client. send_and_get ( & array ( vec ! [ "INFO" , "replication" ] ) ) . await ;
55+ let info2: Vec < & str > = res. split ( "\r \n " ) . collect ( ) ;
7056
7157 // THEN
72- assert_eq ! ( leader_repl_id, prev_leader_repl_id) ;
73- assert_eq ! ( leader_repl_offset, prev_leader_repl_offset) ;
58+ assert_eq ! ( info, info2) ;
7459}
7560
7661fn create_unique_file_name ( function_name : & str ) -> String {
0 commit comments