]>
Commit | Line | Data |
---|---|---|
5713f06b | 1 | set defaults { appendonly {yes} appendfilename {appendonly.aof} } |
53cbf66c PN |
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 | |
5713f06b PN |
19 | set config [concat $defaults $overrides] |
20 | set srv [start_server [list overrides $config]] | |
53cbf66c PN |
21 | uplevel 1 $code |
22 | kill_server $srv | |
23 | } | |
24 | ||
7f7499ee PN |
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 | } | |
53cbf66c | 32 | |
7f7499ee PN |
33 | start_server_aof [list dir $server_path] { |
34 | test {Unfinished MULTI: Server should not have been started} { | |
35 | is_alive $srv | |
36 | } {0} | |
53cbf66c | 37 | |
7f7499ee PN |
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 | } | |
53cbf66c | 42 | |
7f7499ee PN |
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 | } | |
53cbf66c | 48 | |
7f7499ee PN |
49 | start_server_aof [list dir $server_path] { |
50 | test {Short read: Server should not have been started} { | |
51 | is_alive $srv | |
52 | } {0} | |
53cbf66c | 53 | |
7f7499ee PN |
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 | } | |
53cbf66c | 58 | |
7f7499ee PN |
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 { | |
e2641e09 | 62 | exec src/redis-check-aof $aof_path |
7f7499ee PN |
63 | } str |
64 | set _ $str | |
65 | } {*not valid*} | |
53cbf66c | 66 | |
7f7499ee | 67 | test {Short read: Utility should be able to fix the AOF} { |
e2641e09 | 68 | exec echo y | src/redis-check-aof --fix $aof_path |
7f7499ee | 69 | } {*Successfully truncated AOF*} |
53cbf66c | 70 | |
7f7499ee PN |
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} | |
53cbf66c | 76 | |
7f7499ee PN |
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 | } | |
53cbf66c | 82 | } |