]> git.saurik.com Git - redis.git/blame - tests/integration/aof.tcl
Sentinel: do not crash against slaves not publishing the runid.
[redis.git] / tests / integration / aof.tcl
CommitLineData
5713f06b 1set defaults { appendonly {yes} appendfilename {appendonly.aof} }
53cbf66c
PN
2set server_path [tmpdir server.aof]
3set aof_path "$server_path/appendonly.aof"
4
5proc append_to_aof {str} {
6 upvar fp fp
7 puts -nonewline $fp $str
8}
9
10proc 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
17proc 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
25tags {"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 have logged an error" {
954cc9d0 35 set pattern "*Unexpected end of file reading the append only file*"
36 set retry 10
37 while {$retry} {
875944a2 38 set result [exec tail -n1 < [dict get $srv stdout]]
954cc9d0 39 if {[string match $pattern $result]} {
40 break
41 }
42 incr retry -1
43 after 1000
44 }
45 if {$retry == 0} {
46 error "assertion:expected error not found on config file"
47 }
d8b6ae3c 48 }
7f7499ee 49 }
53cbf66c 50
7f7499ee
PN
51 ## Test that the server exits when the AOF contains a short read
52 create_aof {
53 append_to_aof [formatCommand set foo hello]
54 append_to_aof [string range [formatCommand set bar world] 0 end-1]
55 }
53cbf66c 56
7f7499ee 57 start_server_aof [list dir $server_path] {
d8b6ae3c 58 test "Short read: Server should have logged an error" {
954cc9d0 59 set pattern "*Bad file format reading the append only file*"
60 set retry 10
61 while {$retry} {
875944a2 62 set result [exec tail -n1 < [dict get $srv stdout]]
954cc9d0 63 if {[string match $pattern $result]} {
64 break
65 }
66 incr retry -1
67 after 1000
68 }
69 if {$retry == 0} {
70 error "assertion:expected error not found on config file"
71 }
d8b6ae3c 72 }
7f7499ee 73 }
53cbf66c 74
7f7499ee 75 ## Test that redis-check-aof indeed sees this AOF is not valid
d8b6ae3c 76 test "Short read: Utility should confirm the AOF is not valid" {
7f7499ee 77 catch {
e2641e09 78 exec src/redis-check-aof $aof_path
d8b6ae3c
PN
79 } result
80 assert_match "*not valid*" $result
81 }
53cbf66c 82
d8b6ae3c 83 test "Short read: Utility should be able to fix the AOF" {
875944a2 84 set result [exec src/redis-check-aof --fix $aof_path << "y\n"]
d8b6ae3c
PN
85 assert_match "*Successfully truncated AOF*" $result
86 }
53cbf66c 87
7f7499ee
PN
88 ## Test that the server can be started using the truncated AOF
89 start_server_aof [list dir $server_path] {
d8b6ae3c
PN
90 test "Fixed AOF: Server should have been started" {
91 assert_equal 1 [is_alive $srv]
92 }
53cbf66c 93
d8b6ae3c 94 test "Fixed AOF: Keyspace should contain values that were parsable" {
7f7499ee 95 set client [redis [dict get $srv host] [dict get $srv port]]
d8b6ae3c
PN
96 assert_equal "hello" [$client get foo]
97 assert_equal "" [$client get bar]
98 }
7f7499ee 99 }
45b0f6fb
PN
100
101 ## Test that SPOP (that modifies the client its argc/argv) is correctly free'd
102 create_aof {
103 append_to_aof [formatCommand sadd set foo]
104 append_to_aof [formatCommand sadd set bar]
105 append_to_aof [formatCommand spop set]
106 }
107
108 start_server_aof [list dir $server_path] {
109 test "AOF+SPOP: Server should have been started" {
110 assert_equal 1 [is_alive $srv]
111 }
112
113 test "AOF+SPOP: Set should have 1 member" {
114 set client [redis [dict get $srv host] [dict get $srv port]]
115 assert_equal 1 [$client scard set]
116 }
117 }
72bae0cc
HW
118
119 ## Test that EXPIREAT is loaded correctly
120 create_aof {
121 append_to_aof [formatCommand rpush list foo]
122 append_to_aof [formatCommand expireat list 1000]
123 append_to_aof [formatCommand rpush list bar]
124 }
125
126 start_server_aof [list dir $server_path] {
127 test "AOF+EXPIRE: Server should have been started" {
128 assert_equal 1 [is_alive $srv]
129 }
130
131 test "AOF+EXPIRE: List should be empty" {
132 set client [redis [dict get $srv host] [dict get $srv port]]
133 assert_equal 0 [$client llen list]
134 }
135 }
5521fa6a 136
137 start_server {overrides {appendonly {yes} appendfilename {appendonly.aof}}} {
138 test {Redis should not try to convert DEL into EXPIREAT for EXPIRE -1} {
139 r set x 10
140 r expire x -1
141 }
142 }
53cbf66c 143}