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
} {
38 test
{Unfinished MULTI
: Server should have logged an
error} {
39 exec cat
[dict get
$srv stdout
] | tail
-n1
40 } {*Unexpected end of
file reading the
append only
file*}
43 ## Test that the server exits when the AOF contains a short read
45 append_to_aof
[formatCommand
set foo hello
]
46 append_to_aof
[string range
[formatCommand
set bar world
] 0 end-1
]
49 start_server_aof
[list dir
$server_path] {
50 test
{Short
read: Server should not have been started
} {
54 test
{Short
read: Server should have logged an
error} {
55 exec cat
[dict get
$srv stdout
] | tail
-n1
56 } {*Bad
file format reading the
append only
file*}
59 ## Test that redis-check-aof indeed sees this AOF is not valid
60 test
{Short
read: Utility should confirm the AOF is not valid
} {
62 exec src
/redis-check-aof
$aof_path
67 test
{Short
read: Utility should be able to fix the AOF
} {
68 exec echo y | src
/redis-check-aof
--fix $aof_path
69 } {*Successfully truncated AOF
*}
71 ## Test that the server can be started using the truncated AOF
72 start_server_aof
[list dir
$server_path] {
73 test
{Fixed AOF
: Server should have been started
} {
77 test
{Fixed AOF
: Keyspace should contain values that were parsable
} {
78 set client
[redis
[dict get
$srv host
] [dict get
$srv port
]]
79 list [$client get foo
] [$client get bar
]