1set server_path [tmpdir "server.rdb-encoding-test"] 2 3# Copy RDB with different encodings in server path 4exec cp tests/assets/encodings.rdb $server_path 5 6start_server [list overrides [list "dir" $server_path "dbfilename" "encodings.rdb"]] { 7 test "RDB encoding loading test" { 8 r select 0 9 csvdump r 10 } {"0","compressible","string","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 11"0","hash","hash","a","1","aa","10","aaa","100","b","2","bb","20","bbb","200","c","3","cc","30","ccc","300","ddd","400","eee","5000000000", 12"0","hash_zipped","hash","a","1","b","2","c","3", 13"0","list","list","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000", 14"0","list_zipped","list","1","2","3","a","b","c","100000","6000000000", 15"0","number","string","10" 16"0","set","set","1","100000","2","3","6000000000","a","b","c", 17"0","set_zipped_1","set","1","2","3","4", 18"0","set_zipped_2","set","100000","200000","300000","400000", 19"0","set_zipped_3","set","1000000000","2000000000","3000000000","4000000000","5000000000","6000000000", 20"0","string","string","Hello World" 21"0","zset","zset","a","1","b","2","c","3","aa","10","bb","20","cc","30","aaa","100","bbb","200","ccc","300","aaaa","1000","cccc","123456789","bbbb","5000000000", 22"0","zset_zipped","zset","a","1","b","2","c","3", 23} 24} 25 26set server_path [tmpdir "server.rdb-startup-test"] 27 28start_server [list overrides [list "dir" $server_path]] { 29 test {Server started empty with non-existing RDB file} { 30 r debug digest 31 } {0000000000000000000000000000000000000000} 32 # Save an RDB file, needed for the next test. 33 r save 34} 35 36start_server [list overrides [list "dir" $server_path]] { 37 test {Server started empty with empty RDB file} { 38 r debug digest 39 } {0000000000000000000000000000000000000000} 40} 41 42# Helper function to start a server and kill it, just to check the error 43# logged. 44set defaults {} 45proc start_server_and_kill_it {overrides code} { 46 upvar defaults defaults srv srv server_path server_path 47 set config [concat $defaults $overrides] 48 set srv [start_server [list overrides $config]] 49 uplevel 1 $code 50 kill_server $srv 51} 52 53# Make the RDB file unreadable 54file attributes [file join $server_path dump.rdb] -permissions 0222 55 56# Detect root account (it is able to read the file even with 002 perm) 57set isroot 0 58catch { 59 open [file join $server_path dump.rdb] 60 set isroot 1 61} 62 63# Now make sure the server aborted with an error 64if {!$isroot} { 65 start_server_and_kill_it [list "dir" $server_path] { 66 test {Server should not start if RDB file can't be open} { 67 wait_for_condition 50 100 { 68 [string match {*Fatal error loading*} \ 69 [exec tail -n1 < [dict get $srv stdout]]] 70 } else { 71 fail "Server started even if RDB was unreadable!" 72 } 73 } 74 } 75} 76 77# Fix permissions of the RDB file. 78file attributes [file join $server_path dump.rdb] -permissions 0666 79 80# Corrupt its CRC64 checksum. 81set filesize [file size [file join $server_path dump.rdb]] 82set fd [open [file join $server_path dump.rdb] r+] 83fconfigure $fd -translation binary 84seek $fd -8 end 85puts -nonewline $fd "foobar00"; # Corrupt the checksum 86close $fd 87 88# Now make sure the server aborted with an error 89start_server_and_kill_it [list "dir" $server_path] { 90 test {Server should not start if RDB is corrupted} { 91 wait_for_condition 50 100 { 92 [string match {*CRC error*} \ 93 [exec tail -n10 < [dict get $srv stdout]]] 94 } else { 95 fail "Server started even if RDB was corrupted!" 96 } 97 } 98} 99