]>
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 | 33 | start_server_aof [list dir $server_path] { |
d8b6ae3c PN |
34 | test "Unfinished MULTI: Server should not have been started" { |
35 | assert_equal 0 [is_alive $srv] | |
36 | } | |
53cbf66c | 37 | |
d8b6ae3c PN |
38 | test "Unfinished MULTI: Server should have logged an error" { |
39 | set result [exec cat [dict get $srv stdout] | tail -n1] | |
40 | assert_match "*Unexpected end of file reading the append only file*" $result | |
41 | } | |
7f7499ee | 42 | } |
53cbf66c | 43 | |
7f7499ee PN |
44 | ## Test that the server exits when the AOF contains a short read |
45 | create_aof { | |
46 | append_to_aof [formatCommand set foo hello] | |
47 | append_to_aof [string range [formatCommand set bar world] 0 end-1] | |
48 | } | |
53cbf66c | 49 | |
7f7499ee | 50 | start_server_aof [list dir $server_path] { |
d8b6ae3c PN |
51 | test "Short read: Server should not have been started" { |
52 | assert_equal 0 [is_alive $srv] | |
53 | } | |
53cbf66c | 54 | |
d8b6ae3c PN |
55 | test "Short read: Server should have logged an error" { |
56 | set result [exec cat [dict get $srv stdout] | tail -n1] | |
57 | assert_match "*Bad file format reading the append only file*" $result | |
58 | } | |
7f7499ee | 59 | } |
53cbf66c | 60 | |
7f7499ee | 61 | ## Test that redis-check-aof indeed sees this AOF is not valid |
d8b6ae3c | 62 | test "Short read: Utility should confirm the AOF is not valid" { |
7f7499ee | 63 | catch { |
e2641e09 | 64 | exec src/redis-check-aof $aof_path |
d8b6ae3c PN |
65 | } result |
66 | assert_match "*not valid*" $result | |
67 | } | |
53cbf66c | 68 | |
d8b6ae3c PN |
69 | test "Short read: Utility should be able to fix the AOF" { |
70 | set result [exec echo y | src/redis-check-aof --fix $aof_path] | |
71 | assert_match "*Successfully truncated AOF*" $result | |
72 | } | |
53cbf66c | 73 | |
7f7499ee PN |
74 | ## Test that the server can be started using the truncated AOF |
75 | start_server_aof [list dir $server_path] { | |
d8b6ae3c PN |
76 | test "Fixed AOF: Server should have been started" { |
77 | assert_equal 1 [is_alive $srv] | |
78 | } | |
53cbf66c | 79 | |
d8b6ae3c | 80 | test "Fixed AOF: Keyspace should contain values that were parsable" { |
7f7499ee | 81 | set client [redis [dict get $srv host] [dict get $srv port]] |
d8b6ae3c PN |
82 | assert_equal "hello" [$client get foo] |
83 | assert_equal "" [$client get bar] | |
84 | } | |
7f7499ee | 85 | } |
45b0f6fb PN |
86 | |
87 | ## Test that SPOP (that modifies the client its argc/argv) is correctly free'd | |
88 | create_aof { | |
89 | append_to_aof [formatCommand sadd set foo] | |
90 | append_to_aof [formatCommand sadd set bar] | |
91 | append_to_aof [formatCommand spop set] | |
92 | } | |
93 | ||
94 | start_server_aof [list dir $server_path] { | |
95 | test "AOF+SPOP: Server should have been started" { | |
96 | assert_equal 1 [is_alive $srv] | |
97 | } | |
98 | ||
99 | test "AOF+SPOP: Set should have 1 member" { | |
100 | set client [redis [dict get $srv host] [dict get $srv port]] | |
101 | assert_equal 1 [$client scard set] | |
102 | } | |
103 | } | |
53cbf66c | 104 | } |