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