1 set defaults
[list [list appendonly yes
] [list 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 _defaults
$defaults
20 set srv
[start_server
default.conf
[lappend _defaults
$overrides]]
25 ## Test the server doesn't start when the AOF contains an unfinished MULTI
27 append_to_aof
[formatCommand
set foo hello
]
28 append_to_aof
[formatCommand multi
]
29 append_to_aof
[formatCommand
set bar world
]
32 start_server_aof
[list dir
$server_path] {
33 test
{Unfinished MULTI
: Server should not have been started
} {
37 test
{Unfinished MULTI
: Server should have logged an
error} {
38 exec cat
[dict get
$srv stdout
] | tail
-n1
39 } {*Unexpected end of
file reading the
append only
file*}
42 ## Test that the server exits when the AOF contains a short read
44 append_to_aof
[formatCommand
set foo hello
]
45 append_to_aof
[string range
[formatCommand
set bar world
] 0 end-1
]
48 start_server_aof
[list dir
$server_path] {
49 test
{Short
read: Server should not have been started
} {
53 test
{Short
read: Server should have logged an
error} {
54 exec cat
[dict get
$srv stdout
] | tail
-n1
55 } {*Bad
file format reading the
append only
file*}
58 ## Test that redis-check-aof indeed sees this AOF is not valid
59 test
{Short
read: Utility should confirm the AOF is not valid
} {
61 exec .
/redis-check-aof
$aof_path
66 test
{Short
read: Utility should be able to fix the AOF
} {
67 exec echo y | .
/redis-check-aof
--fix $aof_path
68 } {*Successfully truncated AOF
*}
70 ## Test that the server can be started using the truncated AOF
71 start_server_aof
[list dir
$server_path] {
72 test
{Fixed AOF
: Server should have been started
} {
76 test
{Fixed AOF
: Keyspace should contain values that were parsable
} {
77 set client
[redis
[dict get
$srv host
] [dict get
$srv port
]]
78 list [$client get foo
] [$client get bar
]