Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
9ec4ea20
"vscode:/vscode.git/clone" did not exist on "63075b81e628968c860f0baf32effcf9aeededeb"
Commit
9ec4ea20
authored
Mar 14, 2011
by
Pieter Noordhuis
Browse files
Test both sorted set encodings for every test
parent
69298a05
Changes
1
Show whitespace changes
Inline
Side-by-side
tests/unit/type/zset.tcl
View file @
9ec4ea20
...
@@ -6,25 +6,54 @@ start_server {tags {"zset"}} {
...
@@ -6,25 +6,54 @@ start_server {tags {"zset"}} {
}
}
}
}
test
{
ZSET basic ZADD and score update
}
{
proc basics
{
encoding
}
{
if
{
$encoding
==
"ziplist"
}
{
r config set zset-max-ziplist-entries 128
r config set zset-max-ziplist-value 64
}
elseif
{
$encoding
==
"raw"
}
{
r config set zset-max-ziplist-entries 0
r config set zset-max-ziplist-value 0
}
else
{
puts
"Unknown sorted set encoding"
exit
}
test
"Check encoding -
$encoding
"
{
r del ztmp
r zadd ztmp 10 x
assert_encoding $encoding ztmp
}
test
"ZSET basic ZADD and score update -
$encoding
"
{
r del ztmp
r zadd ztmp 10 x
r zadd ztmp 10 x
r zadd ztmp 20 y
r zadd ztmp 20 y
r zadd ztmp 30 z
r zadd ztmp 30 z
set aux1
[
r zrange ztmp 0 -1
]
assert_equal
{
x y z
}
[
r zrange ztmp 0 -1
]
r zadd ztmp 1 y
r zadd ztmp 1 y
set aux2
[
r zrange ztmp 0 -1
]
assert_equal
{
y x z
}
[
r zrange ztmp 0 -1
]
list $aux1 $aux2
}
}
{{
x y z
}
{
y x z
}}
test
"ZSET element can't be set to NaN with ZADD -
$encoding
"
{
assert_error
"*not a double*"
{
r zadd myzset nan abc
}
}
test
{
ZCARD basics
}
{
test
"ZSET element can't be set to NaN with ZINCRBY"
{
r zcard ztmp
assert_error
"*not a double*"
{
r zadd myzset nan abc
}
}
{
3
}
}
test
{
ZCARD non existing key
}
{
test
"ZINCRBY calls leading to NaN result in error"
{
r zcard ztmp-blabla
r zincrby myzset +inf abc
}
{
0
}
assert_error
"*NaN*"
{
r zincrby myzset -inf abc
}
}
test
"ZCARD basics -
$encoding
"
{
assert_equal 3
[
r zcard ztmp
]
assert_equal 0
[
r zcard zdoesntexist
]
}
test
"ZRANGE basics"
{
test
"ZRANGE basics
-
$encoding
"
{
r del ztmp
r del ztmp
r zadd ztmp 1 a
r zadd ztmp 1 a
r zadd ztmp 2 b
r zadd ztmp 2 b
...
@@ -54,7 +83,7 @@ start_server {tags {"zset"}} {
...
@@ -54,7 +83,7 @@ start_server {tags {"zset"}} {
assert_equal
{
a 1 b 2 c 3 d 4
}
[
r zrange ztmp 0 -1 withscores
]
assert_equal
{
a 1 b 2 c 3 d 4
}
[
r zrange ztmp 0 -1 withscores
]
}
}
test
"ZREVRANGE basics"
{
test
"ZREVRANGE basics
-
$encoding
"
{
r del ztmp
r del ztmp
r zadd ztmp 1 a
r zadd ztmp 1 a
r zadd ztmp 2 b
r zadd ztmp 2 b
...
@@ -84,120 +113,47 @@ start_server {tags {"zset"}} {
...
@@ -84,120 +113,47 @@ start_server {tags {"zset"}} {
assert_equal
{
d 4 c 3 b 2 a 1
}
[
r zrevrange ztmp 0 -1 withscores
]
assert_equal
{
d 4 c 3 b 2 a 1
}
[
r zrevrange ztmp 0 -1 withscores
]
}
}
test
{
ZRANK basics
}
{
test
"ZRANK/ZREVRANK basics -
$encoding
"
{
r del zranktmp
r zadd zranktmp 10 x
r zadd zranktmp 10 x
r zadd zranktmp 20 y
r zadd zranktmp 20 y
r zadd zranktmp 30 z
r zadd zranktmp 30 z
list
[
r zrank zranktmp x
]
[
r zrank zranktmp y
]
[
r zrank zranktmp z
]
assert_equal 0
[
r zrank zranktmp x
]
}
{
0 1 2
}
assert_equal 1
[
r zrank zranktmp y
]
assert_equal 2
[
r zrank zranktmp z
]
test
{
ZREVRANK basics
}
{
assert_equal
""
[
r zrank zranktmp foo
]
list
[
r zrevrank zranktmp x
]
[
r zrevrank zranktmp y
]
[
r zrevrank zranktmp z
]
assert_equal 2
[
r zrevrank zranktmp x
]
}
{
2 1 0
}
assert_equal 1
[
r zrevrank zranktmp y
]
assert_equal 0
[
r zrevrank zranktmp z
]
test
{
ZRANK - after deletion
}
{
assert_equal
""
[
r zrevrank zranktmp foo
]
r zrem zranktmp y
list
[
r zrank zranktmp x
]
[
r zrank zranktmp z
]
}
{
0 1
}
test
{
ZSCORE
}
{
set aux
{}
set err
{}
for
{
set i 0
}
{
$i
< 1000
}
{
incr i
}
{
set score
[
expr rand
()]
lappend aux $score
r zadd zscoretest $score $i
}
for
{
set i 0
}
{
$i
< 1000
}
{
incr i
}
{
if
{[
r zscore zscoretest $i
]
!=
[
lindex $aux $i
]}
{
set err
"Expected score was
[
lindex $aux $i
]
but got
[
r zscore zscoretest $i
]
for element
$i
"
break
}
}
}
set _ $err
}
{}
test
{
ZSCORE after a DEBUG RELOAD
}
{
test
"ZRANK - after deletion -
$encoding
"
{
set aux
{}
r zrem zranktmp y
set err
{}
assert_equal 0
[
r zrank zranktmp x
]
r del zscoretest
assert_equal 1
[
r zrank zranktmp z
]
for
{
set i 0
}
{
$i
< 1000
}
{
incr i
}
{
set score
[
expr rand
()]
lappend aux $score
r zadd zscoretest $score $i
}
r debug reload
for
{
set i 0
}
{
$i
< 1000
}
{
incr i
}
{
if
{[
r zscore zscoretest $i
]
!=
[
lindex $aux $i
]}
{
set err
"Expected score was
[
lindex $aux $i
]
but got
[
r zscore zscoretest $i
]
for element
$i
"
break
}
}
set _ $err
}
{}
test
{
ZSETs stress tester - sorting is working well?
}
{
set delta 0
for
{
set test 0
}
{
$test
< 2
}
{
incr test
}
{
unset -nocomplain auxarray
array set auxarray
{}
set auxlist
{}
r del myzset
for
{
set i 0
}
{
$i
< 1000
}
{
incr i
}
{
if
{
$test
== 0
}
{
set score
[
expr rand
()]
}
else
{
set score
[
expr int
(
rand
()
*10
)]
}
set auxarray
(
$i
)
$score
r zadd myzset $score $i
# Random update
if
{[
expr rand
()]
< .2
}
{
set j
[
expr int
(
rand
()
*1000
)]
if
{
$test
== 0
}
{
set score
[
expr rand
()]
}
else
{
set score
[
expr int
(
rand
()
*10
)]
}
set auxarray
(
$j
)
$score
r zadd myzset $score $j
}
}
foreach
{
item score
}
[
array get auxarray
]
{
lappend auxlist
[
list $score $item
]
}
set sorted
[
lsort -command zlistAlikeSort $auxlist
]
set auxlist
{}
foreach x $sorted
{
lappend auxlist
[
lindex $x 1
]
}
set fromredis
[
r zrange myzset 0 -1
]
set delta 0
for
{
set i 0
}
{
$i
<
[
llength $fromredis
]}
{
incr i
}
{
if
{[
lindex $fromredis $i
]
!=
[
lindex $auxlist $i
]}
{
incr delta
}
}
}
}
format $delta
}
{
0
}
test
{
ZINCRBY - can create a new sorted set
}
{
test
"
ZINCRBY - can create a new sorted set
-
$encoding
"
{
r del zset
r del zset
r zincrby zset 1 foo
r zincrby zset 1 foo
list
[
r zrange zset 0 -1
]
[
r zscore zset foo
]
assert_equal
{
foo
}
[
r zrange zset 0 -1
]
}
{
foo 1
}
assert_equal 1
[
r zscore zset foo
]
}
test
{
ZINCRBY - increment and decrement
}
{
test
"
ZINCRBY - increment and decrement
-
$encoding
"
{
r zincrby zset 2 foo
r zincrby zset 2 foo
r zincrby zset 1 bar
r zincrby zset 1 bar
set v1
[
r zrange zset 0 -1
]
assert_equal
{
bar foo
}
[
r zrange zset 0 -1
]
r zincrby zset 10 bar
r zincrby zset 10 bar
r zincrby zset -5 foo
r zincrby zset -5 foo
r zincrby zset -5 bar
r zincrby zset -5 bar
set v2
[
r zrange zset 0 -1
]
assert_equal
{
foo bar
}
[
r zrange zset 0 -1
]
list $v1 $v2
[
r zscore zset foo
]
[
r zscore zset bar
]
}
{{
bar foo
}
{
foo bar
}
-2 6
}
assert_equal -2
[
r zscore zset foo
]
assert_equal 6
[
r zscore zset bar
]
}
proc create_default_zset
{}
{
proc create_default_zset
{}
{
create_zset zset
{
-inf a 1 b 2 c 3 d 4 e 5 f +inf g
}
create_zset zset
{
-inf a 1 b 2 c 3 d 4 e 5 f +inf g
}
...
@@ -285,88 +241,6 @@ start_server {tags {"zset"}} {
...
@@ -285,88 +241,6 @@ start_server {tags {"zset"}} {
assert_error
"*not a double*"
{
r zrangebyscore fooz 1 NaN
}
assert_error
"*not a double*"
{
r zrangebyscore fooz 1 NaN
}
}
}
tags
{
"slow"
}
{
test
{
ZRANGEBYSCORE fuzzy test, 100 ranges in 1000 elements sorted set
}
{
set err
{}
r del zset
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
"
}
foreach x $low
{
set score
[
r zscore zset $x
]
if
{
$score
> $min
}
{
append err
"Error, score for
$x
is
$score
>
$min
\n
"
}
}
foreach x $lowx
{
set score
[
r zscore zset $x
]
if
{
$score
>= $min
}
{
append err
"Error, score for
$x
is
$score
>=
$min
\n
"
}
}
foreach x $ok
{
set score
[
r zscore zset $x
]
if
{
$score
< $min || $score > $max
}
{
append err
"Error, score for
$x
is
$score
outside
$min-$max
range
\n
"
}
}
foreach x $okx
{
set score
[
r zscore zset $x
]
if
{
$score
<= $min || $score >= $max
}
{
append err
"Error, score for
$x
is
$score
outside
$min-$max
open range
\n
"
}
}
foreach x $high
{
set score
[
r zscore zset $x
]
if
{
$score
< $max
}
{
append err
"Error, score for
$x
is
$score
<
$max
\n
"
}
}
foreach x $highx
{
set score
[
r zscore zset $x
]
if
{
$score
<= $max
}
{
append err
"Error, score for
$x
is
$score
<=
$max
\n
"
}
}
}
set _ $err
}
{}
}
test
"ZREMRANGEBYSCORE basics"
{
test
"ZREMRANGEBYSCORE basics"
{
proc remrangebyscore
{
min max
}
{
proc remrangebyscore
{
min max
}
{
create_zset zset
{
1 a 2 b 3 c 4 d 5 e
}
create_zset zset
{
1 a 2 b 3 c 4 d 5 e
}
...
@@ -451,12 +325,13 @@ start_server {tags {"zset"}} {
...
@@ -451,12 +325,13 @@ start_server {tags {"zset"}} {
assert_equal
{}
[
r zrange zset 0 -1
]
assert_equal
{}
[
r zrange zset 0 -1
]
}
}
test
{
ZUNIONSTORE against non-existing key doesn't set destination
}
{
test
"
ZUNIONSTORE against non-existing key doesn't set destination
-
$encoding
"
{
r del zseta
r del zseta
list
[
r zunionstore dst_key 1 zseta
]
[
r exists dst_key
]
assert_equal 0
[
r zunionstore dst_key 1 zseta
]
}
{
0 0
}
assert_equal 0
[
r exists dst_key
]
}
test
{
ZUNIONSTORE basics
}
{
test
"
ZUNIONSTORE basics
-
$encoding
"
{
r del zseta zsetb zsetc
r del zseta zsetb zsetc
r zadd zseta 1 a
r zadd zseta 1 a
r zadd zseta 2 b
r zadd zseta 2 b
...
@@ -464,55 +339,67 @@ start_server {tags {"zset"}} {
...
@@ -464,55 +339,67 @@ start_server {tags {"zset"}} {
r zadd zsetb 1 b
r zadd zsetb 1 b
r zadd zsetb 2 c
r zadd zsetb 2 c
r zadd zsetb 3 d
r zadd zsetb 3 d
list
[
r zunionstore zsetc 2 zseta zsetb
]
[
r zrange zsetc 0 -1 withscores
]
}
{
4
{
a 1 b 3 d 3 c 5
}}
test
{
ZUNIONSTORE with weights
}
{
assert_equal 4
[
r zunionstore zsetc 2 zseta zsetb
]
list
[
r zunionstore zsetc 2 zseta zsetb weights 2 3
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal
{
a 1 b 3 d 3 c 5
}
[
r zrange zsetc 0 -1 withscores
]
}
{
4
{
a 2 b 7 d 9 c 12
}}
}
test
"ZUNIONSTORE with weights -
$encoding
"
{
assert_equal 4
[
r zunionstore zsetc 2 zseta zsetb weights 2 3
]
assert_equal
{
a 2 b 7 d 9 c 12
}
[
r zrange zsetc 0 -1 withscores
]
}
test
{
ZUNIONSTORE with a regular set and weights
}
{
test
"
ZUNIONSTORE with a regular set and weights
-
$encoding
"
{
r del seta
r del seta
r sadd seta a
r sadd seta a
r sadd seta b
r sadd seta b
r sadd seta c
r sadd seta c
list
[
r zunionstore zsetc 2 seta zsetb weights 2 3
]
[
r zrange zsetc 0 -1 withscores
]
}
{
4
{
a 2 b 5 c 8 d 9
}}
test
{
ZUNIONSTORE with AGGREGATE MIN
}
{
assert_equal 4
[
r zunionstore zsetc 2 seta zsetb weights 2 3
]
list
[
r zunionstore zsetc 2 zseta zsetb aggregate min
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal
{
a 2 b 5 c 8 d 9
}
[
r zrange zsetc 0 -1 withscores
]
}
{
4
{
a 1 b 1 c 2 d 3
}
}
}
test
{
ZUNIONSTORE with AGGREGATE MAX
}
{
test
"ZUNIONSTORE with AGGREGATE MIN -
$encoding
"
{
list
[
r zunionstore zsetc 2 zseta zsetb aggregate max
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal 4
[
r zunionstore zsetc 2 zseta zsetb aggregate min
]
}
{
4
{
a 1 b 2 c 3 d 3
}}
assert_equal
{
a 1 b 1 c 2 d 3
}
[
r zrange zsetc 0 -1 withscores
]
}
test
{
ZINTERSTORE basics
}
{
test
"ZUNIONSTORE with AGGREGATE MAX -
$encoding
"
{
list
[
r zinterstore zsetc 2 zseta zsetb
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal 4
[
r zunionstore zsetc 2 zseta zsetb aggregate max
]
}
{
2
{
b 3 c 5
}}
assert_equal
{
a 1 b 2 c 3 d 3
}
[
r zrange zsetc 0 -1 withscores
]
}
test
{
ZINTERSTORE with weights
}
{
test
"ZINTERSTORE basics -
$encoding
"
{
list
[
r zinterstore zsetc 2 zseta zsetb weights 2 3
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal 2
[
r zinterstore zsetc 2 zseta zsetb
]
}
{
2
{
b 7 c 12
}}
assert_equal
{
b 3 c 5
}
[
r zrange zsetc 0 -1 withscores
]
}
test
{
ZINTERSTORE with a regular set and weights
}
{
test
"ZINTERSTORE with weights -
$encoding
"
{
assert_equal 2
[
r zinterstore zsetc 2 zseta zsetb weights 2 3
]
assert_equal
{
b 7 c 12
}
[
r zrange zsetc 0 -1 withscores
]
}
test
"ZINTERSTORE with a regular set and weights -
$encoding
"
{
r del seta
r del seta
r sadd seta a
r sadd seta a
r sadd seta b
r sadd seta b
r sadd seta c
r sadd seta c
list
[
r zinterstore zsetc 2 seta zsetb weights 2 3
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal 2
[
r zinterstore zsetc 2 seta zsetb weights 2 3
]
}
{
2
{
b 5 c 8
}}
assert_equal
{
b 5 c 8
}
[
r zrange zsetc 0 -1 withscores
]
}
test
{
ZINTERSTORE with AGGREGATE MIN
}
{
test
"ZINTERSTORE with AGGREGATE MIN -
$encoding
"
{
list
[
r zinterstore zsetc 2 zseta zsetb aggregate min
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal 2
[
r zinterstore zsetc 2 zseta zsetb aggregate min
]
}
{
2
{
b 1 c 2
}}
assert_equal
{
b 1 c 2
}
[
r zrange zsetc 0 -1 withscores
]
}
test
{
ZINTERSTORE with AGGREGATE MAX
}
{
test
"ZINTERSTORE with AGGREGATE MAX -
$encoding
"
{
list
[
r zinterstore zsetc 2 zseta zsetb aggregate max
]
[
r zrange zsetc 0 -1 withscores
]
assert_equal 2
[
r zinterstore zsetc 2 zseta zsetb aggregate max
]
}
{
2
{
b 2 c 3
}}
assert_equal
{
b 2 c 3
}
[
r zrange zsetc 0 -1 withscores
]
}
foreach cmd
{
ZUNIONSTORE ZINTERSTORE
}
{
foreach cmd
{
ZUNIONSTORE ZINTERSTORE
}
{
test
"
$cmd
with +inf/-inf scores"
{
test
"
$cmd
with +inf/-inf scores
-
$encoding
"
{
r del zsetinf1 zsetinf2
r del zsetinf1 zsetinf2
r zadd zsetinf1 +inf key
r zadd zsetinf1 +inf key
...
@@ -536,7 +423,7 @@ start_server {tags {"zset"}} {
...
@@ -536,7 +423,7 @@ start_server {tags {"zset"}} {
assert_equal -inf
[
r zscore zsetinf3 key
]
assert_equal -inf
[
r zscore zsetinf3 key
]
}
}
test
"
$cmd
with NaN weights"
{
test
"
$cmd
with NaN weights
$encoding
"
{
r del zsetinf1 zsetinf2
r del zsetinf1 zsetinf2
r zadd zsetinf1 1.0 key
r zadd zsetinf1 1.0 key
...
@@ -546,15 +433,195 @@ start_server {tags {"zset"}} {
...
@@ -546,15 +433,195 @@ start_server {tags {"zset"}} {
}
}
}
}
}
}
}
tags
{
"slow"
}
{
basics ziplist
test
{
ZSETs skiplist implementation backlink consistency test
}
{
basics raw
proc stressers
{
encoding
}
{
if
{
$encoding
==
"ziplist"
}
{
# Little extra to allow proper fuzzing in the sorting stresser
r config set zset-max-ziplist-entries 256
r config set zset-max-ziplist-value 64
set elements 128
}
elseif
{
$encoding
==
"raw"
}
{
r config set zset-max-ziplist-entries 0
r config set zset-max-ziplist-value 0
set elements 1000
}
else
{
puts
"Unknown sorted set encoding"
exit
}
test
"ZSCORE -
$encoding
"
{
r del zscoretest
set aux
{}
for
{
set i 0
}
{
$i
< $elements
}
{
incr i
}
{
set score
[
expr rand
()]
lappend aux $score
r zadd zscoretest $score $i
}
assert_encoding $encoding zscoretest
for
{
set i 0
}
{
$i
< $elements
}
{
incr i
}
{
assert_equal
[
lindex $aux $i
]
[
r zscore zscoretest $i
]
}
}
test
"ZSCORE after a DEBUG RELOAD -
$encoding
"
{
r del zscoretest
set aux
{}
for
{
set i 0
}
{
$i
< $elements
}
{
incr i
}
{
set score
[
expr rand
()]
lappend aux $score
r zadd zscoretest $score $i
}
r debug reload
assert_encoding $encoding zscoretest
for
{
set i 0
}
{
$i
< $elements
}
{
incr i
}
{
assert_equal
[
lindex $aux $i
]
[
r zscore zscoretest $i
]
}
}
test
"ZSET sorting stresser -
$encoding
"
{
set delta 0
for
{
set test 0
}
{
$test
< 2
}
{
incr test
}
{
unset -nocomplain auxarray
array set auxarray
{}
set auxlist
{}
r del myzset
for
{
set i 0
}
{
$i
< $elements
}
{
incr i
}
{
if
{
$test
== 0
}
{
set score
[
expr rand
()]
}
else
{
set score
[
expr int
(
rand
()
*10
)]
}
set auxarray
(
$i
)
$score
r zadd myzset $score $i
# Random update
if
{[
expr rand
()]
< .2
}
{
set j
[
expr int
(
rand
()
*1000
)]
if
{
$test
== 0
}
{
set score
[
expr rand
()]
}
else
{
set score
[
expr int
(
rand
()
*10
)]
}
set auxarray
(
$j
)
$score
r zadd myzset $score $j
}
}
foreach
{
item score
}
[
array get auxarray
]
{
lappend auxlist
[
list $score $item
]
}
set sorted
[
lsort -command zlistAlikeSort $auxlist
]
set auxlist
{}
foreach x $sorted
{
lappend auxlist
[
lindex $x 1
]
}
assert_encoding $encoding myzset
set fromredis
[
r zrange myzset 0 -1
]
set delta 0
for
{
set i 0
}
{
$i
<
[
llength $fromredis
]}
{
incr i
}
{
if
{[
lindex $fromredis $i
]
!=
[
lindex $auxlist $i
]}
{
incr delta
}
}
}
assert_equal 0 $delta
}
test
"ZRANGEBYSCORE fuzzy test, 100 ranges in
$elements
element sorted set -
$encoding
"
{
set err
{}
r del zset
for
{
set i 0
}
{
$i
< $elements
}
{
incr i
}
{
r zadd zset
[
expr rand
()]
$i
}
assert_encoding $encoding zset
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
{
set score
[
r zscore zset $x
]
if
{
$score
> $min
}
{
append err
"Error, score for
$x
is
$score
>
$min
\n
"
}
}
foreach x $lowx
{
set score
[
r zscore zset $x
]
if
{
$score
>= $min
}
{
append err
"Error, score for
$x
is
$score
>=
$min
\n
"
}
}
foreach x $ok
{
set score
[
r zscore zset $x
]
if
{
$score
< $min || $score > $max
}
{
append err
"Error, score for
$x
is
$score
outside
$min-$max
range
\n
"
}
}
foreach x $okx
{
set score
[
r zscore zset $x
]
if
{
$score
<= $min || $score >= $max
}
{
append err
"Error, score for
$x
is
$score
outside
$min-$max
open range
\n
"
}
}
foreach x $high
{
set score
[
r zscore zset $x
]
if
{
$score
< $max
}
{
append err
"Error, score for
$x
is
$score
<
$max
\n
"
}
}
foreach x $highx
{
set score
[
r zscore zset $x
]
if
{
$score
<= $max
}
{
append err
"Error, score for
$x
is
$score
<=
$max
\n
"
}
}
}
assert_equal
{}
$err
}
test
"ZSETs skiplist implementation backlink consistency test -
$encoding
"
{
set diff 0
set diff 0
set elements 10000
for
{
set j 0
}
{
$j
< $elements
}
{
incr j
}
{
for
{
set j 0
}
{
$j
< $elements
}
{
incr j
}
{
r zadd myzset
[
expr rand
()]
"Element-
$j
"
r zadd myzset
[
expr rand
()]
"Element-
$j
"
r zrem myzset
"Element-
[
expr int
(
rand
()
*$elements
)]
"
r zrem myzset
"Element-
[
expr int
(
rand
()
*$elements
)]
"
}
}
assert_encoding $encoding myzset
set l1
[
r zrange myzset 0 -1
]
set l1
[
r zrange myzset 0 -1
]
set l2
[
r zrevrange myzset 0 -1
]
set l2
[
r zrevrange myzset 0 -1
]
for
{
set j 0
}
{
$j
<
[
llength $l1
]}
{
incr j
}
{
for
{
set j 0
}
{
$j
<
[
llength $l1
]}
{
incr j
}
{
...
@@ -562,20 +629,22 @@ start_server {tags {"zset"}} {
...
@@ -562,20 +629,22 @@ start_server {tags {"zset"}} {
incr diff
incr diff
}
}
}
}
format
$diff
assert_equal 0
$diff
}
{
0
}
}
test
{
ZSETs ZRANK augmented skip list stress testing
}
{
test
"
ZSETs ZRANK augmented skip list stress testing
-
$encoding
"
{
set err
{}
set err
{}
r del myzset
r del myzset
for
{
set k 0
}
{
$k
<
10
000
}
{
incr k
}
{
for
{
set k 0
}
{
$k
<
2
000
}
{
incr k
}
{
set i
[
expr
{
$k
%1000
}]
set i
[
expr
{
$k
% $elements
}]
if
{[
expr rand
()]
< .2
}
{
if
{[
expr rand
()]
< .2
}
{
r zrem myzset $i
r zrem myzset $i
}
else
{
}
else
{
set score
[
expr rand
()]
set score
[
expr rand
()]
r zadd myzset $score $i
r zadd myzset $score $i
assert_encoding $encoding myzset
}
}
set card
[
r zcard myzset
]
set card
[
r zcard myzset
]
if
{
$card
> 0
}
{
if
{
$card
> 0
}
{
set index
[
randomInt $card
]
set index
[
randomInt $card
]
...
@@ -587,20 +656,12 @@ start_server {tags {"zset"}} {
...
@@ -587,20 +656,12 @@ start_server {tags {"zset"}} {
}
}
}
}
}
}
set _ $err
assert_equal
{}
$err
}
{}
}
test
{
ZSET element can't be set to NaN with ZADD
}
{
assert_error
"*not a double*"
{
r zadd myzset nan abc
}
}
}
test
{
ZSET element can't be set to NaN with ZINCRBY
}
{
assert_error
"*not a double*"
{
r zadd myzset nan abc
}
}
}
t
est
{
ZINCRBY calls leading to NaN result in error
}
{
t
ags
{
"slow"
}
{
r zincrby myzset +inf abc
stressers ziplist
assert_error
"*NaN*"
{
r zincrby myzset -inf abc
}
stressers raw
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment