2012-03-23 10:22:25 -04:00
|
|
|
set server_path [tmpdir "server.rdb-encoding-test"]
|
|
|
|
|
2012-03-23 15:20:43 -04:00
|
|
|
# Copy RDB with different encodings in server path
|
2012-03-23 10:22:25 -04:00
|
|
|
exec cp tests/assets/encodings.rdb $server_path
|
|
|
|
|
|
|
|
start_server [list overrides [list "dir" $server_path "dbfilename" "encodings.rdb"]] {
|
|
|
|
test "RDB encoding loading test" {
|
|
|
|
r select 0
|
|
|
|
csvdump r
|
2015-08-05 08:05:34 -04:00
|
|
|
} {"0","compressible","string","aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
|
|
"0","hash","hash","a","1","aa","10","aaa","100","b","2","bb","20","bbb","200","c","3","cc","30","ccc","300","ddd","400","eee","5000000000",
|
|
|
|
"0","hash_zipped","hash","a","1","b","2","c","3",
|
|
|
|
"0","list","list","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000","1","2","3","a","b","c","100000","6000000000",
|
|
|
|
"0","list_zipped","list","1","2","3","a","b","c","100000","6000000000",
|
|
|
|
"0","number","string","10"
|
|
|
|
"0","set","set","1","100000","2","3","6000000000","a","b","c",
|
|
|
|
"0","set_zipped_1","set","1","2","3","4",
|
|
|
|
"0","set_zipped_2","set","100000","200000","300000","400000",
|
|
|
|
"0","set_zipped_3","set","1000000000","2000000000","3000000000","4000000000","5000000000","6000000000",
|
|
|
|
"0","string","string","Hello World"
|
|
|
|
"0","zset","zset","a","1","b","2","c","3","aa","10","bb","20","cc","30","aaa","100","bbb","200","ccc","300","aaaa","1000","cccc","123456789","bbbb","5000000000",
|
|
|
|
"0","zset_zipped","zset","a","1","b","2","c","3",
|
2012-03-23 10:22:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 14:55:33 -04:00
|
|
|
set server_path [tmpdir "server.rdb-startup-test"]
|
|
|
|
|
|
|
|
start_server [list overrides [list "dir" $server_path]] {
|
|
|
|
test {Server started empty with non-existing RDB file} {
|
|
|
|
r debug digest
|
|
|
|
} {0000000000000000000000000000000000000000}
|
2013-03-13 05:04:33 -04:00
|
|
|
# Save an RDB file, needed for the next test.
|
|
|
|
r save
|
|
|
|
}
|
|
|
|
|
|
|
|
start_server [list overrides [list "dir" $server_path]] {
|
|
|
|
test {Server started empty with empty RDB file} {
|
|
|
|
r debug digest
|
|
|
|
} {0000000000000000000000000000000000000000}
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:29:15 -04:00
|
|
|
start_server [list overrides [list "dir" $server_path]] {
|
|
|
|
test {Test RDB stream encoding} {
|
|
|
|
for {set j 0} {$j < 1000} {incr j} {
|
|
|
|
if {rand() < 0.9} {
|
|
|
|
r xadd stream * foo $j
|
|
|
|
} else {
|
|
|
|
r xadd stream * bar $j
|
|
|
|
}
|
|
|
|
}
|
2018-06-27 08:32:18 -04:00
|
|
|
r xgroup create stream mygroup 0
|
2018-06-26 07:14:35 -04:00
|
|
|
r xreadgroup GROUP mygroup Alice COUNT 1 STREAMS stream >
|
2018-06-19 10:29:15 -04:00
|
|
|
set digest [r debug digest]
|
|
|
|
r debug reload
|
|
|
|
set newdigest [r debug digest]
|
|
|
|
assert {$digest eq $newdigest}
|
|
|
|
r del stream
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 05:04:33 -04:00
|
|
|
# Helper function to start a server and kill it, just to check the error
|
|
|
|
# logged.
|
|
|
|
set defaults {}
|
|
|
|
proc start_server_and_kill_it {overrides code} {
|
|
|
|
upvar defaults defaults srv srv server_path server_path
|
|
|
|
set config [concat $defaults $overrides]
|
|
|
|
set srv [start_server [list overrides $config]]
|
|
|
|
uplevel 1 $code
|
|
|
|
kill_server $srv
|
|
|
|
}
|
|
|
|
|
|
|
|
# Make the RDB file unreadable
|
|
|
|
file attributes [file join $server_path dump.rdb] -permissions 0222
|
|
|
|
|
2013-04-23 08:08:42 -04:00
|
|
|
# Detect root account (it is able to read the file even with 002 perm)
|
|
|
|
set isroot 0
|
|
|
|
catch {
|
|
|
|
open [file join $server_path dump.rdb]
|
|
|
|
set isroot 1
|
|
|
|
}
|
|
|
|
|
2013-03-13 05:04:33 -04:00
|
|
|
# Now make sure the server aborted with an error
|
2013-04-23 08:08:42 -04:00
|
|
|
if {!$isroot} {
|
|
|
|
start_server_and_kill_it [list "dir" $server_path] {
|
|
|
|
test {Server should not start if RDB file can't be open} {
|
|
|
|
wait_for_condition 50 100 {
|
|
|
|
[string match {*Fatal error loading*} \
|
2017-02-22 07:08:21 -05:00
|
|
|
[exec tail -1 < [dict get $srv stdout]]]
|
2013-04-23 08:08:42 -04:00
|
|
|
} else {
|
|
|
|
fail "Server started even if RDB was unreadable!"
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 05:04:33 -04:00
|
|
|
}
|
2013-03-12 14:55:33 -04:00
|
|
|
}
|
2013-03-13 06:12:45 -04:00
|
|
|
|
2013-04-22 05:25:44 -04:00
|
|
|
# Fix permissions of the RDB file.
|
2013-03-13 06:12:45 -04:00
|
|
|
file attributes [file join $server_path dump.rdb] -permissions 0666
|
2013-04-22 05:25:44 -04:00
|
|
|
|
|
|
|
# Corrupt its CRC64 checksum.
|
2013-03-13 06:12:45 -04:00
|
|
|
set filesize [file size [file join $server_path dump.rdb]]
|
|
|
|
set fd [open [file join $server_path dump.rdb] r+]
|
|
|
|
fconfigure $fd -translation binary
|
|
|
|
seek $fd -8 end
|
|
|
|
puts -nonewline $fd "foobar00"; # Corrupt the checksum
|
|
|
|
close $fd
|
|
|
|
|
|
|
|
# Now make sure the server aborted with an error
|
|
|
|
start_server_and_kill_it [list "dir" $server_path] {
|
2013-04-23 08:08:42 -04:00
|
|
|
test {Server should not start if RDB is corrupted} {
|
|
|
|
wait_for_condition 50 100 {
|
2016-07-04 06:41:25 -04:00
|
|
|
[string match {*CRC error*} \
|
2017-02-22 07:08:21 -05:00
|
|
|
[exec tail -10 < [dict get $srv stdout]]]
|
2013-04-23 08:08:42 -04:00
|
|
|
} else {
|
|
|
|
fail "Server started even if RDB was corrupted!"
|
|
|
|
}
|
2013-03-13 06:12:45 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-26 08:16:34 -04:00
|
|
|
|
|
|
|
start_server {} {
|
|
|
|
test {Test FLUSHALL aborts bgsave} {
|
2020-07-23 06:06:24 -04:00
|
|
|
# 1000 keys with 1ms sleep per key shuld take 1 second
|
2019-09-26 08:16:34 -04:00
|
|
|
r config set rdb-key-save-delay 1000
|
|
|
|
r debug populate 1000
|
|
|
|
r bgsave
|
|
|
|
assert_equal [s rdb_bgsave_in_progress] 1
|
|
|
|
r flushall
|
2020-07-23 06:06:24 -04:00
|
|
|
# wait half a second max
|
|
|
|
wait_for_condition 5 100 {
|
|
|
|
[s rdb_bgsave_in_progress] == 0
|
|
|
|
} else {
|
|
|
|
fail "bgsave not aborted"
|
|
|
|
}
|
|
|
|
# veirfy that bgsave failed, by checking that the change counter is still high
|
|
|
|
assert_lessthan 999 [s rdb_changes_since_last_save]
|
2019-09-26 08:16:34 -04:00
|
|
|
# make sure the server is still writable
|
|
|
|
r set x xx
|
|
|
|
}
|
2020-07-23 06:06:24 -04:00
|
|
|
|
|
|
|
test {bgsave resets the change counter} {
|
|
|
|
r config set rdb-key-save-delay 0
|
|
|
|
r bgsave
|
|
|
|
wait_for_condition 5 100 {
|
|
|
|
[s rdb_bgsave_in_progress] == 0
|
|
|
|
} else {
|
|
|
|
fail "bgsave not aborted"
|
|
|
|
}
|
|
|
|
assert_equal [s rdb_changes_since_last_save] 0
|
|
|
|
}
|
2020-05-10 12:13:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
test {client freed during loading} {
|
|
|
|
start_server [list overrides [list key-load-delay 10 rdbcompression no]] {
|
|
|
|
# create a big rdb that will take long to load. it is important
|
|
|
|
# for keys to be big since the server processes events only once in 2mb.
|
|
|
|
# 100mb of rdb, 100k keys will load in more than 1 second
|
|
|
|
r debug populate 100000 key 1000
|
|
|
|
|
tests/valgrind: don't use debug restart (#7404)
* tests/valgrind: don't use debug restart
DEBUG REATART causes two issues:
1. it uses execve which replaces the original process and valgrind doesn't
have a chance to check for errors, so leaks go unreported.
2. valgrind report invalid calls to close() which we're unable to resolve.
So now the tests use restart_server mechanism in the tests, that terminates
the old server and starts a new one, new PID, but same stdout, stderr.
since the stderr can contain two or more valgrind report, it is not enough
to just check for the absence of leaks, we also need to check for some known
errors, we do both, and fail if we either find an error, or can't find a
report saying there are no leaks.
other changes:
- when killing a server that was already terminated we check for leaks too.
- adding DEBUG LEAK which was used to test it.
- adding --trace-children to valgrind, although no longer needed.
- since the stdout contains two or more runs, we need slightly different way
of checking if the new process is up (explicitly looking for the new PID)
- move the code that handles --wait-server to happen earlier (before
watching the startup message in the log), and serve the restarted server too.
* squashme - CR fixes
2020-07-10 01:26:52 -04:00
|
|
|
restart_server 0 false
|
2020-05-10 12:13:47 -04:00
|
|
|
|
|
|
|
# make sure it's still loading
|
|
|
|
assert_equal [s loading] 1
|
|
|
|
|
|
|
|
# connect and disconnect 10 clients
|
|
|
|
set clients {}
|
|
|
|
for {set j 0} {$j < 10} {incr j} {
|
|
|
|
lappend clients [redis_deferring_client]
|
|
|
|
}
|
|
|
|
foreach rd $clients {
|
|
|
|
$rd debug log bla
|
|
|
|
}
|
|
|
|
foreach rd $clients {
|
|
|
|
$rd read
|
|
|
|
}
|
|
|
|
foreach rd $clients {
|
|
|
|
$rd close
|
|
|
|
}
|
|
|
|
|
|
|
|
# make sure the server freed the clients
|
|
|
|
wait_for_condition 100 100 {
|
|
|
|
[s connected_clients] < 3
|
|
|
|
} else {
|
|
|
|
fail "clients didn't disconnect"
|
|
|
|
}
|
|
|
|
|
|
|
|
# make sure it's still loading
|
|
|
|
assert_equal [s loading] 1
|
|
|
|
|
|
|
|
# no need to keep waiting for loading to complete
|
|
|
|
exec kill [srv 0 pid]
|
|
|
|
}
|
tests/valgrind: don't use debug restart (#7404)
* tests/valgrind: don't use debug restart
DEBUG REATART causes two issues:
1. it uses execve which replaces the original process and valgrind doesn't
have a chance to check for errors, so leaks go unreported.
2. valgrind report invalid calls to close() which we're unable to resolve.
So now the tests use restart_server mechanism in the tests, that terminates
the old server and starts a new one, new PID, but same stdout, stderr.
since the stderr can contain two or more valgrind report, it is not enough
to just check for the absence of leaks, we also need to check for some known
errors, we do both, and fail if we either find an error, or can't find a
report saying there are no leaks.
other changes:
- when killing a server that was already terminated we check for leaks too.
- adding DEBUG LEAK which was used to test it.
- adding --trace-children to valgrind, although no longer needed.
- since the stdout contains two or more runs, we need slightly different way
of checking if the new process is up (explicitly looking for the new PID)
- move the code that handles --wait-server to happen earlier (before
watching the startup message in the log), and serve the restarted server too.
* squashme - CR fixes
2020-07-10 01:26:52 -04:00
|
|
|
}
|