1 set defaults
{ appendonly
{yes
} appendfilename
{appendonly.aof
} }
2 set server_path
[tmpdir server.aof
]
3 set aof_path
"$server_path/appendonly.aof"
5 proc append_to_aof
{str
} {
7 puts -nonewline $fp $str
10 proc create_aof
{code
} {
11 upvar fp fp aof_path aof_path
12 set fp
[open $aof_path w
+]
17 proc start_server_aof
{overrides code
} {
18 upvar defaults defaults srv srv server_path server_path
19 set config
[concat $defaults $overrides]
20 set srv
[start_server
[list overrides
$config]]
26 ## Test the server doesn't start when the AOF contains an unfinished MULTI
28 append_to_aof
[formatCommand
set foo hello
]
29 append_to_aof
[formatCommand multi
]
30 append_to_aof
[formatCommand
set bar world
]
33 start_server_aof
[list dir
$server_path] {
34 test
"Unfinished MULTI: Server should not have been started" {
35 if {$::valgrind} {after 2000}
36 assert_equal
0 [is_alive
$srv]
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
45 ## Test that the server exits when the AOF contains a short read
47 append_to_aof
[formatCommand
set foo hello
]
48 append_to_aof
[string range
[formatCommand
set bar world
] 0 end-1
]
51 start_server_aof
[list dir
$server_path] {
52 test
"Short read: Server should not have been started" {
53 if {$::valgrind} {after 2000}
54 assert_equal
0 [is_alive
$srv]
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
63 ## Test that redis-check-aof indeed sees this AOF is not valid
64 test
"Short read: Utility should confirm the AOF is not valid" {
66 exec src
/redis-check-aof
$aof_path
68 assert_match
"*not valid*" $result
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
76 ## Test that the server can be started using the truncated AOF
77 start_server_aof
[list dir
$server_path] {
78 test
"Fixed AOF: Server should have been started" {
79 assert_equal
1 [is_alive
$srv]
82 test
"Fixed AOF: Keyspace should contain values that were parsable" {
83 set client
[redis
[dict get
$srv host
] [dict get
$srv port
]]
84 assert_equal
"hello" [$client get foo
]
85 assert_equal
"" [$client get bar
]
89 ## Test that SPOP (that modifies the client its argc/argv) is correctly free'd
91 append_to_aof
[formatCommand sadd
set foo
]
92 append_to_aof
[formatCommand sadd
set bar
]
93 append_to_aof
[formatCommand spop
set]
96 start_server_aof
[list dir
$server_path] {
97 test
"AOF+SPOP: Server should have been started" {
98 assert_equal
1 [is_alive
$srv]
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]
107 ## Test that EXPIREAT is loaded correctly
109 append_to_aof
[formatCommand rpush
list foo
]
110 append_to_aof
[formatCommand expireat
list 1000]
111 append_to_aof
[formatCommand rpush
list bar
]
114 start_server_aof
[list dir
$server_path] {
115 test
"AOF+EXPIRE: Server should have been started" {
116 assert_equal
1 [is_alive
$srv]
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]
125 start_server
{overrides
{appendonly
{yes
} appendfilename
{appendonly.aof
}}} {
126 test
{Redis should not try to convert DEL into EXPIREAT
for EXPIRE
-1} {