Commit 7f7499ee authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

tags for existing tests

parent 73bd6c58
...@@ -22,59 +22,61 @@ proc start_server_aof {overrides code} { ...@@ -22,59 +22,61 @@ proc start_server_aof {overrides code} {
kill_server $srv kill_server $srv
} }
## Test the server doesn't start when the AOF contains an unfinished MULTI tags {"aof"} {
create_aof { ## Test the server doesn't start when the AOF contains an unfinished MULTI
append_to_aof [formatCommand set foo hello] create_aof {
append_to_aof [formatCommand multi] append_to_aof [formatCommand set foo hello]
append_to_aof [formatCommand set bar world] append_to_aof [formatCommand multi]
} append_to_aof [formatCommand set bar world]
}
start_server_aof [list dir $server_path] { start_server_aof [list dir $server_path] {
test {Unfinished MULTI: Server should not have been started} { test {Unfinished MULTI: Server should not have been started} {
is_alive $srv is_alive $srv
} {0} } {0}
test {Unfinished MULTI: Server should have logged an error} { test {Unfinished MULTI: Server should have logged an error} {
exec cat [dict get $srv stdout] | tail -n1 exec cat [dict get $srv stdout] | tail -n1
} {*Unexpected end of file reading the append only file*} } {*Unexpected end of file reading the append only file*}
} }
## Test that the server exits when the AOF contains a short read ## Test that the server exits when the AOF contains a short read
create_aof { create_aof {
append_to_aof [formatCommand set foo hello] append_to_aof [formatCommand set foo hello]
append_to_aof [string range [formatCommand set bar world] 0 end-1] append_to_aof [string range [formatCommand set bar world] 0 end-1]
} }
start_server_aof [list dir $server_path] { start_server_aof [list dir $server_path] {
test {Short read: Server should not have been started} { test {Short read: Server should not have been started} {
is_alive $srv is_alive $srv
} {0} } {0}
test {Short read: Server should have logged an error} { test {Short read: Server should have logged an error} {
exec cat [dict get $srv stdout] | tail -n1 exec cat [dict get $srv stdout] | tail -n1
} {*Bad file format reading the append only file*} } {*Bad file format reading the append only file*}
} }
## Test that redis-check-aof indeed sees this AOF is not valid ## Test that redis-check-aof indeed sees this AOF is not valid
test {Short read: Utility should confirm the AOF is not valid} { test {Short read: Utility should confirm the AOF is not valid} {
catch { catch {
exec ./redis-check-aof $aof_path exec ./redis-check-aof $aof_path
} str } str
set _ $str set _ $str
} {*not valid*} } {*not valid*}
test {Short read: Utility should be able to fix the AOF} { test {Short read: Utility should be able to fix the AOF} {
exec echo y | ./redis-check-aof --fix $aof_path exec echo y | ./redis-check-aof --fix $aof_path
} {*Successfully truncated AOF*} } {*Successfully truncated AOF*}
## Test that the server can be started using the truncated AOF ## Test that the server can be started using the truncated AOF
start_server_aof [list dir $server_path] { start_server_aof [list dir $server_path] {
test {Fixed AOF: Server should have been started} { test {Fixed AOF: Server should have been started} {
is_alive $srv is_alive $srv
} {1} } {1}
test {Fixed AOF: Keyspace should contain values that were parsable} { test {Fixed AOF: Keyspace should contain values that were parsable} {
set client [redis [dict get $srv host] [dict get $srv port]] set client [redis [dict get $srv host] [dict get $srv port]]
list [$client get foo] [$client get bar] list [$client get foo] [$client get bar]
} {hello {}} } {hello {}}
}
} }
start_server {} { start_server {tags {"repl"}} {
r set mykey foo r set mykey foo
start_server {} { start_server {} {
......
start_server {overrides {requirepass foobar}} { start_server {tags {"auth"} overrides {requirepass foobar}} {
test {AUTH fails when a wrong password is given} { test {AUTH fails when a wrong password is given} {
catch {r auth wrong!} err catch {r auth wrong!} err
format $err format $err
......
start_server {tags {basic}} { start_server {tags {"basic"}} {
test {DEL all keys to start with a clean DB} { test {DEL all keys to start with a clean DB} {
foreach key [r keys *] {r del $key} foreach key [r keys *] {r del $key}
r dbsize r dbsize
...@@ -52,47 +52,47 @@ start_server {tags {basic}} { ...@@ -52,47 +52,47 @@ start_server {tags {basic}} {
r get foo r get foo
} [string repeat "abcd" 1000000] } [string repeat "abcd" 1000000]
tags {slow} { tags {"slow"} {
test {Very big payload random access} { test {Very big payload random access} {
set err {} set err {}
array set payload {} array set payload {}
for {set j 0} {$j < 100} {incr j} { for {set j 0} {$j < 100} {incr j} {
set size [expr 1+[randomInt 100000]] set size [expr 1+[randomInt 100000]]
set buf [string repeat "pl-$j" $size] set buf [string repeat "pl-$j" $size]
set payload($j) $buf set payload($j) $buf
r set bigpayload_$j $buf r set bigpayload_$j $buf
}
for {set j 0} {$j < 1000} {incr j} {
set index [randomInt 100]
set buf [r get bigpayload_$index]
if {$buf != $payload($index)} {
set err "Values differ: I set '$payload($index)' but I read back '$buf'"
break
} }
} for {set j 0} {$j < 1000} {incr j} {
unset payload set index [randomInt 100]
set _ $err set buf [r get bigpayload_$index]
} {} if {$buf != $payload($index)} {
set err "Values differ: I set '$payload($index)' but I read back '$buf'"
test {SET 10000 numeric keys and access all them in reverse order} { break
set err {} }
for {set x 0} {$x < 10000} {incr x} {
r set $x $x
}
set sum 0
for {set x 9999} {$x >= 0} {incr x -1} {
set val [r get $x]
if {$val ne $x} {
set err "Eleemnt at position $x is $val instead of $x"
break
} }
} unset payload
set _ $err set _ $err
} {} } {}
test {SET 10000 numeric keys and access all them in reverse order} {
set err {}
for {set x 0} {$x < 10000} {incr x} {
r set $x $x
}
set sum 0
for {set x 9999} {$x >= 0} {incr x -1} {
set val [r get $x]
if {$val ne $x} {
set err "Eleemnt at position $x is $val instead of $x"
break
}
}
set _ $err
} {}
test {DBSIZE should be 10101 now} { test {DBSIZE should be 10101 now} {
r dbsize r dbsize
} {10101} } {10101}
} }
test {INCR against non existing key} { test {INCR against non existing key} {
......
start_server {} { start_server {tags {"cas"}} {
test {EXEC works on WATCHed key not modified} { test {EXEC works on WATCHed key not modified} {
r watch x y z r watch x y z
r watch k r watch k
......
start_server {} { start_server {tags {"expire"}} {
test {EXPIRE - don't set timeouts multiple times} { test {EXPIRE - don't set timeouts multiple times} {
r set x foobar r set x foobar
set v1 [r expire x 5] set v1 [r expire x 5]
......
start_server {} { start_server {tags {"sort"}} {
test {SORT ALPHA against integer encoded strings} { test {SORT ALPHA against integer encoded strings} {
r del mylist r del mylist
r lpush mylist 2 r lpush mylist 2
...@@ -8,130 +8,132 @@ start_server {} { ...@@ -8,130 +8,132 @@ start_server {} {
r sort mylist alpha r sort mylist alpha
} {1 10 2 3} } {1 10 2 3}
test {Create a random list and a random set} { tags {"slow"} {
set tosort {} test {Create a random list and a random set} {
array set seenrand {} set tosort {}
for {set i 0} {$i < 10000} {incr i} { array set seenrand {}
while 1 { for {set i 0} {$i < 10000} {incr i} {
# Make sure all the weights are different because while 1 {
# Redis does not use a stable sort but Tcl does. # Make sure all the weights are different because
randpath { # Redis does not use a stable sort but Tcl does.
set rint [expr int(rand()*1000000)] randpath {
} { set rint [expr int(rand()*1000000)]
set rint [expr rand()] } {
set rint [expr rand()]
}
if {![info exists seenrand($rint)]} break
} }
if {![info exists seenrand($rint)]} break set seenrand($rint) x
r lpush tosort $i
r sadd tosort-set $i
r set weight_$i $rint
r hset wobj_$i weight $rint
lappend tosort [list $i $rint]
} }
set seenrand($rint) x set sorted [lsort -index 1 -real $tosort]
r lpush tosort $i set res {}
r sadd tosort-set $i for {set i 0} {$i < 10000} {incr i} {
r set weight_$i $rint lappend res [lindex $sorted $i 0]
r hset wobj_$i weight $rint
lappend tosort [list $i $rint]
}
set sorted [lsort -index 1 -real $tosort]
set res {}
for {set i 0} {$i < 10000} {incr i} {
lappend res [lindex $sorted $i 0]
}
format {}
} {}
test {SORT with BY against the newly created list} {
r sort tosort {BY weight_*}
} $res
test {SORT with BY (hash field) against the newly created list} {
r sort tosort {BY wobj_*->weight}
} $res
test {SORT with GET (key+hash) with sanity check of each element (list)} {
set err {}
set l1 [r sort tosort GET # GET weight_*]
set l2 [r sort tosort GET # GET wobj_*->weight]
foreach {id1 w1} $l1 {id2 w2} $l2 {
set realweight [r get weight_$id1]
if {$id1 != $id2} {
set err "ID mismatch $id1 != $id2"
break
} }
if {$realweight != $w1 || $realweight != $w2} { format {}
set err "Weights mismatch! w1: $w1 w2: $w2 real: $realweight" } {}
break
test {SORT with BY against the newly created list} {
r sort tosort {BY weight_*}
} $res
test {SORT with BY (hash field) against the newly created list} {
r sort tosort {BY wobj_*->weight}
} $res
test {SORT with GET (key+hash) with sanity check of each element (list)} {
set err {}
set l1 [r sort tosort GET # GET weight_*]
set l2 [r sort tosort GET # GET wobj_*->weight]
foreach {id1 w1} $l1 {id2 w2} $l2 {
set realweight [r get weight_$id1]
if {$id1 != $id2} {
set err "ID mismatch $id1 != $id2"
break
}
if {$realweight != $w1 || $realweight != $w2} {
set err "Weights mismatch! w1: $w1 w2: $w2 real: $realweight"
break
}
} }
} set _ $err
set _ $err } {}
} {}
test {SORT with BY, but against the newly created set} {
test {SORT with BY, but against the newly created set} { r sort tosort-set {BY weight_*}
r sort tosort-set {BY weight_*} } $res
} $res
test {SORT with BY (hash field), but against the newly created set} {
test {SORT with BY (hash field), but against the newly created set} { r sort tosort-set {BY wobj_*->weight}
r sort tosort-set {BY wobj_*->weight} } $res
} $res
test {SORT with BY and STORE against the newly created list} {
test {SORT with BY and STORE against the newly created list} { r sort tosort {BY weight_*} store sort-res
r sort tosort {BY weight_*} store sort-res r lrange sort-res 0 -1
r lrange sort-res 0 -1 } $res
} $res
test {SORT with BY (hash field) and STORE against the newly created list} {
test {SORT with BY (hash field) and STORE against the newly created list} { r sort tosort {BY wobj_*->weight} store sort-res
r sort tosort {BY wobj_*->weight} store sort-res r lrange sort-res 0 -1
r lrange sort-res 0 -1 } $res
} $res
test {SORT direct, numeric, against the newly created list} {
test {SORT direct, numeric, against the newly created list} { r sort tosort
r sort tosort } [lsort -integer $res]
} [lsort -integer $res]
test {SORT decreasing sort} {
test {SORT decreasing sort} { r sort tosort {DESC}
r sort tosort {DESC} } [lsort -decreasing -integer $res]
} [lsort -decreasing -integer $res]
test {SORT speed, sorting 10000 elements list using BY, 100 times} {
test {SORT speed, sorting 10000 elements list using BY, 100 times} { set start [clock clicks -milliseconds]
set start [clock clicks -milliseconds] for {set i 0} {$i < 100} {incr i} {
for {set i 0} {$i < 100} {incr i} { set sorted [r sort tosort {BY weight_* LIMIT 0 10}]
set sorted [r sort tosort {BY weight_* LIMIT 0 10}] }
} set elapsed [expr [clock clicks -milliseconds]-$start]
set elapsed [expr [clock clicks -milliseconds]-$start] puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds " flush stdout
flush stdout format {}
format {} } {}
} {}
test {SORT speed, as above but against hash field} {
test {SORT speed, as above but against hash field} { set start [clock clicks -milliseconds]
set start [clock clicks -milliseconds] for {set i 0} {$i < 100} {incr i} {
for {set i 0} {$i < 100} {incr i} { set sorted [r sort tosort {BY wobj_*->weight LIMIT 0 10}]
set sorted [r sort tosort {BY wobj_*->weight LIMIT 0 10}] }
} set elapsed [expr [clock clicks -milliseconds]-$start]
set elapsed [expr [clock clicks -milliseconds]-$start] puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds " flush stdout
flush stdout format {}
format {} } {}
} {}
test {SORT speed, sorting 10000 elements list directly, 100 times} {
test {SORT speed, sorting 10000 elements list directly, 100 times} { set start [clock clicks -milliseconds]
set start [clock clicks -milliseconds] for {set i 0} {$i < 100} {incr i} {
for {set i 0} {$i < 100} {incr i} { set sorted [r sort tosort {LIMIT 0 10}]
set sorted [r sort tosort {LIMIT 0 10}] }
} set elapsed [expr [clock clicks -milliseconds]-$start]
set elapsed [expr [clock clicks -milliseconds]-$start] puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds " flush stdout
flush stdout format {}
format {} } {}
} {}
test {SORT speed, pseudo-sorting 10000 elements list, BY <const>, 100 times} {
test {SORT speed, pseudo-sorting 10000 elements list, BY <const>, 100 times} { set start [clock clicks -milliseconds]
set start [clock clicks -milliseconds] for {set i 0} {$i < 100} {incr i} {
for {set i 0} {$i < 100} {incr i} { set sorted [r sort tosort {BY nokey LIMIT 0 10}]
set sorted [r sort tosort {BY nokey LIMIT 0 10}] }
} set elapsed [expr [clock clicks -milliseconds]-$start]
set elapsed [expr [clock clicks -milliseconds]-$start] puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds " flush stdout
flush stdout format {}
format {} } {}
} {} }
test {SORT regression for issue #19, sorting floats} { test {SORT regression for issue #19, sorting floats} {
r flushdb r flushdb
......
start_server {} { start_server {tags {"hash"}} {
test {HSET/HLEN - Small hash creation} { test {HSET/HLEN - Small hash creation} {
array set smallhash {} array set smallhash {}
for {set i 0} {$i < 8} {incr i} { for {set i 0} {$i < 8} {incr i} {
......
start_server {} { start_server {tags {"list"}} {
test {Basic LPUSH, RPUSH, LLENGTH, LINDEX} { test {Basic LPUSH, RPUSH, LLENGTH, LINDEX} {
set res [r lpush mylist a] set res [r lpush mylist a]
append res [r lpush mylist b] append res [r lpush mylist b]
......
start_server {} { start_server {tags {"set"}} {
test {SADD, SCARD, SISMEMBER, SMEMBERS basics} { test {SADD, SCARD, SISMEMBER, SMEMBERS basics} {
r sadd myset foo r sadd myset foo
r sadd myset bar r sadd myset bar
......
start_server {} { start_server {tags {"zset"}} {
test {ZSET basic ZADD and score update} { test {ZSET basic ZADD and score update} {
r zadd ztmp 10 x r zadd ztmp 10 x
r zadd ztmp 20 y r zadd ztmp 20 y
...@@ -162,85 +162,87 @@ start_server {} { ...@@ -162,85 +162,87 @@ start_server {} {
r zrangebyscore zset 2 4 withscores r zrangebyscore zset 2 4 withscores
} {b 2 c 3 d 4} } {b 2 c 3 d 4}
test {ZRANGEBYSCORE fuzzy test, 100 ranges in 1000 elements sorted set} { tags {"slow"} {
set err {} test {ZRANGEBYSCORE fuzzy test, 100 ranges in 1000 elements sorted set} {
r del zset set err {}
for {set i 0} {$i < 1000} {incr i} { r del zset
r zadd zset [expr rand()] $i for {set i 0} {$i < 1000} {incr i} {
} r zadd zset [expr rand()] $i
for {set i 0} {$i < 100} {incr i} {
set min [expr rand()]
set max [expr rand()]
if {$min > $max} {
set aux $min
set min $max
set max $aux
}
set low [r zrangebyscore zset -inf $min]
set ok [r zrangebyscore zset $min $max]
set high [r zrangebyscore zset $max +inf]
set lowx [r zrangebyscore zset -inf ($min]
set okx [r zrangebyscore zset ($min ($max]
set highx [r zrangebyscore zset ($max +inf]
if {[r zcount zset -inf $min] != [llength $low]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset $min $max] != [llength $ok]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset $max +inf] != [llength $high]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset -inf ($min] != [llength $lowx]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset ($min ($max] != [llength $okx]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset ($max +inf] != [llength $highx]} {
append err "Error, len does not match zcount\n"
} }
for {set i 0} {$i < 100} {incr i} {
set min [expr rand()]
set max [expr rand()]
if {$min > $max} {
set aux $min
set min $max
set max $aux
}
set low [r zrangebyscore zset -inf $min]
set ok [r zrangebyscore zset $min $max]
set high [r zrangebyscore zset $max +inf]
set lowx [r zrangebyscore zset -inf ($min]
set okx [r zrangebyscore zset ($min ($max]
set highx [r zrangebyscore zset ($max +inf]
if {[r zcount zset -inf $min] != [llength $low]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset $min $max] != [llength $ok]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset $max +inf] != [llength $high]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset -inf ($min] != [llength $lowx]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset ($min ($max] != [llength $okx]} {
append err "Error, len does not match zcount\n"
}
if {[r zcount zset ($max +inf] != [llength $highx]} {
append err "Error, len does not match zcount\n"
}
foreach x $low { foreach x $low {
set score [r zscore zset $x] set score [r zscore zset $x]
if {$score > $min} { if {$score > $min} {
append err "Error, score for $x is $score > $min\n" append err "Error, score for $x is $score > $min\n"
}
} }
} foreach x $lowx {
foreach x $lowx { set score [r zscore zset $x]
set score [r zscore zset $x] if {$score >= $min} {
if {$score >= $min} { append err "Error, score for $x is $score >= $min\n"
append err "Error, score for $x is $score >= $min\n" }
} }
} foreach x $ok {
foreach x $ok { set score [r zscore zset $x]
set score [r zscore zset $x] if {$score < $min || $score > $max} {
if {$score < $min || $score > $max} { append err "Error, score for $x is $score outside $min-$max range\n"
append err "Error, score for $x is $score outside $min-$max range\n" }
} }
} foreach x $okx {
foreach x $okx { set score [r zscore zset $x]
set score [r zscore zset $x] if {$score <= $min || $score >= $max} {
if {$score <= $min || $score >= $max} { append err "Error, score for $x is $score outside $min-$max open range\n"
append err "Error, score for $x is $score outside $min-$max open range\n" }
} }
} foreach x $high {
foreach x $high { set score [r zscore zset $x]
set score [r zscore zset $x] if {$score < $max} {
if {$score < $max} { append err "Error, score for $x is $score < $max\n"
append err "Error, score for $x is $score < $max\n" }
} }
} foreach x $highx {
foreach x $highx { set score [r zscore zset $x]
set score [r zscore zset $x] if {$score <= $max} {
if {$score <= $max} { append err "Error, score for $x is $score <= $max\n"
append err "Error, score for $x is $score <= $max\n" }
} }
} }
} set _ $err
set _ $err } {}
} {} }
test {ZRANGEBYSCORE with LIMIT} { test {ZRANGEBYSCORE with LIMIT} {
r del zset r del zset
...@@ -356,47 +358,49 @@ start_server {} { ...@@ -356,47 +358,49 @@ start_server {} {
list [r zinterstore zsetc 2 zseta zsetb aggregate max] [r zrange zsetc 0 -1 withscores] list [r zinterstore zsetc 2 zseta zsetb aggregate max] [r zrange zsetc 0 -1 withscores]
} {2 {b 2 c 3}} } {2 {b 2 c 3}}
test {ZSETs skiplist implementation backlink consistency test} { tags {"slow"} {
set diff 0 test {ZSETs skiplist implementation backlink consistency test} {
set elements 10000 set diff 0
for {set j 0} {$j < $elements} {incr j} { set elements 10000
r zadd myzset [expr rand()] "Element-$j" for {set j 0} {$j < $elements} {incr j} {
r zrem myzset "Element-[expr int(rand()*$elements)]" r zadd myzset [expr rand()] "Element-$j"
} r zrem myzset "Element-[expr int(rand()*$elements)]"
set l1 [r zrange myzset 0 -1]
set l2 [r zrevrange myzset 0 -1]
for {set j 0} {$j < [llength $l1]} {incr j} {
if {[lindex $l1 $j] ne [lindex $l2 end-$j]} {
incr diff
} }
} set l1 [r zrange myzset 0 -1]
format $diff set l2 [r zrevrange myzset 0 -1]
} {0} for {set j 0} {$j < [llength $l1]} {incr j} {
if {[lindex $l1 $j] ne [lindex $l2 end-$j]} {
test {ZSETs ZRANK augmented skip list stress testing} { incr diff
set err {} }
r del myzset
for {set k 0} {$k < 10000} {incr k} {
set i [expr {$k%1000}]
if {[expr rand()] < .2} {
r zrem myzset $i
} else {
set score [expr rand()]
r zadd myzset $score $i
} }
set card [r zcard myzset] format $diff
if {$card > 0} { } {0}
set index [randomInt $card]
set ele [lindex [r zrange myzset $index $index] 0] test {ZSETs ZRANK augmented skip list stress testing} {
set rank [r zrank myzset $ele] set err {}
if {$rank != $index} { r del myzset
set err "$ele RANK is wrong! ($rank != $index)" for {set k 0} {$k < 10000} {incr k} {
break set i [expr {$k%1000}]
if {[expr rand()] < .2} {
r zrem myzset $i
} else {
set score [expr rand()]
r zadd myzset $score $i
}
set card [r zcard myzset]
if {$card > 0} {
set index [randomInt $card]
set ele [lindex [r zrange myzset $index $index] 0]
set rank [r zrank myzset $ele]
if {$rank != $index} {
set err "$ele RANK is wrong! ($rank != $index)"
break
}
} }
} }
} set _ $err
set _ $err } {}
} {} }
test {ZSET element can't be set to nan with ZADD} { test {ZSET element can't be set to nan with ZADD} {
set e {} set e {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment