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