]>
Commit | Line | Data |
---|---|---|
1 | set defaults [list [list appendonly yes] [list appendfilename appendonly.aof]] | |
2 | set server_path [tmpdir server.aof] | |
3 | set aof_path "$server_path/appendonly.aof" | |
4 | ||
5 | proc append_to_aof {str} { | |
6 | upvar fp fp | |
7 | puts -nonewline $fp $str | |
8 | } | |
9 | ||
10 | proc create_aof {code} { | |
11 | upvar fp fp aof_path aof_path | |
12 | set fp [open $aof_path w+] | |
13 | uplevel 1 $code | |
14 | close $fp | |
15 | } | |
16 | ||
17 | proc start_server_aof {overrides code} { | |
18 | upvar defaults defaults srv srv server_path server_path | |
19 | set _defaults $defaults | |
20 | set srv [start_server {overrides [lappend _defaults $overrides]}] | |
21 | uplevel 1 $code | |
22 | kill_server $srv | |
23 | } | |
24 | ||
25 | tags {"aof"} { | |
26 | ## Test the server doesn't start when the AOF contains an unfinished MULTI | |
27 | create_aof { | |
28 | append_to_aof [formatCommand set foo hello] | |
29 | append_to_aof [formatCommand multi] | |
30 | append_to_aof [formatCommand set bar world] | |
31 | } | |
32 | ||
33 | start_server_aof [list dir $server_path] { | |
34 | test {Unfinished MULTI: Server should not have been started} { | |
35 | is_alive $srv | |
36 | } {0} | |
37 | ||
38 | test {Unfinished MULTI: Server should have logged an error} { | |
39 | exec cat [dict get $srv stdout] | tail -n1 | |
40 | } {*Unexpected end of file reading the append only file*} | |
41 | } | |
42 | ||
43 | ## Test that the server exits when the AOF contains a short read | |
44 | create_aof { | |
45 | append_to_aof [formatCommand set foo hello] | |
46 | append_to_aof [string range [formatCommand set bar world] 0 end-1] | |
47 | } | |
48 | ||
49 | start_server_aof [list dir $server_path] { | |
50 | test {Short read: Server should not have been started} { | |
51 | is_alive $srv | |
52 | } {0} | |
53 | ||
54 | test {Short read: Server should have logged an error} { | |
55 | exec cat [dict get $srv stdout] | tail -n1 | |
56 | } {*Bad file format reading the append only file*} | |
57 | } | |
58 | ||
59 | ## Test that redis-check-aof indeed sees this AOF is not valid | |
60 | test {Short read: Utility should confirm the AOF is not valid} { | |
61 | catch { | |
62 | exec ./redis-check-aof $aof_path | |
63 | } str | |
64 | set _ $str | |
65 | } {*not valid*} | |
66 | ||
67 | test {Short read: Utility should be able to fix the AOF} { | |
68 | exec echo y | ./redis-check-aof --fix $aof_path | |
69 | } {*Successfully truncated AOF*} | |
70 | ||
71 | ## Test that the server can be started using the truncated AOF | |
72 | start_server_aof [list dir $server_path] { | |
73 | test {Fixed AOF: Server should have been started} { | |
74 | is_alive $srv | |
75 | } {1} | |
76 | ||
77 | test {Fixed AOF: Keyspace should contain values that were parsable} { | |
78 | set client [redis [dict get $srv host] [dict get $srv port]] | |
79 | list [$client get foo] [$client get bar] | |
80 | } {hello {}} | |
81 | } | |
82 | } |