]>
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 | 34 | test "Unfinished MULTI: Server should not have been started" { |
4c378d7f | 35 | if {$::valgrind} {after 2000} |
d8b6ae3c PN |
36 | assert_equal 0 [is_alive $srv] |
37 | } | |
53cbf66c | 38 | |
d8b6ae3c PN |
39 | test "Unfinished MULTI: Server should have logged an error" { |
40 | set result [exec cat [dict get $srv stdout] | tail -n1] | |
41 | assert_match "*Unexpected end of file reading the append only file*" $result | |
42 | } | |
7f7499ee | 43 | } |
53cbf66c | 44 | |
7f7499ee PN |
45 | ## Test that the server exits when the AOF contains a short read |
46 | create_aof { | |
47 | append_to_aof [formatCommand set foo hello] | |
48 | append_to_aof [string range [formatCommand set bar world] 0 end-1] | |
49 | } | |
53cbf66c | 50 | |
7f7499ee | 51 | start_server_aof [list dir $server_path] { |
d8b6ae3c | 52 | test "Short read: Server should not have been started" { |
4c378d7f | 53 | if {$::valgrind} {after 2000} |
d8b6ae3c PN |
54 | assert_equal 0 [is_alive $srv] |
55 | } | |
53cbf66c | 56 | |
d8b6ae3c PN |
57 | test "Short read: Server should have logged an error" { |
58 | set result [exec cat [dict get $srv stdout] | tail -n1] | |
59 | assert_match "*Bad file format reading the append only file*" $result | |
60 | } | |
7f7499ee | 61 | } |
53cbf66c | 62 | |
7f7499ee | 63 | ## Test that redis-check-aof indeed sees this AOF is not valid |
d8b6ae3c | 64 | test "Short read: Utility should confirm the AOF is not valid" { |
7f7499ee | 65 | catch { |
e2641e09 | 66 | exec src/redis-check-aof $aof_path |
d8b6ae3c PN |
67 | } result |
68 | assert_match "*not valid*" $result | |
69 | } | |
53cbf66c | 70 | |
d8b6ae3c PN |
71 | test "Short read: Utility should be able to fix the AOF" { |
72 | set result [exec echo y | src/redis-check-aof --fix $aof_path] | |
73 | assert_match "*Successfully truncated AOF*" $result | |
74 | } | |
53cbf66c | 75 | |
7f7499ee PN |
76 | ## Test that the server can be started using the truncated AOF |
77 | start_server_aof [list dir $server_path] { | |
d8b6ae3c PN |
78 | test "Fixed AOF: Server should have been started" { |
79 | assert_equal 1 [is_alive $srv] | |
80 | } | |
53cbf66c | 81 | |
d8b6ae3c | 82 | test "Fixed AOF: Keyspace should contain values that were parsable" { |
7f7499ee | 83 | set client [redis [dict get $srv host] [dict get $srv port]] |
d8b6ae3c PN |
84 | assert_equal "hello" [$client get foo] |
85 | assert_equal "" [$client get bar] | |
86 | } | |
7f7499ee | 87 | } |
45b0f6fb PN |
88 | |
89 | ## Test that SPOP (that modifies the client its argc/argv) is correctly free'd | |
90 | create_aof { | |
91 | append_to_aof [formatCommand sadd set foo] | |
92 | append_to_aof [formatCommand sadd set bar] | |
93 | append_to_aof [formatCommand spop set] | |
94 | } | |
95 | ||
96 | start_server_aof [list dir $server_path] { | |
97 | test "AOF+SPOP: Server should have been started" { | |
98 | assert_equal 1 [is_alive $srv] | |
99 | } | |
100 | ||
101 | test "AOF+SPOP: Set should have 1 member" { | |
102 | set client [redis [dict get $srv host] [dict get $srv port]] | |
103 | assert_equal 1 [$client scard set] | |
104 | } | |
105 | } | |
72bae0cc HW |
106 | |
107 | ## Test that EXPIREAT is loaded correctly | |
108 | create_aof { | |
109 | append_to_aof [formatCommand rpush list foo] | |
110 | append_to_aof [formatCommand expireat list 1000] | |
111 | append_to_aof [formatCommand rpush list bar] | |
112 | } | |
113 | ||
114 | start_server_aof [list dir $server_path] { | |
115 | test "AOF+EXPIRE: Server should have been started" { | |
116 | assert_equal 1 [is_alive $srv] | |
117 | } | |
118 | ||
119 | test "AOF+EXPIRE: List should be empty" { | |
120 | set client [redis [dict get $srv host] [dict get $srv port]] | |
121 | assert_equal 0 [$client llen list] | |
122 | } | |
123 | } | |
5521fa6a | 124 | |
125 | start_server {overrides {appendonly {yes} appendfilename {appendonly.aof}}} { | |
126 | test {Redis should not try to convert DEL into EXPIREAT for EXPIRE -1} { | |
127 | r set x 10 | |
128 | r expire x -1 | |
129 | } | |
130 | } | |
53cbf66c | 131 | } |