Unverified Commit 8a86bca5 authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by GitHub
Browse files

Improve test suite to handle external servers better. (#9033)

This commit revives the improves the ability to run the test suite against
external servers, instead of launching and managing `redis-server` processes as
part of the test fixture.

This capability existed in the past, using the `--host` and `--port` options.
However, it was quite limited and mostly useful when running a specific tests.
Attempting to run larger chunks of the test suite experienced many issues:

* Many tests depend on being able to start and control `redis-server` themselves,
and there's no clear distinction between external server compatible and other
tests.
* Cluster mode is not supported (resulting with `CROSSSLOT` errors).

This PR cleans up many things and makes it possible to run the entire test suite
against an external server. It also provides more fine grained controls to
handle cases where the external server supports a subset of the Redis commands,
limited number of databases, cluster mode, etc.

The tests directory now contains a `README.md` file that describes how this
works.

This commit also includes additional cleanups and fixes:

* Tests can now be tagged.
* Tag-based selection is now unified across `start_server`, `tags` and `test`.
* More information is provided about skipped or ignored tests.
* Repeated patterns in tests have been extracted to common procedures, both at a
  global level and on a per-test file basis.
* Cleaned up some cases where test setup was based on a previous test executing
  (a major anti-pattern that repeats itself in many places).
* Cleaned up some cases where test teardown was not part of a test (in the
  future we should have dedicated teardown code that executes even when tests
  fail).
* Fixed some tests that were flaky running on external servers.
parent c396fd91
......@@ -97,7 +97,9 @@ start_server {
}
test "Set encoding after DEBUG RELOAD" {
r del myintset myhashset mylargeintset
r del myintset
r del myhashset
r del mylargeintset
for {set i 0} {$i < 100} {incr i} { r sadd myintset $i }
for {set i 0} {$i < 1280} {incr i} { r sadd mylargeintset $i }
for {set i 0} {$i < 256} {incr i} { r sadd myhashset [format "i%03d" $i] }
......@@ -109,7 +111,7 @@ start_server {
assert_encoding intset myintset
assert_encoding hashtable mylargeintset
assert_encoding hashtable myhashset
}
} {} {needs:debug}
test {SREM basics - regular set} {
create_set myset {foo bar ciao}
......@@ -143,19 +145,19 @@ start_server {
foreach {type} {hashtable intset} {
for {set i 1} {$i <= 5} {incr i} {
r del [format "set%d" $i]
r del [format "set%d{t}" $i]
}
for {set i 0} {$i < 200} {incr i} {
r sadd set1 $i
r sadd set2 [expr $i+195]
r sadd set1{t} $i
r sadd set2{t} [expr $i+195]
}
foreach i {199 195 1000 2000} {
r sadd set3 $i
r sadd set3{t} $i
}
for {set i 5} {$i < 200} {incr i} {
r sadd set4 $i
r sadd set4{t} $i
}
r sadd set5 0
r sadd set5{t} 0
# To make sure the sets are encoded as the type we are testing -- also
# when the VM is enabled and the values may be swapped in and out
......@@ -167,81 +169,81 @@ start_server {
}
for {set i 1} {$i <= 5} {incr i} {
r sadd [format "set%d" $i] $large
r sadd [format "set%d{t}" $i] $large
}
test "Generated sets must be encoded as $type" {
for {set i 1} {$i <= 5} {incr i} {
assert_encoding $type [format "set%d" $i]
assert_encoding $type [format "set%d{t}" $i]
}
}
test "SINTER with two sets - $type" {
assert_equal [list 195 196 197 198 199 $large] [lsort [r sinter set1 set2]]
assert_equal [list 195 196 197 198 199 $large] [lsort [r sinter set1{t} set2{t}]]
}
test "SINTERSTORE with two sets - $type" {
r sinterstore setres set1 set2
assert_encoding $type setres
assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres]]
r sinterstore setres{t} set1{t} set2{t}
assert_encoding $type setres{t}
assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres{t}]]
}
test "SINTERSTORE with two sets, after a DEBUG RELOAD - $type" {
r debug reload
r sinterstore setres set1 set2
assert_encoding $type setres
assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres]]
}
r sinterstore setres{t} set1{t} set2{t}
assert_encoding $type setres{t}
assert_equal [list 195 196 197 198 199 $large] [lsort [r smembers setres{t}]]
} {} {needs:debug}
test "SUNION with two sets - $type" {
set expected [lsort -uniq "[r smembers set1] [r smembers set2]"]
assert_equal $expected [lsort [r sunion set1 set2]]
set expected [lsort -uniq "[r smembers set1{t}] [r smembers set2{t}]"]
assert_equal $expected [lsort [r sunion set1{t} set2{t}]]
}
test "SUNIONSTORE with two sets - $type" {
r sunionstore setres set1 set2
assert_encoding $type setres
set expected [lsort -uniq "[r smembers set1] [r smembers set2]"]
assert_equal $expected [lsort [r smembers setres]]
r sunionstore setres{t} set1{t} set2{t}
assert_encoding $type setres{t}
set expected [lsort -uniq "[r smembers set1{t}] [r smembers set2{t}]"]
assert_equal $expected [lsort [r smembers setres{t}]]
}
test "SINTER against three sets - $type" {
assert_equal [list 195 199 $large] [lsort [r sinter set1 set2 set3]]
assert_equal [list 195 199 $large] [lsort [r sinter set1{t} set2{t} set3{t}]]
}
test "SINTERSTORE with three sets - $type" {
r sinterstore setres set1 set2 set3
assert_equal [list 195 199 $large] [lsort [r smembers setres]]
r sinterstore setres{t} set1{t} set2{t} set3{t}
assert_equal [list 195 199 $large] [lsort [r smembers setres{t}]]
}
test "SUNION with non existing keys - $type" {
set expected [lsort -uniq "[r smembers set1] [r smembers set2]"]
assert_equal $expected [lsort [r sunion nokey1 set1 set2 nokey2]]
set expected [lsort -uniq "[r smembers set1{t}] [r smembers set2{t}]"]
assert_equal $expected [lsort [r sunion nokey1{t} set1{t} set2{t} nokey2{t}]]
}
test "SDIFF with two sets - $type" {
assert_equal {0 1 2 3 4} [lsort [r sdiff set1 set4]]
assert_equal {0 1 2 3 4} [lsort [r sdiff set1{t} set4{t}]]
}
test "SDIFF with three sets - $type" {
assert_equal {1 2 3 4} [lsort [r sdiff set1 set4 set5]]
assert_equal {1 2 3 4} [lsort [r sdiff set1{t} set4{t} set5{t}]]
}
test "SDIFFSTORE with three sets - $type" {
r sdiffstore setres set1 set4 set5
r sdiffstore setres{t} set1{t} set4{t} set5{t}
# When we start with intsets, we should always end with intsets.
if {$type eq {intset}} {
assert_encoding intset setres
assert_encoding intset setres{t}
}
assert_equal {1 2 3 4} [lsort [r smembers setres]]
assert_equal {1 2 3 4} [lsort [r smembers setres{t}]]
}
}
test "SDIFF with first set empty" {
r del set1 set2 set3
r sadd set2 1 2 3 4
r sadd set3 a b c d
r sdiff set1 set2 set3
r del set1{t} set2{t} set3{t}
r sadd set2{t} 1 2 3 4
r sadd set3{t} a b c d
r sdiff set1{t} set2{t} set3{t}
} {}
test "SDIFF with same set two times" {
......@@ -258,11 +260,11 @@ start_server {
set num_sets [expr {[randomInt 10]+1}]
for {set i 0} {$i < $num_sets} {incr i} {
set num_elements [randomInt 100]
r del set_$i
lappend args set_$i
r del set_$i{t}
lappend args set_$i{t}
while {$num_elements} {
set ele [randomValue]
r sadd set_$i $ele
r sadd set_$i{t} $ele
if {$i == 0} {
set s($ele) x
} else {
......@@ -277,42 +279,42 @@ start_server {
}
test "SINTER against non-set should throw error" {
r set key1 x
assert_error "WRONGTYPE*" {r sinter key1 noset}
r set key1{t} x
assert_error "WRONGTYPE*" {r sinter key1{t} noset{t}}
}
test "SUNION against non-set should throw error" {
r set key1 x
assert_error "WRONGTYPE*" {r sunion key1 noset}
r set key1{t} x
assert_error "WRONGTYPE*" {r sunion key1{t} noset{t}}
}
test "SINTER should handle non existing key as empty" {
r del set1 set2 set3
r sadd set1 a b c
r sadd set2 b c d
r sinter set1 set2 set3
r del set1{t} set2{t} set3{t}
r sadd set1{t} a b c
r sadd set2{t} b c d
r sinter set1{t} set2{t} set3{t}
} {}
test "SINTER with same integer elements but different encoding" {
r del set1 set2
r sadd set1 1 2 3
r sadd set2 1 2 3 a
r srem set2 a
assert_encoding intset set1
assert_encoding hashtable set2
lsort [r sinter set1 set2]
r del set1{t} set2{t}
r sadd set1{t} 1 2 3
r sadd set2{t} 1 2 3 a
r srem set2{t} a
assert_encoding intset set1{t}
assert_encoding hashtable set2{t}
lsort [r sinter set1{t} set2{t}]
} {1 2 3}
test "SINTERSTORE against non existing keys should delete dstkey" {
r set setres xxx
assert_equal 0 [r sinterstore setres foo111 bar222]
assert_equal 0 [r exists setres]
r set setres{t} xxx
assert_equal 0 [r sinterstore setres{t} foo111{t} bar222{t}]
assert_equal 0 [r exists setres{t}]
}
test "SUNIONSTORE against non existing keys should delete dstkey" {
r set setres xxx
assert_equal 0 [r sunionstore setres foo111 bar222]
assert_equal 0 [r exists setres]
r set setres{t} xxx
assert_equal 0 [r sunionstore setres{t} foo111{t} bar222{t}]
assert_equal 0 [r exists setres{t}]
}
foreach {type contents} {hashtable {a b c} intset {1 2 3}} {
......@@ -555,81 +557,81 @@ start_server {
}
proc setup_move {} {
r del myset3 myset4
create_set myset1 {1 a b}
create_set myset2 {2 3 4}
assert_encoding hashtable myset1
assert_encoding intset myset2
r del myset3{t} myset4{t}
create_set myset1{t} {1 a b}
create_set myset2{t} {2 3 4}
assert_encoding hashtable myset1{t}
assert_encoding intset myset2{t}
}
test "SMOVE basics - from regular set to intset" {
# move a non-integer element to an intset should convert encoding
setup_move
assert_equal 1 [r smove myset1 myset2 a]
assert_equal {1 b} [lsort [r smembers myset1]]
assert_equal {2 3 4 a} [lsort [r smembers myset2]]
assert_encoding hashtable myset2
assert_equal 1 [r smove myset1{t} myset2{t} a]
assert_equal {1 b} [lsort [r smembers myset1{t}]]
assert_equal {2 3 4 a} [lsort [r smembers myset2{t}]]
assert_encoding hashtable myset2{t}
# move an integer element should not convert the encoding
setup_move
assert_equal 1 [r smove myset1 myset2 1]
assert_equal {a b} [lsort [r smembers myset1]]
assert_equal {1 2 3 4} [lsort [r smembers myset2]]
assert_encoding intset myset2
assert_equal 1 [r smove myset1{t} myset2{t} 1]
assert_equal {a b} [lsort [r smembers myset1{t}]]
assert_equal {1 2 3 4} [lsort [r smembers myset2{t}]]
assert_encoding intset myset2{t}
}
test "SMOVE basics - from intset to regular set" {
setup_move
assert_equal 1 [r smove myset2 myset1 2]
assert_equal {1 2 a b} [lsort [r smembers myset1]]
assert_equal {3 4} [lsort [r smembers myset2]]
assert_equal 1 [r smove myset2{t} myset1{t} 2]
assert_equal {1 2 a b} [lsort [r smembers myset1{t}]]
assert_equal {3 4} [lsort [r smembers myset2{t}]]
}
test "SMOVE non existing key" {
setup_move
assert_equal 0 [r smove myset1 myset2 foo]
assert_equal 0 [r smove myset1 myset1 foo]
assert_equal {1 a b} [lsort [r smembers myset1]]
assert_equal {2 3 4} [lsort [r smembers myset2]]
assert_equal 0 [r smove myset1{t} myset2{t} foo]
assert_equal 0 [r smove myset1{t} myset1{t} foo]
assert_equal {1 a b} [lsort [r smembers myset1{t}]]
assert_equal {2 3 4} [lsort [r smembers myset2{t}]]
}
test "SMOVE non existing src set" {
setup_move
assert_equal 0 [r smove noset myset2 foo]
assert_equal {2 3 4} [lsort [r smembers myset2]]
assert_equal 0 [r smove noset{t} myset2{t} foo]
assert_equal {2 3 4} [lsort [r smembers myset2{t}]]
}
test "SMOVE from regular set to non existing destination set" {
setup_move
assert_equal 1 [r smove myset1 myset3 a]
assert_equal {1 b} [lsort [r smembers myset1]]
assert_equal {a} [lsort [r smembers myset3]]
assert_encoding hashtable myset3
assert_equal 1 [r smove myset1{t} myset3{t} a]
assert_equal {1 b} [lsort [r smembers myset1{t}]]
assert_equal {a} [lsort [r smembers myset3{t}]]
assert_encoding hashtable myset3{t}
}
test "SMOVE from intset to non existing destination set" {
setup_move
assert_equal 1 [r smove myset2 myset3 2]
assert_equal {3 4} [lsort [r smembers myset2]]
assert_equal {2} [lsort [r smembers myset3]]
assert_encoding intset myset3
assert_equal 1 [r smove myset2{t} myset3{t} 2]
assert_equal {3 4} [lsort [r smembers myset2{t}]]
assert_equal {2} [lsort [r smembers myset3{t}]]
assert_encoding intset myset3{t}
}
test "SMOVE wrong src key type" {
r set x 10
assert_error "WRONGTYPE*" {r smove x myset2 foo}
r set x{t} 10
assert_error "WRONGTYPE*" {r smove x{t} myset2{t} foo}
}
test "SMOVE wrong dst key type" {
r set x 10
assert_error "WRONGTYPE*" {r smove myset2 x foo}
r set x{t} 10
assert_error "WRONGTYPE*" {r smove myset2{t} x{t} foo}
}
test "SMOVE with identical source and destination" {
r del set
r sadd set a b c
r smove set set b
lsort [r smembers set]
r del set{t}
r sadd set{t} a b c
r smove set{t} set{t} b
lsort [r smembers set{t}]
} {a b c}
tags {slow} {
......
......@@ -214,24 +214,24 @@ start_server {
}
test {RENAME can unblock XREADGROUP with data} {
r del mystream
r XGROUP CREATE mystream mygroup $ MKSTREAM
r del mystream{t}
r XGROUP CREATE mystream{t} mygroup $ MKSTREAM
set rd [redis_deferring_client]
$rd XREADGROUP GROUP mygroup Alice BLOCK 0 STREAMS mystream ">"
r XGROUP CREATE mystream2 mygroup $ MKSTREAM
r XADD mystream2 100 f1 v1
r RENAME mystream2 mystream
assert_equal "{mystream {{100-0 {f1 v1}}}}" [$rd read] ;# mystream2 had mygroup before RENAME
$rd XREADGROUP GROUP mygroup Alice BLOCK 0 STREAMS mystream{t} ">"
r XGROUP CREATE mystream2{t} mygroup $ MKSTREAM
r XADD mystream2{t} 100 f1 v1
r RENAME mystream2{t} mystream{t}
assert_equal "{mystream{t} {{100-0 {f1 v1}}}}" [$rd read] ;# mystream2{t} had mygroup before RENAME
}
test {RENAME can unblock XREADGROUP with -NOGROUP} {
r del mystream
r XGROUP CREATE mystream mygroup $ MKSTREAM
r del mystream{t}
r XGROUP CREATE mystream{t} mygroup $ MKSTREAM
set rd [redis_deferring_client]
$rd XREADGROUP GROUP mygroup Alice BLOCK 0 STREAMS mystream ">"
r XADD mystream2 100 f1 v1
r RENAME mystream2 mystream
assert_error "*NOGROUP*" {$rd read} ;# mystream2 didn't have mygroup before RENAME
$rd XREADGROUP GROUP mygroup Alice BLOCK 0 STREAMS mystream{t} ">"
r XADD mystream2{t} 100 f1 v1
r RENAME mystream2{t} mystream{t}
assert_error "*NOGROUP*" {$rd read} ;# mystream2{t} didn't have mygroup before RENAME
}
test {XCLAIM can claim PEL items from another consumer} {
......@@ -548,7 +548,7 @@ start_server {
assert_error "*NOGROUP*" {r XGROUP CREATECONSUMER mystream mygroup consumer}
}
start_server {tags {"stream"} overrides {appendonly yes aof-use-rdb-preamble no appendfsync always}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes aof-use-rdb-preamble no appendfsync always}} {
test {XREADGROUP with NOACK creates consumer} {
r del mystream
r XGROUP CREATE mystream mygroup $ MKSTREAM
......@@ -596,7 +596,7 @@ start_server {
}
}
start_server {} {
start_server {tags {"external:skip"}} {
set master [srv -1 client]
set master_host [srv -1 host]
set master_port [srv -1 port]
......@@ -647,7 +647,7 @@ start_server {
}
}
start_server {tags {"stream"} overrides {appendonly yes aof-use-rdb-preamble no}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes aof-use-rdb-preamble no}} {
test {Empty stream with no lastid can be rewrite into AOF correctly} {
r XGROUP CREATE mystream group-name $ MKSTREAM
assert {[dict get [r xinfo stream mystream] length] == 0}
......
......@@ -117,6 +117,7 @@ start_server {
test {XADD with MAXLEN option and the '~' argument} {
r DEL mystream
r config set stream-node-max-entries 100
for {set j 0} {$j < 1000} {incr j} {
if {rand() < 0.9} {
r XADD mystream MAXLEN ~ 555 * xitem $j
......@@ -172,19 +173,23 @@ start_server {
assert_equal [r XRANGE mystream - +] {{3-0 {f v}} {4-0 {f v}} {5-0 {f v}}}
}
test {XADD mass insertion and XLEN} {
r DEL mystream
proc insert_into_stream_key {key {count 10000}} {
r multi
for {set j 0} {$j < 10000} {incr j} {
for {set j 0} {$j < $count} {incr j} {
# From time to time insert a field with a different set
# of fields in order to stress the stream compression code.
if {rand() < 0.9} {
r XADD mystream * item $j
r XADD $key * item $j
} else {
r XADD mystream * item $j otherfield foo
r XADD $key * item $j otherfield foo
}
}
r exec
}
test {XADD mass insertion and XLEN} {
r DEL mystream
insert_into_stream_key mystream
set items [r XRANGE mystream - +]
for {set j 0} {$j < 10000} {incr j} {
......@@ -267,32 +272,33 @@ start_server {
}
test {Non blocking XREAD with empty streams} {
set res [r XREAD STREAMS s1 s2 0-0 0-0]
set res [r XREAD STREAMS s1{t} s2{t} 0-0 0-0]
assert {$res eq {}}
}
test {XREAD with non empty second stream} {
set res [r XREAD COUNT 1 STREAMS nostream mystream 0-0 0-0]
assert {[lindex $res 0 0] eq {mystream}}
insert_into_stream_key mystream{t}
set res [r XREAD COUNT 1 STREAMS nostream{t} mystream{t} 0-0 0-0]
assert {[lindex $res 0 0] eq {mystream{t}}}
assert {[lrange [lindex $res 0 1 0 1] 0 1] eq {item 0}}
}
test {Blocking XREAD waiting new data} {
r XADD s2 * old abcd1234
r XADD s2{t} * old abcd1234
set rd [redis_deferring_client]
$rd XREAD BLOCK 20000 STREAMS s1 s2 s3 $ $ $
r XADD s2 * new abcd1234
$rd XREAD BLOCK 20000 STREAMS s1{t} s2{t} s3{t} $ $ $
r XADD s2{t} * new abcd1234
set res [$rd read]
assert {[lindex $res 0 0] eq {s2}}
assert {[lindex $res 0 0] eq {s2{t}}}
assert {[lindex $res 0 1 0 1] eq {new abcd1234}}
}
test {Blocking XREAD waiting old data} {
set rd [redis_deferring_client]
$rd XREAD BLOCK 20000 STREAMS s1 s2 s3 $ 0-0 $
r XADD s2 * foo abcd1234
$rd XREAD BLOCK 20000 STREAMS s1{t} s2{t} s3{t} $ 0-0 $
r XADD s2{t} * foo abcd1234
set res [$rd read]
assert {[lindex $res 0 0] eq {s2}}
assert {[lindex $res 0 0] eq {s2{t}}}
assert {[lindex $res 0 1 0 1] eq {old abcd1234}}
}
......@@ -410,12 +416,13 @@ start_server {
}
test {XRANGE fuzzing} {
set items [r XRANGE mystream{t} - +]
set low_id [lindex $items 0 0]
set high_id [lindex $items end 0]
for {set j 0} {$j < 100} {incr j} {
set start [streamRandomID $low_id $high_id]
set end [streamRandomID $low_id $high_id]
set range [r xrange mystream $start $end]
set range [r xrange mystream{t} $start $end]
set tcl_range [streamSimulateXRANGE $items $start $end]
if {$range ne $tcl_range} {
puts "*** WARNING *** - XRANGE fuzzing mismatch: $start - $end"
......@@ -546,7 +553,7 @@ start_server {
}
}
start_server {tags {"stream"} overrides {appendonly yes}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes}} {
test {XADD with MAXLEN > xlen can propagate correctly} {
for {set j 0} {$j < 100} {incr j} {
r XADD mystream * xitem v
......@@ -561,7 +568,7 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
}
}
start_server {tags {"stream"} overrides {appendonly yes}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes}} {
test {XADD with MINID > lastid can propagate correctly} {
for {set j 0} {$j < 100} {incr j} {
set id [expr {$j+1}]
......@@ -577,7 +584,7 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
}
}
start_server {tags {"stream"} overrides {appendonly yes}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes stream-node-max-entries 100}} {
test {XADD with ~ MAXLEN can propagate correctly} {
for {set j 0} {$j < 100} {incr j} {
r XADD mystream * xitem v
......@@ -593,7 +600,7 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
}
}
start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries 10}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes stream-node-max-entries 10}} {
test {XADD with ~ MAXLEN and LIMIT can propagate correctly} {
for {set j 0} {$j < 100} {incr j} {
r XADD mystream * xitem v
......@@ -607,7 +614,7 @@ start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries
}
}
start_server {tags {"stream"} overrides {appendonly yes}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes stream-node-max-entries 100}} {
test {XADD with ~ MINID can propagate correctly} {
for {set j 0} {$j < 100} {incr j} {
set id [expr {$j+1}]
......@@ -624,7 +631,7 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
}
}
start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries 10}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes stream-node-max-entries 10}} {
test {XADD with ~ MINID and LIMIT can propagate correctly} {
for {set j 0} {$j < 100} {incr j} {
set id [expr {$j+1}]
......@@ -639,7 +646,7 @@ start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries
}
}
start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries 10}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes stream-node-max-entries 10}} {
test {XTRIM with ~ MAXLEN can propagate correctly} {
for {set j 0} {$j < 100} {incr j} {
r XADD mystream * xitem v
......@@ -678,7 +685,7 @@ start_server {tags {"stream xsetid"}} {
} {ERR no such key}
}
start_server {tags {"stream"} overrides {appendonly yes aof-use-rdb-preamble no}} {
start_server {tags {"stream needs:debug"} overrides {appendonly yes aof-use-rdb-preamble no}} {
test {Empty stream can be rewrite into AOF correctly} {
r XADD mystream MAXLEN 0 * a b
assert {[dict get [r xinfo stream mystream] length] == 0}
......
......@@ -173,7 +173,7 @@ start_server {tags {"string"}} {
{set foo bar}
{del foo}
}
}
} {} {needs:repl}
test {GETEX without argument does not propagate to replica} {
set repl [attach_to_replication_stream]
......@@ -185,23 +185,23 @@ start_server {tags {"string"}} {
{set foo bar}
{del foo}
}
}
} {} {needs:repl}
test {MGET} {
r flushdb
r set foo BAR
r set bar FOO
r mget foo bar
r set foo{t} BAR
r set bar{t} FOO
r mget foo{t} bar{t}
} {BAR FOO}
test {MGET against non existing key} {
r mget foo baazz bar
r mget foo{t} baazz{t} bar{t}
} {BAR {} FOO}
test {MGET against non-string key} {
r sadd myset ciao
r sadd myset bau
r mget foo baazz bar myset
r sadd myset{t} ciao
r sadd myset{t} bau
r mget foo{t} baazz{t} bar{t} myset{t}
} {BAR {} FOO {}}
test {GETSET (set new value)} {
......@@ -215,21 +215,21 @@ start_server {tags {"string"}} {
} {bar xyz}
test {MSET base case} {
r mset x 10 y "foo bar" z "x x x x x x x\n\n\r\n"
r mget x y z
r mset x{t} 10 y{t} "foo bar" z{t} "x x x x x x x\n\n\r\n"
r mget x{t} y{t} z{t}
} [list 10 {foo bar} "x x x x x x x\n\n\r\n"]
test {MSET wrong number of args} {
catch {r mset x 10 y "foo bar" z} err
catch {r mset x{t} 10 y{t} "foo bar" z{t}} err
format $err
} {*wrong number*}
test {MSETNX with already existent key} {
list [r msetnx x1 xxx y2 yyy x 20] [r exists x1] [r exists y2]
list [r msetnx x1{t} xxx y2{t} yyy x{t} 20] [r exists x1{t}] [r exists y2{t}]
} {0 0 0}
test {MSETNX with not existing keys} {
list [r msetnx x1 xxx y2 yyy] [r get x1] [r get y2]
list [r msetnx x1{t} xxx y2{t} yyy] [r get x1{t}] [r get y2{t}]
} {1 xxx yyy}
test "STRLEN against non-existing key" {
......@@ -582,20 +582,20 @@ start_server {tags {"string"}} {
} [string length $rnalcs]
test {LCS with KEYS option} {
r set virus1 $rna1
r set virus2 $rna2
r STRALGO LCS KEYS virus1 virus2
r set virus1{t} $rna1
r set virus2{t} $rna2
r STRALGO LCS KEYS virus1{t} virus2{t}
} $rnalcs
test {LCS indexes} {
dict get [r STRALGO LCS IDX KEYS virus1 virus2] matches
dict get [r STRALGO LCS IDX KEYS virus1{t} virus2{t}] matches
} {{{238 238} {239 239}} {{236 236} {238 238}} {{229 230} {236 237}} {{224 224} {235 235}} {{1 222} {13 234}}}
test {LCS indexes with match len} {
dict get [r STRALGO LCS IDX KEYS virus1 virus2 WITHMATCHLEN] matches
dict get [r STRALGO LCS IDX KEYS virus1{t} virus2{t} WITHMATCHLEN] matches
} {{{238 238} {239 239} 1} {{236 236} {238 238} 1} {{229 230} {236 237} 2} {{224 224} {235 235} 1} {{1 222} {13 234} 222}}
test {LCS indexes with match len and minimum match len} {
dict get [r STRALGO LCS IDX KEYS virus1 virus2 WITHMATCHLEN MINMATCHLEN 5] matches
dict get [r STRALGO LCS IDX KEYS virus1{t} virus2{t} WITHMATCHLEN MINMATCHLEN 5] matches
} {{{1 222} {13 234} 222}}
}
......@@ -642,9 +642,9 @@ start_server {tags {"zset"}} {
}
test "ZUNIONSTORE against non-existing key doesn't set destination - $encoding" {
r del zseta
assert_equal 0 [r zunionstore dst_key 1 zseta]
assert_equal 0 [r exists dst_key]
r del zseta{t}
assert_equal 0 [r zunionstore dst_key{t} 1 zseta{t}]
assert_equal 0 [r exists dst_key{t}]
}
test "ZUNION/ZINTER/ZDIFF against non-existing key - $encoding" {
......@@ -655,214 +655,214 @@ start_server {tags {"zset"}} {
}
test "ZUNIONSTORE with empty set - $encoding" {
r del zseta zsetb
r zadd zseta 1 a
r zadd zseta 2 b
r zunionstore zsetc 2 zseta zsetb
r zrange zsetc 0 -1 withscores
r del zseta{t} zsetb{t}
r zadd zseta{t} 1 a
r zadd zseta{t} 2 b
r zunionstore zsetc{t} 2 zseta{t} zsetb{t}
r zrange zsetc{t} 0 -1 withscores
} {a 1 b 2}
test "ZUNION/ZINTER/ZDIFF with empty set - $encoding" {
r del zseta zsetb
r zadd zseta 1 a
r zadd zseta 2 b
assert_equal {a 1 b 2} [r zunion 2 zseta zsetb withscores]
assert_equal {} [r zinter 2 zseta zsetb withscores]
assert_equal {a 1 b 2} [r zdiff 2 zseta zsetb withscores]
r del zseta{t} zsetb{t}
r zadd zseta{t} 1 a
r zadd zseta{t} 2 b
assert_equal {a 1 b 2} [r zunion 2 zseta{t} zsetb{t} withscores]
assert_equal {} [r zinter 2 zseta{t} zsetb{t} withscores]
assert_equal {a 1 b 2} [r zdiff 2 zseta{t} zsetb{t} withscores]
}
test "ZUNIONSTORE basics - $encoding" {
r del zseta zsetb zsetc
r zadd zseta 1 a
r zadd zseta 2 b
r zadd zseta 3 c
r zadd zsetb 1 b
r zadd zsetb 2 c
r zadd zsetb 3 d
r del zseta{t} zsetb{t} zsetc{t}
r zadd zseta{t} 1 a
r zadd zseta{t} 2 b
r zadd zseta{t} 3 c
r zadd zsetb{t} 1 b
r zadd zsetb{t} 2 c
r zadd zsetb{t} 3 d
assert_equal 4 [r zunionstore zsetc 2 zseta zsetb]
assert_equal {a 1 b 3 d 3 c 5} [r zrange zsetc 0 -1 withscores]
assert_equal 4 [r zunionstore zsetc{t} 2 zseta{t} zsetb{t}]
assert_equal {a 1 b 3 d 3 c 5} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZUNION/ZINTER/ZDIFF with integer members - $encoding" {
r del zsetd zsetf
r zadd zsetd 1 1
r zadd zsetd 2 2
r zadd zsetd 3 3
r zadd zsetf 1 1
r zadd zsetf 3 3
r zadd zsetf 4 4
r del zsetd{t} zsetf{t}
r zadd zsetd{t} 1 1
r zadd zsetd{t} 2 2
r zadd zsetd{t} 3 3
r zadd zsetf{t} 1 1
r zadd zsetf{t} 3 3
r zadd zsetf{t} 4 4
assert_equal {1 2 2 2 4 4 3 6} [r zunion 2 zsetd zsetf withscores]
assert_equal {1 2 3 6} [r zinter 2 zsetd zsetf withscores]
assert_equal {2 2} [r zdiff 2 zsetd zsetf withscores]
assert_equal {1 2 2 2 4 4 3 6} [r zunion 2 zsetd{t} zsetf{t} withscores]
assert_equal {1 2 3 6} [r zinter 2 zsetd{t} zsetf{t} withscores]
assert_equal {2 2} [r zdiff 2 zsetd{t} zsetf{t} withscores]
}
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]
assert_equal 4 [r zunionstore zsetc{t} 2 zseta{t} zsetb{t} weights 2 3]
assert_equal {a 2 b 7 d 9 c 12} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZUNION with weights - $encoding" {
assert_equal {a 2 b 7 d 9 c 12} [r zunion 2 zseta zsetb weights 2 3 withscores]
assert_equal {b 7 c 12} [r zinter 2 zseta zsetb weights 2 3 withscores]
assert_equal {a 2 b 7 d 9 c 12} [r zunion 2 zseta{t} zsetb{t} weights 2 3 withscores]
assert_equal {b 7 c 12} [r zinter 2 zseta{t} zsetb{t} weights 2 3 withscores]
}
test "ZUNIONSTORE with a regular set and weights - $encoding" {
r del seta
r sadd seta a
r sadd seta b
r sadd seta c
r del seta{t}
r sadd seta{t} a
r sadd seta{t} b
r sadd seta{t} c
assert_equal 4 [r zunionstore zsetc 2 seta zsetb weights 2 3]
assert_equal {a 2 b 5 c 8 d 9} [r zrange zsetc 0 -1 withscores]
assert_equal 4 [r zunionstore zsetc{t} 2 seta{t} zsetb{t} weights 2 3]
assert_equal {a 2 b 5 c 8 d 9} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZUNIONSTORE with AGGREGATE MIN - $encoding" {
assert_equal 4 [r zunionstore zsetc 2 zseta zsetb aggregate min]
assert_equal {a 1 b 1 c 2 d 3} [r zrange zsetc 0 -1 withscores]
assert_equal 4 [r zunionstore zsetc{t} 2 zseta{t} zsetb{t} aggregate min]
assert_equal {a 1 b 1 c 2 d 3} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZUNION/ZINTER with AGGREGATE MIN - $encoding" {
assert_equal {a 1 b 1 c 2 d 3} [r zunion 2 zseta zsetb aggregate min withscores]
assert_equal {b 1 c 2} [r zinter 2 zseta zsetb aggregate min withscores]
assert_equal {a 1 b 1 c 2 d 3} [r zunion 2 zseta{t} zsetb{t} aggregate min withscores]
assert_equal {b 1 c 2} [r zinter 2 zseta{t} zsetb{t} aggregate min withscores]
}
test "ZUNIONSTORE with AGGREGATE MAX - $encoding" {
assert_equal 4 [r zunionstore zsetc 2 zseta zsetb aggregate max]
assert_equal {a 1 b 2 c 3 d 3} [r zrange zsetc 0 -1 withscores]
assert_equal 4 [r zunionstore zsetc{t} 2 zseta{t} zsetb{t} aggregate max]
assert_equal {a 1 b 2 c 3 d 3} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZUNION/ZINTER with AGGREGATE MAX - $encoding" {
assert_equal {a 1 b 2 c 3 d 3} [r zunion 2 zseta zsetb aggregate max withscores]
assert_equal {b 2 c 3} [r zinter 2 zseta zsetb aggregate max withscores]
assert_equal {a 1 b 2 c 3 d 3} [r zunion 2 zseta{t} zsetb{t} aggregate max withscores]
assert_equal {b 2 c 3} [r zinter 2 zseta{t} zsetb{t} aggregate max withscores]
}
test "ZINTERSTORE basics - $encoding" {
assert_equal 2 [r zinterstore zsetc 2 zseta zsetb]
assert_equal {b 3 c 5} [r zrange zsetc 0 -1 withscores]
assert_equal 2 [r zinterstore zsetc{t} 2 zseta{t} zsetb{t}]
assert_equal {b 3 c 5} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZINTER basics - $encoding" {
assert_equal {b 3 c 5} [r zinter 2 zseta zsetb withscores]
assert_equal {b 3 c 5} [r zinter 2 zseta{t} zsetb{t} withscores]
}
test "ZINTER RESP3 - $encoding" {
r hello 3
assert_equal {{b 3.0} {c 5.0}} [r zinter 2 zseta zsetb withscores]
}
assert_equal {{b 3.0} {c 5.0}} [r zinter 2 zseta{t} zsetb{t} withscores]
r hello 2
}
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]
assert_equal 2 [r zinterstore zsetc{t} 2 zseta{t} zsetb{t} weights 2 3]
assert_equal {b 7 c 12} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZINTER with weights - $encoding" {
assert_equal {b 7 c 12} [r zinter 2 zseta zsetb weights 2 3 withscores]
assert_equal {b 7 c 12} [r zinter 2 zseta{t} zsetb{t} weights 2 3 withscores]
}
test "ZINTERSTORE with a regular set and weights - $encoding" {
r del seta
r sadd seta a
r sadd seta b
r sadd seta c
assert_equal 2 [r zinterstore zsetc 2 seta zsetb weights 2 3]
assert_equal {b 5 c 8} [r zrange zsetc 0 -1 withscores]
r del seta{t}
r sadd seta{t} a
r sadd seta{t} b
r sadd seta{t} c
assert_equal 2 [r zinterstore zsetc{t} 2 seta{t} zsetb{t} weights 2 3]
assert_equal {b 5 c 8} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZINTERSTORE with AGGREGATE MIN - $encoding" {
assert_equal 2 [r zinterstore zsetc 2 zseta zsetb aggregate min]
assert_equal {b 1 c 2} [r zrange zsetc 0 -1 withscores]
assert_equal 2 [r zinterstore zsetc{t} 2 zseta{t} zsetb{t} aggregate min]
assert_equal {b 1 c 2} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZINTERSTORE with AGGREGATE MAX - $encoding" {
assert_equal 2 [r zinterstore zsetc 2 zseta zsetb aggregate max]
assert_equal {b 2 c 3} [r zrange zsetc 0 -1 withscores]
assert_equal 2 [r zinterstore zsetc{t} 2 zseta{t} zsetb{t} aggregate max]
assert_equal {b 2 c 3} [r zrange zsetc{t} 0 -1 withscores]
}
foreach cmd {ZUNIONSTORE ZINTERSTORE} {
test "$cmd with +inf/-inf scores - $encoding" {
r del zsetinf1 zsetinf2
r del zsetinf1{t} zsetinf2{t}
r zadd zsetinf1 +inf key
r zadd zsetinf2 +inf key
r $cmd zsetinf3 2 zsetinf1 zsetinf2
assert_equal inf [r zscore zsetinf3 key]
r zadd zsetinf1{t} +inf key
r zadd zsetinf2{t} +inf key
r $cmd zsetinf3{t} 2 zsetinf1{t} zsetinf2{t}
assert_equal inf [r zscore zsetinf3{t} key]
r zadd zsetinf1 -inf key
r zadd zsetinf2 +inf key
r $cmd zsetinf3 2 zsetinf1 zsetinf2
assert_equal 0 [r zscore zsetinf3 key]
r zadd zsetinf1{t} -inf key
r zadd zsetinf2{t} +inf key
r $cmd zsetinf3{t} 2 zsetinf1{t} zsetinf2{t}
assert_equal 0 [r zscore zsetinf3{t} key]
r zadd zsetinf1 +inf key
r zadd zsetinf2 -inf key
r $cmd zsetinf3 2 zsetinf1 zsetinf2
assert_equal 0 [r zscore zsetinf3 key]
r zadd zsetinf1{t} +inf key
r zadd zsetinf2{t} -inf key
r $cmd zsetinf3{t} 2 zsetinf1{t} zsetinf2{t}
assert_equal 0 [r zscore zsetinf3{t} key]
r zadd zsetinf1 -inf key
r zadd zsetinf2 -inf key
r $cmd zsetinf3 2 zsetinf1 zsetinf2
assert_equal -inf [r zscore zsetinf3 key]
r zadd zsetinf1{t} -inf key
r zadd zsetinf2{t} -inf key
r $cmd zsetinf3{t} 2 zsetinf1{t} zsetinf2{t}
assert_equal -inf [r zscore zsetinf3{t} key]
}
test "$cmd with NaN weights - $encoding" {
r del zsetinf1 zsetinf2
r del zsetinf1{t} zsetinf2{t}
r zadd zsetinf1 1.0 key
r zadd zsetinf2 1.0 key
r zadd zsetinf1{t} 1.0 key
r zadd zsetinf2{t} 1.0 key
assert_error "*weight*not*float*" {
r $cmd zsetinf3 2 zsetinf1 zsetinf2 weights nan nan
r $cmd zsetinf3{t} 2 zsetinf1{t} zsetinf2{t} weights nan nan
}
}
}
test "ZDIFFSTORE basics - $encoding" {
assert_equal 1 [r zdiffstore zsetc 2 zseta zsetb]
assert_equal {a 1} [r zrange zsetc 0 -1 withscores]
assert_equal 1 [r zdiffstore zsetc{t} 2 zseta{t} zsetb{t}]
assert_equal {a 1} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZDIFF basics - $encoding" {
assert_equal {a 1} [r zdiff 2 zseta zsetb withscores]
assert_equal {a 1} [r zdiff 2 zseta{t} zsetb{t} withscores]
}
test "ZDIFFSTORE with a regular set - $encoding" {
r del seta
r sadd seta a
r sadd seta b
r sadd seta c
assert_equal 1 [r zdiffstore zsetc 2 seta zsetb]
assert_equal {a 1} [r zrange zsetc 0 -1 withscores]
r del seta{t}
r sadd seta{t} a
r sadd seta{t} b
r sadd seta{t} c
assert_equal 1 [r zdiffstore zsetc{t} 2 seta{t} zsetb{t}]
assert_equal {a 1} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZDIFF subtracting set from itself - $encoding" {
assert_equal 0 [r zdiffstore zsetc 2 zseta zseta]
assert_equal {} [r zrange zsetc 0 -1 withscores]
assert_equal 0 [r zdiffstore zsetc{t} 2 zseta{t} zseta{t}]
assert_equal {} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZDIFF algorithm 1 - $encoding" {
r del zseta zsetb zsetc
r zadd zseta 1 a
r zadd zseta 2 b
r zadd zseta 3 c
r zadd zsetb 1 b
r zadd zsetb 2 c
r zadd zsetb 3 d
assert_equal 1 [r zdiffstore zsetc 2 zseta zsetb]
assert_equal {a 1} [r zrange zsetc 0 -1 withscores]
r del zseta{t} zsetb{t} zsetc{t}
r zadd zseta{t} 1 a
r zadd zseta{t} 2 b
r zadd zseta{t} 3 c
r zadd zsetb{t} 1 b
r zadd zsetb{t} 2 c
r zadd zsetb{t} 3 d
assert_equal 1 [r zdiffstore zsetc{t} 2 zseta{t} zsetb{t}]
assert_equal {a 1} [r zrange zsetc{t} 0 -1 withscores]
}
test "ZDIFF algorithm 2 - $encoding" {
r del zseta zsetb zsetc zsetd zsete
r zadd zseta 1 a
r zadd zseta 2 b
r zadd zseta 3 c
r zadd zseta 5 e
r zadd zsetb 1 b
r zadd zsetc 1 c
r zadd zsetd 1 d
assert_equal 2 [r zdiffstore zsete 4 zseta zsetb zsetc zsetd]
assert_equal {a 1 e 5} [r zrange zsete 0 -1 withscores]
r del zseta{t} zsetb{t} zsetc{t} zsetd{t} zsete{t}
r zadd zseta{t} 1 a
r zadd zseta{t} 2 b
r zadd zseta{t} 3 c
r zadd zseta{t} 5 e
r zadd zsetb{t} 1 b
r zadd zsetc{t} 1 c
r zadd zsetd{t} 1 d
assert_equal 2 [r zdiffstore zsete{t} 4 zseta{t} zsetb{t} zsetc{t} zsetd{t}]
assert_equal {a 1 e 5} [r zrange zsete{t} 0 -1 withscores]
}
test "ZDIFF fuzzing - $encoding" {
......@@ -873,11 +873,11 @@ start_server {tags {"zset"}} {
set num_sets [expr {[randomInt 10]+1}]
for {set i 0} {$i < $num_sets} {incr i} {
set num_elements [randomInt 100]
r del zset_$i
lappend args zset_$i
r del zset_$i{t}
lappend args zset_$i{t}
while {$num_elements} {
set ele [randomValue]
r zadd zset_$i [randomInt 100] $ele
r zadd zset_$i{t} [randomInt 100] $ele
if {$i == 0} {
set s($ele) x
} else {
......@@ -906,7 +906,10 @@ start_server {tags {"zset"}} {
}
test "ZPOP with count - $encoding" {
r del z1 z2 z3 foo
r del z1
r del z2
r del z3
r del foo
r set foo bar
assert_equal {} [r zpopmin z1 2]
assert_error "*WRONGTYPE*" {r zpopmin foo 2}
......@@ -930,34 +933,34 @@ start_server {tags {"zset"}} {
test "BZPOP with multiple existing sorted sets - $encoding" {
set rd [redis_deferring_client]
create_zset z1 {0 a 1 b 2 c}
create_zset z2 {3 d 4 e 5 f}
create_zset z1{t} {0 a 1 b 2 c}
create_zset z2{t} {3 d 4 e 5 f}
$rd bzpopmin z1 z2 5
assert_equal {z1 a 0} [$rd read]
$rd bzpopmax z1 z2 5
assert_equal {z1 c 2} [$rd read]
assert_equal 1 [r zcard z1]
assert_equal 3 [r zcard z2]
$rd bzpopmin z1{t} z2{t} 5
assert_equal {z1{t} a 0} [$rd read]
$rd bzpopmax z1{t} z2{t} 5
assert_equal {z1{t} c 2} [$rd read]
assert_equal 1 [r zcard z1{t}]
assert_equal 3 [r zcard z2{t}]
$rd bzpopmax z2 z1 5
assert_equal {z2 f 5} [$rd read]
$rd bzpopmin z2 z1 5
assert_equal {z2 d 3} [$rd read]
assert_equal 1 [r zcard z1]
assert_equal 1 [r zcard z2]
$rd bzpopmax z2{t} z1{t} 5
assert_equal {z2{t} f 5} [$rd read]
$rd bzpopmin z2{t} z1{t} 5
assert_equal {z2{t} d 3} [$rd read]
assert_equal 1 [r zcard z1{t}]
assert_equal 1 [r zcard z2{t}]
}
test "BZPOP second sorted set has members - $encoding" {
set rd [redis_deferring_client]
r del z1
create_zset z2 {3 d 4 e 5 f}
$rd bzpopmax z1 z2 5
assert_equal {z2 f 5} [$rd read]
$rd bzpopmin z2 z1 5
assert_equal {z2 d 3} [$rd read]
assert_equal 0 [r zcard z1]
assert_equal 1 [r zcard z2]
r del z1{t}
create_zset z2{t} {3 d 4 e 5 f}
$rd bzpopmax z1{t} z2{t} 5
assert_equal {z2{t} f 5} [$rd read]
$rd bzpopmin z2{t} z1{t} 5
assert_equal {z2{t} d 3} [$rd read]
assert_equal 0 [r zcard z1{t}]
assert_equal 1 [r zcard z2{t}]
}
r config set zset-max-ziplist-entries $original_max_entries
......@@ -968,52 +971,52 @@ start_server {tags {"zset"}} {
basics skiplist
test {ZINTERSTORE regression with two sets, intset+hashtable} {
r del seta setb setc
r sadd set1 a
r sadd set2 10
r zinterstore set3 2 set1 set2
r del seta{t} setb{t} setc{t}
r sadd set1{t} a
r sadd set2{t} 10
r zinterstore set3{t} 2 set1{t} set2{t}
} {0}
test {ZUNIONSTORE regression, should not create NaN in scores} {
r zadd z -inf neginf
r zunionstore out 1 z weights 0
r zrange out 0 -1 withscores
r zadd z{t} -inf neginf
r zunionstore out{t} 1 z{t} weights 0
r zrange out{t} 0 -1 withscores
} {neginf 0}
test {ZINTERSTORE #516 regression, mixed sets and ziplist zsets} {
r sadd one 100 101 102 103
r sadd two 100 200 201 202
r zadd three 1 500 1 501 1 502 1 503 1 100
r zinterstore to_here 3 one two three WEIGHTS 0 0 1
r zrange to_here 0 -1
r sadd one{t} 100 101 102 103
r sadd two{t} 100 200 201 202
r zadd three{t} 1 500 1 501 1 502 1 503 1 100
r zinterstore to_here{t} 3 one{t} two{t} three{t} WEIGHTS 0 0 1
r zrange to_here{t} 0 -1
} {100}
test {ZUNIONSTORE result is sorted} {
# Create two sets with common and not common elements, perform
# the UNION, check that elements are still sorted.
r del one two dest
set cmd1 [list r zadd one]
set cmd2 [list r zadd two]
r del one{t} two{t} dest{t}
set cmd1 [list r zadd one{t}]
set cmd2 [list r zadd two{t}]
for {set j 0} {$j < 1000} {incr j} {
lappend cmd1 [expr rand()] [randomInt 1000]
lappend cmd2 [expr rand()] [randomInt 1000]
}
{*}$cmd1
{*}$cmd2
assert {[r zcard one] > 100}
assert {[r zcard two] > 100}
r zunionstore dest 2 one two
assert {[r zcard one{t}] > 100}
assert {[r zcard two{t}] > 100}
r zunionstore dest{t} 2 one{t} two{t}
set oldscore 0
foreach {ele score} [r zrange dest 0 -1 withscores] {
foreach {ele score} [r zrange dest{t} 0 -1 withscores] {
assert {$score >= $oldscore}
set oldscore $score
}
}
test "ZUNIONSTORE/ZINTERSTORE/ZDIFFSTORE error if using WITHSCORES " {
assert_error "*ERR*syntax*" {r zunionstore foo 2 zsetd zsetf withscores}
assert_error "*ERR*syntax*" {r zinterstore foo 2 zsetd zsetf withscores}
assert_error "*ERR*syntax*" {r zdiffstore foo 2 zsetd zsetf withscores}
assert_error "*ERR*syntax*" {r zunionstore foo{t} 2 zsetd{t} zsetf{t} withscores}
assert_error "*ERR*syntax*" {r zinterstore foo{t} 2 zsetd{t} zsetf{t} withscores}
assert_error "*ERR*syntax*" {r zdiffstore foo{t} 2 zsetd{t} zsetf{t} withscores}
}
test {ZMSCORE retrieve} {
......@@ -1119,7 +1122,7 @@ start_server {tags {"zset"}} {
for {set i 0} {$i < $elements} {incr i} {
assert_equal [lindex $aux $i] [r zscore zscoretest $i]
}
}
} {} {needs:debug}
test "ZSET sorting stresser - $encoding" {
set delta 0
......@@ -1318,16 +1321,16 @@ start_server {tags {"zset"}} {
test "ZREMRANGEBYLEX fuzzy test, 100 ranges in $elements element sorted set - $encoding" {
set lexset {}
r del zset zsetcopy
r del zset{t} zsetcopy{t}
for {set j 0} {$j < $elements} {incr j} {
set e [randstring 0 30 alpha]
lappend lexset $e
r zadd zset 0 $e
r zadd zset{t} 0 $e
}
set lexset [lsort -unique $lexset]
for {set j 0} {$j < 100} {incr j} {
# Copy...
r zunionstore zsetcopy 1 zset
r zunionstore zsetcopy{t} 1 zset{t}
set lexsetcopy $lexset
set min [randstring 0 30 alpha]
......@@ -1338,13 +1341,13 @@ start_server {tags {"zset"}} {
if {$maxinc} {set cmax "\[$max"} else {set cmax "($max"}
# Make sure data is the same in both sides
assert {[r zrange zset 0 -1] eq $lexset}
assert {[r zrange zset{t} 0 -1] eq $lexset}
# Get the range we are going to remove
set torem [r zrangebylex zset $cmin $cmax]
set toremlen [r zlexcount zset $cmin $cmax]
r zremrangebylex zsetcopy $cmin $cmax
set output [r zrange zsetcopy 0 -1]
set torem [r zrangebylex zset{t} $cmin $cmax]
set toremlen [r zlexcount zset{t} $cmin $cmax]
r zremrangebylex zsetcopy{t} $cmin $cmax
set output [r zrange zsetcopy{t} 0 -1]
# Remove the range with Tcl from the original list
if {$toremlen} {
......@@ -1434,23 +1437,23 @@ start_server {tags {"zset"}} {
test "BZPOPMIN with same key multiple times should work" {
set rd [redis_deferring_client]
r del z1 z2
r del z1{t} z2{t}
# Data arriving after the BZPOPMIN.
$rd bzpopmin z1 z2 z2 z1 0
r zadd z1 0 a
assert_equal [$rd read] {z1 a 0}
$rd bzpopmin z1 z2 z2 z1 0
r zadd z2 1 b
assert_equal [$rd read] {z2 b 1}
$rd bzpopmin z1{t} z2{t} z2{t} z1{t} 0
r zadd z1{t} 0 a
assert_equal [$rd read] {z1{t} a 0}
$rd bzpopmin z1{t} z2{t} z2{t} z1{t} 0
r zadd z2{t} 1 b
assert_equal [$rd read] {z2{t} b 1}
# Data already there.
r zadd z1 0 a
r zadd z2 1 b
$rd bzpopmin z1 z2 z2 z1 0
assert_equal [$rd read] {z1 a 0}
$rd bzpopmin z1 z2 z2 z1 0
assert_equal [$rd read] {z2 b 1}
r zadd z1{t} 0 a
r zadd z2{t} 1 b
$rd bzpopmin z1{t} z2{t} z2{t} z1{t} 0
assert_equal [$rd read] {z1{t} a 0}
$rd bzpopmin z1{t} z2{t} z2{t} z1{t} 0
assert_equal [$rd read] {z2{t} b 1}
}
test "MULTI/EXEC is isolated from the point of view of BZPOPMIN" {
......@@ -1522,89 +1525,89 @@ start_server {tags {"zset"}} {
test {ZRANGESTORE basic} {
r flushall
r zadd z1 1 a 2 b 3 c 4 d
set res [r zrangestore z2 z1 0 -1]
r zadd z1{t} 1 a 2 b 3 c 4 d
set res [r zrangestore z2{t} z1{t} 0 -1]
assert_equal $res 4
r zrange z2 0 -1 withscores
r zrange z2{t} 0 -1 withscores
} {a 1 b 2 c 3 d 4}
test {ZRANGESTORE RESP3} {
r hello 3
r zrange z2 0 -1 withscores
} {{a 1.0} {b 2.0} {c 3.0} {d 4.0}}
assert_equal [r zrange z2{t} 0 -1 withscores] {{a 1.0} {b 2.0} {c 3.0} {d 4.0}}
r hello 2
}
test {ZRANGESTORE range} {
set res [r zrangestore z2 z1 1 2]
set res [r zrangestore z2{t} z1{t} 1 2]
assert_equal $res 2
r zrange z2 0 -1 withscores
r zrange z2{t} 0 -1 withscores
} {b 2 c 3}
test {ZRANGESTORE BYLEX} {
set res [r zrangestore z2 z1 \[b \[c BYLEX]
set res [r zrangestore z2{t} z1{t} \[b \[c BYLEX]
assert_equal $res 2
r zrange z2 0 -1 withscores
r zrange z2{t} 0 -1 withscores
} {b 2 c 3}
test {ZRANGESTORE BYSCORE} {
set res [r zrangestore z2 z1 1 2 BYSCORE]
set res [r zrangestore z2{t} z1{t} 1 2 BYSCORE]
assert_equal $res 2
r zrange z2 0 -1 withscores
r zrange z2{t} 0 -1 withscores
} {a 1 b 2}
test {ZRANGESTORE BYSCORE LIMIT} {
set res [r zrangestore z2 z1 0 5 BYSCORE LIMIT 0 2]
set res [r zrangestore z2{t} z1{t} 0 5 BYSCORE LIMIT 0 2]
assert_equal $res 2
r zrange z2 0 -1 withscores
r zrange z2{t} 0 -1 withscores
} {a 1 b 2}
test {ZRANGESTORE BYSCORE REV LIMIT} {
set res [r zrangestore z2 z1 5 0 BYSCORE REV LIMIT 0 2]
set res [r zrangestore z2{t} z1{t} 5 0 BYSCORE REV LIMIT 0 2]
assert_equal $res 2
r zrange z2 0 -1 withscores
r zrange z2{t} 0 -1 withscores
} {c 3 d 4}
test {ZRANGE BYSCORE REV LIMIT} {
r zrange z1 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES
r zrange z1{t} 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES
} {d 4 c 3}
test {ZRANGESTORE - empty range} {
set res [r zrangestore z2 z1 5 6]
set res [r zrangestore z2{t} z1{t} 5 6]
assert_equal $res 0
r exists z2
r exists z2{t}
} {0}
test {ZRANGESTORE BYLEX - empty range} {
set res [r zrangestore z2 z1 \[f \[g BYLEX]
set res [r zrangestore z2{t} z1{t} \[f \[g BYLEX]
assert_equal $res 0
r exists z2
r exists z2{t}
} {0}
test {ZRANGESTORE BYSCORE - empty range} {
set res [r zrangestore z2 z1 5 6 BYSCORE]
set res [r zrangestore z2{t} z1{t} 5 6 BYSCORE]
assert_equal $res 0
r exists z2
r exists z2{t}
} {0}
test {ZRANGE BYLEX} {
r zrange z1 \[b \[c BYLEX
r zrange z1{t} \[b \[c BYLEX
} {b c}
test {ZRANGESTORE invalid syntax} {
catch {r zrangestore z2 z1 0 -1 limit 1 2} err
catch {r zrangestore z2{t} z1{t} 0 -1 limit 1 2} err
assert_match "*syntax*" $err
catch {r zrangestore z2 z1 0 -1 WITHSCORES} err
catch {r zrangestore z2{t} z1{t} 0 -1 WITHSCORES} err
assert_match "*syntax*" $err
}
test {ZRANGE invalid syntax} {
catch {r zrange z1 0 -1 limit 1 2} err
catch {r zrange z1{t} 0 -1 limit 1 2} err
assert_match "*syntax*" $err
catch {r zrange z1 0 -1 BYLEX WITHSCORES} err
catch {r zrange z1{t} 0 -1 BYLEX WITHSCORES} err
assert_match "*syntax*" $err
catch {r zrevrange z1 0 -1 BYSCORE} err
catch {r zrevrange z1{t} 0 -1 BYSCORE} err
assert_match "*syntax*" $err
catch {r zrangebyscore z1 0 -1 REV} err
catch {r zrangebyscore z1{t} 0 -1 REV} err
assert_match "*syntax*" $err
}
......@@ -1643,8 +1646,8 @@ start_server {tags {"zset"}} {
set res [r zrandmember myzset 3]
assert_equal [llength $res] 3
assert_equal [llength [lindex $res 1]] 1
}
r hello 2
}
test "ZRANDMEMBER count of 0 is handled correctly" {
r zrandmember myzset 0
......
source tests/support/cli.tcl
start_server {tags {"wait network"}} {
start_server {tags {"wait network external:skip"}} {
start_server {} {
set slave [srv 0 client]
set slave_host [srv 0 host]
......
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