Added tests for saving various data types to disk and loading them back, and for loading data types from redis to maintain compatibility
Former-commit-id: dcb44d3a09a4021f05079bedbac690e33ec7f39e
This commit is contained in:
parent
6c16fe69e7
commit
54b36868ba
BIN
tests/assets/redis-save.rdb
Normal file
BIN
tests/assets/redis-save.rdb
Normal file
Binary file not shown.
@ -76,6 +76,7 @@ set ::all_tests {
|
||||
unit/tls
|
||||
unit/tracking
|
||||
unit/oom-score-adj
|
||||
unit/loadsave
|
||||
}
|
||||
# Index to the next test to run in the ::all_tests list.
|
||||
set ::next_test 0
|
||||
|
50
tests/unit/loadsave.tcl
Normal file
50
tests/unit/loadsave.tcl
Normal file
@ -0,0 +1,50 @@
|
||||
set server_path [tmpdir "server.rdb-encoding-test"]
|
||||
set testmodule [file normalize tests/modules/datatype.so]
|
||||
|
||||
# Store a bunch of datatypes to the database,
|
||||
# compute the hash of the database,
|
||||
# and save the data to a file
|
||||
start_server [list tags [list "loadsave"] overrides [list "dir" $server_path "loadmodule" $testmodule] keep_persistence true] {
|
||||
|
||||
test "Save various data types to .rdb file" {
|
||||
r set "int" [expr {int(rand()*10000)}]
|
||||
r set "string" [string repeat A [expr {int(rand()*10000)}]]
|
||||
r hset "hash" [string repeat A [expr {int(rand()*1000)}]] 0[string repeat A [expr {int(rand()*1000)}]]
|
||||
r sadd "set" [string repeat A [expr {int(rand()*1000)}]]
|
||||
r zadd "zset" [expr {rand()}] [string repeat A [expr {int(rand()*1000)}]]
|
||||
r lpush "list" [string repeat A [expr {int(rand()*1000)}]]
|
||||
r datatype.set dtkey 100 stringval
|
||||
r keydb.cron "cron" single [expr {10000 + int(rand()*1000)}] "return 0" 0;# set delay long enough so it doesn't contend with saving
|
||||
set saved_digest [r debug digest];# debug digest computes the hash
|
||||
r save
|
||||
} {OK};
|
||||
}
|
||||
|
||||
# Load that data back from the file,
|
||||
# and compare its hash to the previously computed hash
|
||||
start_server [list tags [list "loadsave"] overrides [list "dir" $server_path "loadmodule" $testmodule] keep_persistence true] {
|
||||
test "Load various data types from .rdb file" {
|
||||
set loaded_digest [r debug digest]
|
||||
if {![string match $saved_digest $loaded_digest]} {
|
||||
fail "Loaded data did not match saved data"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Load in data from a redis instance
|
||||
# The hash should match what we get in redis
|
||||
set saved_digest 26ce4a819a86355af7ec75c7a3410f5b9fad02f3
|
||||
exec cp -f tests/assets/redis-save.rdb $server_path/dump.rdb
|
||||
|
||||
start_server [list tags [list "loadsave"] overrides [list "dir" $server_path "loadmodule" $testmodule] keep_persistence true] {
|
||||
test "Load various data types from Redis generated .rdb file" {
|
||||
set loaded_digest [r debug digest]
|
||||
if {![string match $saved_digest $loaded_digest]} {
|
||||
fail "Loaded data did not match saved data"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
puts $server_path
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user