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
start_server {tags {"limits network"} overrides {maxclients 10}} {
start_server {tags {"limits network external:skip"} overrides {maxclients 10}} {
if {$::tls} {
set expected_code "*I/O error*"
} else {
......
start_server {tags {"maxmemory"}} {
start_server {tags {"maxmemory external:skip"}} {
test "Without maxmemory small integers are shared" {
r config set maxmemory 0
r set a 1
......@@ -144,7 +144,7 @@ start_server {tags {"maxmemory"}} {
}
proc test_slave_buffers {test_name cmd_count payload_len limit_memory pipeline} {
start_server {tags {"maxmemory"}} {
start_server {tags {"maxmemory external:skip"}} {
start_server {} {
set slave_pid [s process_id]
test "$test_name" {
......@@ -241,7 +241,7 @@ test_slave_buffers {slave buffer are counted correctly} 1000000 10 0 1
# test again with fewer (and bigger) commands without pipeline, but with eviction
test_slave_buffers "replica buffer don't induce eviction" 100000 100 1 0
start_server {tags {"maxmemory"}} {
start_server {tags {"maxmemory external:skip"}} {
test {Don't rehash if used memory exceeds maxmemory after rehash} {
r config set maxmemory 0
r config set maxmemory-policy allkeys-random
......@@ -261,7 +261,7 @@ start_server {tags {"maxmemory"}} {
} {4098}
}
start_server {tags {"maxmemory"}} {
start_server {tags {"maxmemory external:skip"}} {
test {client tracking don't cause eviction feedback loop} {
r config set maxmemory 0
r config set maxmemory-policy allkeys-lru
......
......@@ -21,7 +21,7 @@ proc test_memory_efficiency {range} {
return $efficiency
}
start_server {tags {"memefficiency"}} {
start_server {tags {"memefficiency external:skip"}} {
foreach {size_range expected_min_efficiency} {
32 0.15
64 0.25
......@@ -37,7 +37,7 @@ start_server {tags {"memefficiency"}} {
}
run_solo {defrag} {
start_server {tags {"defrag"} overrides {appendonly yes auto-aof-rewrite-percentage 0 save ""}} {
start_server {tags {"defrag external:skip"} overrides {appendonly yes auto-aof-rewrite-percentage 0 save ""}} {
if {[string match {*jemalloc*} [s mem_allocator]] && [r debug mallctl arenas.page] <= 8192} {
test "Active defrag" {
r config set hz 100
......
proc wait_for_dbsize {size} {
set r2 [redis_client]
wait_for_condition 50 100 {
[$r2 dbsize] == $size
} else {
fail "Target dbsize not reached"
}
$r2 close
}
start_server {tags {"multi"}} {
test {MUTLI / EXEC basics} {
r del mylist
......@@ -47,47 +57,47 @@ start_server {tags {"multi"}} {
} {*ERR WATCH*}
test {EXEC fails if there are errors while queueing commands #1} {
r del foo1 foo2
r del foo1{t} foo2{t}
r multi
r set foo1 bar1
r set foo1{t} bar1
catch {r non-existing-command}
r set foo2 bar2
r set foo2{t} bar2
catch {r exec} e
assert_match {EXECABORT*} $e
list [r exists foo1] [r exists foo2]
list [r exists foo1{t}] [r exists foo2{t}]
} {0 0}
test {EXEC fails if there are errors while queueing commands #2} {
set rd [redis_deferring_client]
r del foo1 foo2
r del foo1{t} foo2{t}
r multi
r set foo1 bar1
r set foo1{t} bar1
$rd config set maxmemory 1
assert {[$rd read] eq {OK}}
catch {r lpush mylist myvalue}
catch {r lpush mylist{t} myvalue}
$rd config set maxmemory 0
assert {[$rd read] eq {OK}}
r set foo2 bar2
r set foo2{t} bar2
catch {r exec} e
assert_match {EXECABORT*} $e
$rd close
list [r exists foo1] [r exists foo2]
} {0 0}
list [r exists foo1{t}] [r exists foo2{t}]
} {0 0} {needs:config-maxmemory}
test {If EXEC aborts, the client MULTI state is cleared} {
r del foo1 foo2
r del foo1{t} foo2{t}
r multi
r set foo1 bar1
r set foo1{t} bar1
catch {r non-existing-command}
r set foo2 bar2
r set foo2{t} bar2
catch {r exec} e
assert_match {EXECABORT*} $e
r ping
} {PONG}
test {EXEC works on WATCHed key not modified} {
r watch x y z
r watch k
r watch x{t} y{t} z{t}
r watch k{t}
r multi
r ping
r exec
......@@ -103,9 +113,9 @@ start_server {tags {"multi"}} {
} {}
test {EXEC fail on WATCHed key modified (1 key of 5 watched)} {
r set x 30
r watch a b x k z
r set x 40
r set x{t} 30
r watch a{t} b{t} x{t} k{t} z{t}
r set x{t} 40
r multi
r ping
r exec
......@@ -119,7 +129,7 @@ start_server {tags {"multi"}} {
r multi
r ping
r exec
} {}
} {} {cluster:skip}
test {After successful EXEC key is no longer watched} {
r set x 30
......@@ -205,7 +215,7 @@ start_server {tags {"multi"}} {
r multi
r ping
r exec
} {}
} {} {singledb:skip}
test {SWAPDB is able to touch the watched keys that do not exist} {
r flushall
......@@ -217,7 +227,7 @@ start_server {tags {"multi"}} {
r multi
r ping
r exec
} {}
} {} {singledb:skip}
test {WATCH is able to remember the DB a key belongs to} {
r select 5
......@@ -232,7 +242,7 @@ start_server {tags {"multi"}} {
# Restore original DB
r select 9
set res
} {PONG}
} {PONG} {singledb:skip}
test {WATCH will consider touched keys target of EXPIRE} {
r del x
......@@ -245,11 +255,15 @@ start_server {tags {"multi"}} {
} {}
test {WATCH will consider touched expired keys} {
r flushall
r del x
r set x foo
r expire x 1
r watch x
after 1100
# Wait for the keys to expire.
wait_for_dbsize 0
r multi
r ping
r exec
......@@ -288,7 +302,7 @@ start_server {tags {"multi"}} {
{exec}
}
close_replication_stream $repl
}
} {} {needs:repl}
test {MULTI / EXEC is propagated correctly (empty transaction)} {
set repl [attach_to_replication_stream]
......@@ -300,7 +314,7 @@ start_server {tags {"multi"}} {
{set foo bar}
}
close_replication_stream $repl
}
} {} {needs:repl}
test {MULTI / EXEC is propagated correctly (read-only commands)} {
r set foo value1
......@@ -314,10 +328,11 @@ start_server {tags {"multi"}} {
{set foo value2}
}
close_replication_stream $repl
}
} {} {needs:repl}
test {MULTI / EXEC is propagated correctly (write command, no effect)} {
r del bar foo bar
r del bar
r del foo
set repl [attach_to_replication_stream]
r multi
r del foo
......@@ -332,7 +347,7 @@ start_server {tags {"multi"}} {
{incr foo}
}
close_replication_stream $repl
}
} {} {needs:repl}
test {DISCARD should not fail during OOM} {
set rd [redis_deferring_client]
......@@ -346,7 +361,7 @@ start_server {tags {"multi"}} {
assert {[$rd read] eq {OK}}
$rd close
r ping
} {PONG}
} {PONG} {needs:config-maxmemory}
test {MULTI and script timeout} {
# check that if MULTI arrives during timeout, it is either refused, or
......@@ -460,8 +475,8 @@ start_server {tags {"multi"}} {
# make sure that the INCR wasn't executed
assert { $xx == 1}
$r1 config set min-replicas-to-write 0
$r1 close;
}
$r1 close
} {0} {needs:repl}
test {exec with read commands and stale replica state change} {
# check that exec that contains read commands fails if server state changed since they were queued
......@@ -491,8 +506,8 @@ start_server {tags {"multi"}} {
set xx [r exec]
# make sure that the INCR was executed
assert { $xx == 1 }
$r1 close;
}
$r1 close
} {0} {needs:repl cluster:skip}
test {EXEC with only read commands should not be rejected when OOM} {
set r2 [redis_client]
......@@ -511,7 +526,7 @@ start_server {tags {"multi"}} {
# releasing OOM
$r2 config set maxmemory 0
$r2 close
}
} {0} {needs:config-maxmemory}
test {EXEC with at least one use-memory command should fail} {
set r2 [redis_client]
......@@ -530,20 +545,20 @@ start_server {tags {"multi"}} {
# releasing OOM
$r2 config set maxmemory 0
$r2 close
}
} {0} {needs:config-maxmemory}
test {Blocking commands ignores the timeout} {
r xgroup create s g $ MKSTREAM
r xgroup create s{t} g $ MKSTREAM
set m [r multi]
r blpop empty_list 0
r brpop empty_list 0
r brpoplpush empty_list1 empty_list2 0
r blmove empty_list1 empty_list2 LEFT LEFT 0
r bzpopmin empty_zset 0
r bzpopmax empty_zset 0
r xread BLOCK 0 STREAMS s $
r xreadgroup group g c BLOCK 0 STREAMS s >
r blpop empty_list{t} 0
r brpop empty_list{t} 0
r brpoplpush empty_list1{t} empty_list2{t} 0
r blmove empty_list1{t} empty_list2{t} LEFT LEFT 0
r bzpopmin empty_zset{t} 0
r bzpopmax empty_zset{t} 0
r xread BLOCK 0 STREAMS s{t} $
r xreadgroup group g c BLOCK 0 STREAMS s{t} >
set res [r exec]
list $m $res
......@@ -564,7 +579,7 @@ start_server {tags {"multi"}} {
{exec}
}
close_replication_stream $repl
}
} {} {needs:repl cluster:skip}
test {MULTI propagation of SCRIPT LOAD} {
set repl [attach_to_replication_stream]
......@@ -582,7 +597,7 @@ start_server {tags {"multi"}} {
{exec}
}
close_replication_stream $repl
}
} {} {needs:repl}
test {MULTI propagation of SCRIPT LOAD} {
set repl [attach_to_replication_stream]
......@@ -600,7 +615,7 @@ start_server {tags {"multi"}} {
{exec}
}
close_replication_stream $repl
}
} {} {needs:repl}
tags {"stream"} {
test {MULTI propagation of XREADGROUP} {
......@@ -624,7 +639,7 @@ start_server {tags {"multi"}} {
{exec}
}
close_replication_stream $repl
}
} {} {needs:repl}
}
}
......@@ -20,7 +20,7 @@ test {CONFIG SET port number} {
$rd PING
$rd close
}
}
} {} {external:skip}
test {CONFIG SET bind address} {
start_server {} {
......@@ -33,4 +33,4 @@ test {CONFIG SET bind address} {
$rd PING
$rd close
}
}
} {} {external:skip}
start_server {tags {"obuf-limits"}} {
start_server {tags {"obuf-limits external:skip"}} {
test {Client output buffer hard limit is enforced} {
r config set client-output-buffer-limit {pubsub 100000 0 0}
set rd1 [redis_deferring_client]
......
......@@ -2,7 +2,7 @@ set system_name [string tolower [exec uname -s]]
set user_id [exec id -u]
if {$system_name eq {linux}} {
start_server {tags {"oom-score-adj"}} {
start_server {tags {"oom-score-adj external:skip"}} {
proc get_oom_score_adj {{pid ""}} {
if {$pid == ""} {
set pid [srv 0 pid]
......
start_server {overrides {save ""} tags {"other"}} {
start_server {tags {"other"}} {
if {$::force_failure} {
# This is used just for test suite development purposes.
test {Failing test} {
......@@ -17,7 +17,7 @@ start_server {overrides {save ""} tags {"other"}} {
r zadd mytestzset 20 b
r zadd mytestzset 30 c
r save
} {OK}
} {OK} {needs:save}
tags {slow} {
if {$::accurate} {set iterations 10000} else {set iterations 1000}
......@@ -47,65 +47,65 @@ start_server {overrides {save ""} tags {"other"}} {
waitForBgsave r
r debug reload
r get x
} {10}
} {10} {needs:save}
test {SELECT an out of range DB} {
catch {r select 1000000} err
set _ $err
} {*index is out of range*}
} {*index is out of range*} {cluster:skip}
tags {consistency} {
if {true} {
if {$::accurate} {set numops 10000} else {set numops 1000}
test {Check consistency of different data types after a reload} {
r flushdb
createComplexDataset r $numops
set dump [csvdump r]
set sha1 [r debug digest]
r debug reload
set sha1_after [r debug digest]
if {$sha1 eq $sha1_after} {
set _ 1
} else {
set newdump [csvdump r]
puts "Consistency test failed!"
puts "You can inspect the two dumps in /tmp/repldump*.txt"
set fd [open /tmp/repldump1.txt w]
puts $fd $dump
close $fd
set fd [open /tmp/repldump2.txt w]
puts $fd $newdump
close $fd
set _ 0
proc check_consistency {dumpname code} {
set dump [csvdump r]
set sha1 [r debug digest]
uplevel 1 $code
set sha1_after [r debug digest]
if {$sha1 eq $sha1_after} {
return 1
}
# Failed
set newdump [csvdump r]
puts "Consistency test failed!"
puts "You can inspect the two dumps in /tmp/${dumpname}*.txt"
set fd [open /tmp/${dumpname}1.txt w]
puts $fd $dump
close $fd
set fd [open /tmp/${dumpname}2.txt w]
puts $fd $newdump
close $fd
return 0
}
if {$::accurate} {set numops 10000} else {set numops 1000}
test {Check consistency of different data types after a reload} {
r flushdb
createComplexDataset r $numops usetag
if {$::ignoredigest} {
set _ 1
} else {
check_consistency {repldump} {
r debug reload
}
} {1}
test {Same dataset digest if saving/reloading as AOF?} {
r config set aof-use-rdb-preamble no
r bgrewriteaof
waitForBgrewriteaof r
r debug loadaof
set sha1_after [r debug digest]
if {$sha1 eq $sha1_after} {
set _ 1
} else {
set newdump [csvdump r]
puts "Consistency test failed!"
puts "You can inspect the two dumps in /tmp/aofdump*.txt"
set fd [open /tmp/aofdump1.txt w]
puts $fd $dump
close $fd
set fd [open /tmp/aofdump2.txt w]
puts $fd $newdump
close $fd
set _ 0
}
} {1}
test {Same dataset digest if saving/reloading as AOF?} {
if {$::ignoredigest} {
set _ 1
} else {
check_consistency {aofdump} {
r config set aof-use-rdb-preamble no
r bgrewriteaof
waitForBgrewriteaof r
r debug loadaof
}
} {1}
}
}
} {1} {needs:debug}
}
test {EXPIRES after a reload (snapshot + append only file rewrite)} {
......@@ -122,7 +122,7 @@ start_server {overrides {save ""} tags {"other"}} {
set ttl [r ttl x]
set e2 [expr {$ttl > 900 && $ttl <= 1000}]
list $e1 $e2
} {1 1}
} {1 1} {needs:debug needs:save}
test {EXPIRES after AOF reload (without rewrite)} {
r flushdb
......@@ -162,7 +162,7 @@ start_server {overrides {save ""} tags {"other"}} {
set ttl [r ttl pz]
assert {$ttl > 2900 && $ttl <= 3000}
r config set appendonly no
}
} {OK} {needs:debug}
tags {protocol} {
test {PIPELINING stresser (also a regression for the old epoll bug)} {
......@@ -237,18 +237,23 @@ start_server {overrides {save ""} tags {"other"}} {
# Leave the user with a clean DB before to exit
test {FLUSHDB} {
set aux {}
r select 9
r flushdb
lappend aux [r dbsize]
r select 10
r flushdb
lappend aux [r dbsize]
if {$::singledb} {
r flushdb
lappend aux 0 [r dbsize]
} else {
r select 9
r flushdb
lappend aux [r dbsize]
r select 10
r flushdb
lappend aux [r dbsize]
}
} {0 0}
test {Perform a final SAVE to leave a clean DB on disk} {
waitForBgsave r
r save
} {OK}
} {OK} {needs:save}
test {RESET clears client state} {
r client setname test-client
......@@ -258,7 +263,7 @@ start_server {overrides {save ""} tags {"other"}} {
set client [r client list]
assert_match {*name= *} $client
assert_match {*flags=N *} $client
}
} {} {needs:reset}
test {RESET clears MONITOR state} {
set rd [redis_deferring_client]
......@@ -269,7 +274,7 @@ start_server {overrides {save ""} tags {"other"}} {
assert_equal [$rd read] "RESET"
assert_no_match {*flags=O*} [r client list]
}
} {} {needs:reset}
test {RESET clears and discards MULTI state} {
r multi
......@@ -278,7 +283,7 @@ start_server {overrides {save ""} tags {"other"}} {
r reset
catch {r exec} err
assert_match {*EXEC without MULTI*} $err
}
} {} {needs:reset}
test {RESET clears Pub/Sub state} {
r subscribe channel-1
......@@ -286,7 +291,7 @@ start_server {overrides {save ""} tags {"other"}} {
# confirm we're not subscribed by executing another command
r set key val
}
} {OK} {needs:reset}
test {RESET clears authenticated state} {
r acl setuser user1 on >secret +@all
......@@ -296,10 +301,10 @@ start_server {overrides {save ""} tags {"other"}} {
r reset
assert_equal [r acl whoami] default
}
} {} {needs:reset}
}
start_server {tags {"other"}} {
start_server {tags {"other external:skip"}} {
test {Don't rehash if redis has child proecess} {
r config set save ""
r config set rdb-key-save-delay 1000000
......@@ -322,7 +327,7 @@ start_server {tags {"other"}} {
# size is power of two and over 4098, so it is 8192
r set k3 v3
assert_match "*table size: 8192*" [r debug HTSTATS 9]
}
} {} {needs:local-process}
}
proc read_proc_title {pid} {
......@@ -333,7 +338,7 @@ proc read_proc_title {pid} {
return $cmdline
}
start_server {tags {"other"}} {
start_server {tags {"other external:skip"}} {
test {Process title set as expected} {
# Test only on Linux where it's easy to get cmdline without relying on tools.
# Skip valgrind as it messes up the arguments.
......
......@@ -12,7 +12,7 @@ proc prepare_value {size} {
return $_v
}
start_server {tags {"wait"}} {
start_server {tags {"wait external:skip"}} {
start_server {} {
set slave [srv 0 client]
set slave_host [srv 0 host]
......
start_server {tags {"pubsub network"}} {
if {$::singledb} {
set db 0
} else {
set db 9
}
test "Pub/Sub PING" {
set rd1 [redis_deferring_client]
subscribe $rd1 somechannel
......@@ -182,7 +188,7 @@ start_server {tags {"pubsub network"}} {
set rd1 [redis_deferring_client]
assert_equal {1} [psubscribe $rd1 *]
r set foo bar
assert_equal {pmessage * __keyspace@9__:foo set} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:foo set" [$rd1 read]
$rd1 close
}
......@@ -191,7 +197,7 @@ start_server {tags {"pubsub network"}} {
set rd1 [redis_deferring_client]
assert_equal {1} [psubscribe $rd1 *]
r set foo bar
assert_equal {pmessage * __keyevent@9__:set foo} [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:set foo" [$rd1 read]
$rd1 close
}
......@@ -200,8 +206,8 @@ start_server {tags {"pubsub network"}} {
set rd1 [redis_deferring_client]
assert_equal {1} [psubscribe $rd1 *]
r set foo bar
assert_equal {pmessage * __keyspace@9__:foo set} [$rd1 read]
assert_equal {pmessage * __keyevent@9__:set foo} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:foo set" [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:set foo" [$rd1 read]
$rd1 close
}
......@@ -213,8 +219,8 @@ start_server {tags {"pubsub network"}} {
r set foo bar
r lpush mylist a
# No notification for set, because only list commands are enabled.
assert_equal {pmessage * __keyspace@9__:mylist lpush} [$rd1 read]
assert_equal {pmessage * __keyevent@9__:lpush mylist} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:mylist lpush" [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:lpush mylist" [$rd1 read]
$rd1 close
}
......@@ -225,10 +231,10 @@ start_server {tags {"pubsub network"}} {
r set foo bar
r expire foo 1
r del foo
assert_equal {pmessage * __keyspace@9__:foo expire} [$rd1 read]
assert_equal {pmessage * __keyevent@9__:expire foo} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:foo del} [$rd1 read]
assert_equal {pmessage * __keyevent@9__:del foo} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:foo expire" [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:expire foo" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:foo del" [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:del foo" [$rd1 read]
$rd1 close
}
......@@ -240,12 +246,12 @@ start_server {tags {"pubsub network"}} {
r lpush mylist a
r rpush mylist a
r rpop mylist
assert_equal {pmessage * __keyspace@9__:mylist lpush} [$rd1 read]
assert_equal {pmessage * __keyevent@9__:lpush mylist} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:mylist rpush} [$rd1 read]
assert_equal {pmessage * __keyevent@9__:rpush mylist} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:mylist rpop} [$rd1 read]
assert_equal {pmessage * __keyevent@9__:rpop mylist} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:mylist lpush" [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:lpush mylist" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:mylist rpush" [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:rpush mylist" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:mylist rpop" [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:rpop mylist" [$rd1 read]
$rd1 close
}
......@@ -258,9 +264,9 @@ start_server {tags {"pubsub network"}} {
r srem myset x
r sadd myset x y z
r srem myset x
assert_equal {pmessage * __keyspace@9__:myset sadd} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:myset sadd} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:myset srem} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myset sadd" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myset sadd" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myset srem" [$rd1 read]
$rd1 close
}
......@@ -273,9 +279,9 @@ start_server {tags {"pubsub network"}} {
r zrem myzset x
r zadd myzset 3 x 4 y 5 z
r zrem myzset x
assert_equal {pmessage * __keyspace@9__:myzset zadd} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:myzset zadd} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:myzset zrem} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myzset zadd" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myzset zadd" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myzset zrem" [$rd1 read]
$rd1 close
}
......@@ -286,8 +292,8 @@ start_server {tags {"pubsub network"}} {
assert_equal {1} [psubscribe $rd1 *]
r hmset myhash yes 1 no 0
r hincrby myhash yes 10
assert_equal {pmessage * __keyspace@9__:myhash hset} [$rd1 read]
assert_equal {pmessage * __keyspace@9__:myhash hincrby} [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myhash hset" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myhash hincrby" [$rd1 read]
$rd1 close
}
......@@ -302,7 +308,7 @@ start_server {tags {"pubsub network"}} {
} else {
fail "Key does not expire?!"
}
assert_equal {pmessage * __keyevent@9__:expired foo} [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:expired foo" [$rd1 read]
$rd1 close
}
......@@ -312,7 +318,7 @@ start_server {tags {"pubsub network"}} {
set rd1 [redis_deferring_client]
assert_equal {1} [psubscribe $rd1 *]
r psetex foo 100 1
assert_equal {pmessage * __keyevent@9__:expired foo} [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:expired foo" [$rd1 read]
$rd1 close
}
......@@ -324,10 +330,11 @@ start_server {tags {"pubsub network"}} {
assert_equal {1} [psubscribe $rd1 *]
r set foo bar
r config set maxmemory 1
assert_equal {pmessage * __keyevent@9__:evicted foo} [$rd1 read]
assert_equal "pmessage * __keyevent@${db}__:evicted foo" [$rd1 read]
r config set maxmemory 0
$rd1 close
}
r config set maxmemory-policy noeviction
} {OK} {needs:config-maxmemory}
test "Keyspace notifications: test CONFIG GET/SET of event flags" {
r config set notify-keyspace-events gKE
......
start_server {tags {"scan network"}} {
test "SCAN basic" {
r flushdb
r debug populate 1000
populate 1000
set cur 0
set keys {}
......@@ -19,7 +19,7 @@ start_server {tags {"scan network"}} {
test "SCAN COUNT" {
r flushdb
r debug populate 1000
populate 1000
set cur 0
set keys {}
......@@ -37,7 +37,7 @@ start_server {tags {"scan network"}} {
test "SCAN MATCH" {
r flushdb
r debug populate 1000
populate 1000
set cur 0
set keys {}
......@@ -56,7 +56,7 @@ start_server {tags {"scan network"}} {
test "SCAN TYPE" {
r flushdb
# populate only creates strings
r debug populate 1000
populate 1000
# Check non-strings are excluded
set cur 0
......@@ -114,7 +114,7 @@ start_server {tags {"scan network"}} {
r sadd set {*}$elements
# Verify that the encoding matches.
assert {[r object encoding set] eq $enc}
assert_encoding $enc set
# Test SSCAN
set cur 0
......@@ -148,7 +148,7 @@ start_server {tags {"scan network"}} {
r hmset hash {*}$elements
# Verify that the encoding matches.
assert {[r object encoding hash] eq $enc}
assert_encoding $enc hash
# Test HSCAN
set cur 0
......@@ -188,7 +188,7 @@ start_server {tags {"scan network"}} {
r zadd zset {*}$elements
# Verify that the encoding matches.
assert {[r object encoding zset] eq $enc}
assert_encoding $enc zset
# Test ZSCAN
set cur 0
......@@ -214,7 +214,7 @@ start_server {tags {"scan network"}} {
test "SCAN guarantees check under write load" {
r flushdb
r debug populate 100
populate 100
# We start scanning here, so keys from 0 to 99 should all be
# reported at the end of the iteration.
......
......@@ -35,8 +35,8 @@ start_server {tags {"scripting"}} {
} {1 2 3 ciao {1 2}}
test {EVAL - Are the KEYS and ARGV arrays populated correctly?} {
r eval {return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}} 2 a b c d
} {a b c d}
r eval {return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}} 2 a{t} b{t} c{t} d{t}
} {a{t} b{t} c{t} d{t}}
test {EVAL - is Lua able to call Redis API?} {
r set mykey myval
......@@ -116,7 +116,7 @@ start_server {tags {"scripting"}} {
r select 10
r set mykey "this is DB 10"
r eval {return redis.pcall('get',KEYS[1])} 1 mykey
} {this is DB 10}
} {this is DB 10} {singledb:skip}
test {EVAL - SELECT inside Lua should not affect the caller} {
# here we DB 10 is selected
......@@ -125,7 +125,7 @@ start_server {tags {"scripting"}} {
set res [r get mykey]
r select 9
set res
} {original value}
} {original value} {singledb:skip}
if 0 {
test {EVAL - Script can't run more than configured time limit} {
......@@ -195,7 +195,7 @@ start_server {tags {"scripting"}} {
} e
r debug lua-always-replicate-commands 1
set e
} {*not allowed after*}
} {*not allowed after*} {needs:debug}
test {EVAL - No arguments to redis.call/pcall is considered an error} {
set e {}
......@@ -368,25 +368,25 @@ start_server {tags {"scripting"}} {
set res [r eval {return redis.call('smembers',KEYS[1])} 1 myset]
r debug lua-always-replicate-commands 1
set res
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z}
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z} {needs:debug}
test "SORT is normally not alpha re-ordered for the scripting engine" {
r del myset
r sadd myset 1 2 3 4 10
r eval {return redis.call('sort',KEYS[1],'desc')} 1 myset
} {10 4 3 2 1}
} {10 4 3 2 1} {cluster:skip}
test "SORT BY <constant> output gets ordered for scripting" {
r del myset
r sadd myset a b c d e f g h i l m n o p q r s t u v z aa aaa azz
r eval {return redis.call('sort',KEYS[1],'by','_')} 1 myset
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z}
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z} {cluster:skip}
test "SORT BY <constant> with GET gets ordered for scripting" {
r del myset
r sadd myset a b c
r eval {return redis.call('sort',KEYS[1],'by','_','get','#','get','_:*')} 1 myset
} {a {} b {} c {}}
} {a {} b {} c {}} {cluster:skip}
test "redis.sha1hex() implementation" {
list [r eval {return redis.sha1hex('')} 0] \
......@@ -477,9 +477,9 @@ start_server {tags {"scripting"}} {
r debug loadaof
set res [r get foo]
r slaveof no one
r config set aof-use-rdb-preamble yes
set res
} {102}
r config set aof-use-rdb-preamble yes
} {102} {external:skip}
test {EVAL timeout from AOF} {
# generate a long running script that is propagated to the AOF as script
......@@ -516,16 +516,16 @@ start_server {tags {"scripting"}} {
if {$::verbose} { puts "loading took $elapsed milliseconds" }
$rd close
r get x
} {y}
} {y} {external:skip}
test {We can call scripts rewriting client->argv from Lua} {
r del myset
r sadd myset a b c
r mset a 1 b 2 c 3 d 4
r mset a{t} 1 b{t} 2 c{t} 3 d{t} 4
assert {[r spop myset] ne {}}
assert {[r spop myset 1] ne {}}
assert {[r spop myset] ne {}}
assert {[r mget a b c d] eq {1 2 3 4}}
assert {[r mget a{t} b{t} c{t} d{t}] eq {1 2 3 4}}
assert {[r spop myset] eq {}}
}
......@@ -539,7 +539,7 @@ start_server {tags {"scripting"}} {
end
redis.call('rpush','mylist',unpack(x))
return redis.call('lrange','mylist',0,-1)
} 0
} 1 mylist
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100}
test {Number conversion precision test (issue #1118)} {
......@@ -547,14 +547,14 @@ start_server {tags {"scripting"}} {
local value = 9007199254740991
redis.call("set","foo",value)
return redis.call("get","foo")
} 0
} 1 foo
} {9007199254740991}
test {String containing number precision test (regression of issue #1118)} {
r eval {
redis.call("set", "key", "12039611435714932082")
return redis.call("get", "key")
} 0
} 1 key
} {12039611435714932082}
test {Verify negative arg count is error instead of crash (issue #1842)} {
......@@ -565,13 +565,13 @@ start_server {tags {"scripting"}} {
test {Correct handling of reused argv (issue #1939)} {
r eval {
for i = 0, 10 do
redis.call('SET', 'a', '1')
redis.call('MGET', 'a', 'b', 'c')
redis.call('EXPIRE', 'a', 0)
redis.call('GET', 'a')
redis.call('MGET', 'a', 'b', 'c')
redis.call('SET', 'a{t}', '1')
redis.call('MGET', 'a{t}', 'b{t}', 'c{t}')
redis.call('EXPIRE', 'a{t}', 0)
redis.call('GET', 'a{t}')
redis.call('MGET', 'a{t}', 'b{t}', 'c{t}')
end
} 0
} 3 a{t} b{t} c{t}
}
test {Functions in the Redis namespace are able to report errors} {
......@@ -705,7 +705,7 @@ start_server {tags {"scripting"}} {
assert_match {UNKILLABLE*} $e
catch {r ping} e
assert_match {BUSY*} $e
}
} {} {external:skip}
# Note: keep this test at the end of this server stanza because it
# kills the server.
......@@ -717,11 +717,11 @@ start_server {tags {"scripting"}} {
# Make sure the server was killed
catch {set rd [redis_deferring_client]} e
assert_match {*connection refused*} $e
}
} {} {external:skip}
}
foreach cmdrepl {0 1} {
start_server {tags {"scripting repl"}} {
start_server {tags {"scripting repl needs:debug external:skip"}} {
start_server {} {
if {$cmdrepl == 1} {
set rt "(commands replication)"
......@@ -817,12 +817,12 @@ foreach cmdrepl {0 1} {
} else {
fail "Master-Replica desync after Lua script using SELECT."
}
}
} {} {singledb:skip}
}
}
}
start_server {tags {"scripting repl"}} {
start_server {tags {"scripting repl external:skip"}} {
start_server {overrides {appendonly yes aof-use-rdb-preamble no}} {
test "Connect a replica to the master instance" {
r -1 slaveof [srv 0 host] [srv 0 port]
......@@ -929,7 +929,7 @@ start_server {tags {"scripting repl"}} {
}
}
start_server {tags {"scripting"}} {
start_server {tags {"scripting external:skip"}} {
r script debug sync
r eval {return 'hello'} 0
r eval {return 'hello'} 0
......
start_server {tags {"shutdown"}} {
start_server {tags {"shutdown external:skip"}} {
test {Temp rdb will be deleted if we use bg_unlink when shutdown} {
for {set i 0} {$i < 20} {incr i} {
r set $i $i
......@@ -25,7 +25,7 @@ start_server {tags {"shutdown"}} {
}
}
start_server {tags {"shutdown"}} {
start_server {tags {"shutdown external:skip"}} {
test {Temp rdb will be deleted in signal handle} {
for {set i 0} {$i < 20} {incr i} {
r set $i $i
......
start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
test {SLOWLOG - check that it starts with an empty log} {
if {$::external} {
r slowlog reset
}
r slowlog len
} {0}
......@@ -9,7 +12,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
assert_equal [r slowlog len] 0
r debug sleep 0.2
assert_equal [r slowlog len] 1
}
} {} {needs:debug}
test {SLOWLOG - max entries is correctly handled} {
r config set slowlog-log-slower-than 0
......@@ -35,11 +38,13 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
r debug sleep 0.2
set e [lindex [r slowlog get] 0]
assert_equal [llength $e] 6
assert_equal [lindex $e 0] 105
if {!$::external} {
assert_equal [lindex $e 0] 105
}
assert_equal [expr {[lindex $e 2] > 100000}] 1
assert_equal [lindex $e 3] {debug sleep 0.2}
assert_equal {foobar} [lindex $e 5]
}
} {} {needs:debug}
test {SLOWLOG - Certain commands are omitted that contain sensitive information} {
r config set slowlog-log-slower-than 0
......@@ -57,7 +62,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
assert_equal {config set masterauth (redacted)} [lindex [lindex [r slowlog get] 2] 3]
assert_equal {acl setuser (redacted) (redacted) (redacted)} [lindex [lindex [r slowlog get] 1] 3]
assert_equal {config set slowlog-log-slower-than 0} [lindex [lindex [r slowlog get] 0] 3]
}
} {} {needs:repl}
test {SLOWLOG - Some commands can redact sensitive fields} {
r config set slowlog-log-slower-than 0
......@@ -72,7 +77,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
assert_match {* key 9 5000} [lindex [lindex [r slowlog get] 2] 3]
assert_match {* key 9 5000 AUTH (redacted)} [lindex [lindex [r slowlog get] 1] 3]
assert_match {* key 9 5000 AUTH2 (redacted) (redacted)} [lindex [lindex [r slowlog get] 0] 3]
}
} {} {needs:repl}
test {SLOWLOG - Rewritten commands are logged as their original command} {
r config set slowlog-log-slower-than 0
......@@ -111,11 +116,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
# blocked BLPOP is replicated as LPOP
set rd [redis_deferring_client]
$rd blpop l 0
wait_for_condition 50 100 {
[s blocked_clients] eq {1}
} else {
fail "Clients are not blocked"
}
wait_for_blocked_clients_count 1 50 100
r multi
r lpush l foo
r slowlog reset
......@@ -129,7 +130,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
r config set slowlog-log-slower-than 0
r slowlog reset
r sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
set e [lindex [r slowlog get] 0]
set e [lindex [r slowlog get] end-1]
lindex $e 3
} {sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 {... (2 more arguments)}}
......@@ -138,7 +139,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
r slowlog reset
set arg [string repeat A 129]
r sadd set foo $arg
set e [lindex [r slowlog get] 0]
set e [lindex [r slowlog get] end-1]
lindex $e 3
} {sadd set foo {AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... (1 more bytes)}}
......@@ -152,7 +153,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
assert_equal [r slowlog len] 1
set e [lindex [r slowlog get] 0]
assert_equal [lindex $e 3] {debug sleep 0.2}
}
} {} {needs:debug}
test {SLOWLOG - can clean older entries} {
r client setname lastentry_client
......@@ -161,7 +162,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
assert {[llength [r slowlog get]] == 1}
set e [lindex [r slowlog get] 0]
assert_equal {lastentry_client} [lindex $e 5]
}
} {} {needs:debug}
test {SLOWLOG - can be disabled} {
r config set slowlog-max-len 1
......@@ -173,5 +174,5 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
r slowlog reset
r debug sleep 0.2
assert_equal [r slowlog len] 0
}
} {} {needs:debug}
}
......@@ -47,28 +47,28 @@ start_server {
test "$title: SORT BY key" {
assert_equal $result [r sort tosort BY weight_*]
}
} {} {cluster:skip}
test "$title: SORT BY key with limit" {
assert_equal [lrange $result 5 9] [r sort tosort BY weight_* LIMIT 5 5]
}
} {} {cluster:skip}
test "$title: SORT BY hash field" {
assert_equal $result [r sort tosort BY wobj_*->weight]
}
} {} {cluster:skip}
}
set result [create_random_dataset 16 lpush]
test "SORT GET #" {
assert_equal [lsort -integer $result] [r sort tosort GET #]
}
} {} {cluster:skip}
test "SORT GET <const>" {
r del foo
set res [r sort tosort GET foo]
assert_equal 16 [llength $res]
foreach item $res { assert_equal {} $item }
}
} {} {cluster:skip}
test "SORT GET (key and hash) with sanity check" {
set l1 [r sort tosort GET # GET weight_*]
......@@ -78,21 +78,21 @@ start_server {
assert_equal $w1 [r get weight_$id1]
assert_equal $w2 [r get weight_$id1]
}
}
} {} {cluster:skip}
test "SORT BY key STORE" {
r sort tosort BY weight_* store sort-res
assert_equal $result [r lrange sort-res 0 -1]
assert_equal 16 [r llen sort-res]
assert_encoding quicklist sort-res
}
} {} {cluster:skip}
test "SORT BY hash field STORE" {
r sort tosort BY wobj_*->weight store sort-res
assert_equal $result [r lrange sort-res 0 -1]
assert_equal 16 [r llen sort-res]
assert_encoding quicklist sort-res
}
} {} {cluster:skip}
test "SORT extracts STORE correctly" {
r command getkeys sort abc store def
......@@ -188,21 +188,21 @@ start_server {
test "SORT with STORE returns zero if result is empty (github issue 224)" {
r flushdb
r sort foo store bar
r sort foo{t} store bar{t}
} {0}
test "SORT with STORE does not create empty lists (github issue 224)" {
r flushdb
r lpush foo bar
r sort foo alpha limit 10 10 store zap
r exists zap
r lpush foo{t} bar
r sort foo{t} alpha limit 10 10 store zap{t}
r exists zap{t}
} {0}
test "SORT with STORE removes key if result is empty (github issue 227)" {
r flushdb
r lpush foo bar
r sort emptylist store foo
r exists foo
r lpush foo{t} bar
r sort emptylist{t} store foo{t}
r exists foo{t}
} {0}
test "SORT with BY <constant> and STORE should still order output" {
......@@ -210,7 +210,7 @@ start_server {
r sadd myset a b c d e f g h i l m n o p q r s t u v z aa aaa azz
r sort myset alpha by _ store mylist
r lrange mylist 0 -1
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z}
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z} {cluster:skip}
test "SORT will complain with numerical sorting and bad doubles (1)" {
r del myset
......@@ -227,7 +227,7 @@ start_server {
set e {}
catch {r sort myset by score:*} e
set e
} {*ERR*double*}
} {*ERR*double*} {cluster:skip}
test "SORT BY sub-sorts lexicographically if score is the same" {
r del myset
......@@ -236,32 +236,32 @@ start_server {
set score:$ele 100
}
r sort myset by score:*
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z}
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z} {cluster:skip}
test "SORT GET with pattern ending with just -> does not get hash field" {
r del mylist
r lpush mylist a
r set x:a-> 100
r sort mylist by num get x:*->
} {100}
} {100} {cluster:skip}
test "SORT by nosort retains native order for lists" {
r del testa
r lpush testa 2 1 4 3 5
r sort testa by nosort
} {5 3 4 1 2}
} {5 3 4 1 2} {cluster:skip}
test "SORT by nosort plus store retains native order for lists" {
r del testa
r lpush testa 2 1 4 3 5
r sort testa by nosort store testb
r lrange testb 0 -1
} {5 3 4 1 2}
} {5 3 4 1 2} {cluster:skip}
test "SORT by nosort with limit returns based on original list order" {
r sort testa by nosort limit 0 3 store testb
r lrange testb 0 -1
} {5 3 4}
} {5 3 4} {cluster:skip}
tags {"slow"} {
set num 100
......@@ -277,7 +277,7 @@ start_server {
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
flush stdout
}
}
} {} {cluster:skip}
test "SORT speed, $num element list BY hash field, 100 times" {
set start [clock clicks -milliseconds]
......@@ -289,7 +289,7 @@ start_server {
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
flush stdout
}
}
} {} {cluster:skip}
test "SORT speed, $num element list directly, 100 times" {
set start [clock clicks -milliseconds]
......@@ -313,6 +313,6 @@ start_server {
puts -nonewline "\n Average time to sort: [expr double($elapsed)/100] milliseconds "
flush stdout
}
}
} {} {cluster:skip}
}
}
......@@ -40,20 +40,20 @@ start_server {tags {"tracking network"}} {
} {*OK}
test {The other connection is able to get invalidations} {
r SET a 1
r SET b 1
r GET a
r INCR b ; # This key should not be notified, since it wasn't fetched.
r INCR a
r SET a{t} 1
r SET b{t} 1
r GET a{t}
r INCR b{t} ; # This key should not be notified, since it wasn't fetched.
r INCR a{t}
set keys [lindex [$rd_redirection read] 2]
assert {[llength $keys] == 1}
assert {[lindex $keys 0] eq {a}}
assert {[lindex $keys 0] eq {a{t}}}
}
test {The client is now able to disable tracking} {
# Make sure to add a few more keys in the tracking list
# so that we can check for leaks, as a side effect.
r MGET a b c d e f g
r MGET a{t} b{t} c{t} d{t} e{t} f{t} g{t}
r CLIENT TRACKING off
} {*OK}
......@@ -62,28 +62,28 @@ start_server {tags {"tracking network"}} {
} {*OK*}
test {The connection gets invalidation messages about all the keys} {
r MSET a 1 b 2 c 3
r MSET a{t} 1 b{t} 2 c{t} 3
set keys [lsort [lindex [$rd_redirection read] 2]]
assert {$keys eq {a b c}}
assert {$keys eq {a{t} b{t} c{t}}}
}
test {Clients can enable the BCAST mode with prefixes} {
r CLIENT TRACKING off
r CLIENT TRACKING on BCAST REDIRECT $redir_id PREFIX a: PREFIX b:
r MULTI
r INCR a:1
r INCR a:2
r INCR b:1
r INCR b:2
r INCR a:1{t}
r INCR a:2{t}
r INCR b:1{t}
r INCR b:2{t}
# we should not get this key
r INCR c:1
r INCR c:1{t}
r EXEC
# Because of the internals, we know we are going to receive
# two separated notifications for the two different prefixes.
set keys1 [lsort [lindex [$rd_redirection read] 2]]
set keys2 [lsort [lindex [$rd_redirection read] 2]]
set keys [lsort [list {*}$keys1 {*}$keys2]]
assert {$keys eq {a:1 a:2 b:1 b:2}}
assert {$keys eq {a:1{t} a:2{t} b:1{t} b:2{t}}}
}
test {Adding prefixes to BCAST mode works} {
......@@ -96,16 +96,16 @@ start_server {tags {"tracking network"}} {
test {Tracking NOLOOP mode in standard mode works} {
r CLIENT TRACKING off
r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
r MGET otherkey1 loopkey otherkey2
$rd_sg SET otherkey1 1; # We should get this
r SET loopkey 1 ; # We should not get this
$rd_sg SET otherkey2 1; # We should get this
r MGET otherkey1{t} loopkey{t} otherkey2{t}
$rd_sg SET otherkey1{t} 1; # We should get this
r SET loopkey{t} 1 ; # We should not get this
$rd_sg SET otherkey2{t} 1; # We should get this
# Because of the internals, we know we are going to receive
# two separated notifications for the two different keys.
set keys1 [lsort [lindex [$rd_redirection read] 2]]
set keys2 [lsort [lindex [$rd_redirection read] 2]]
set keys [lsort [list {*}$keys1 {*}$keys2]]
assert {$keys eq {otherkey1 otherkey2}}
assert {$keys eq {otherkey1{t} otherkey2{t}}}
}
test {Tracking NOLOOP mode in BCAST mode works} {
......@@ -220,16 +220,16 @@ start_server {tags {"tracking network"}} {
r CLIENT TRACKING on REDIRECT $redir_id
$rd CLIENT TRACKING on REDIRECT $redir_id
assert_equal OK [$rd read] ; # Consume the TRACKING reply
$rd_sg MSET key1 1 key2 1
r GET key1
$rd GET key2
$rd_sg MSET key1{t} 1 key2{t} 1
r GET key1{t}
$rd GET key2{t}
assert_equal 1 [$rd read] ; # Consume the GET reply
$rd_sg INCR key1
$rd_sg INCR key2
$rd_sg INCR key1{t}
$rd_sg INCR key2{t}
set res1 [lindex [$rd_redirection read] 2]
set res2 [lindex [$rd_redirection read] 2]
assert {$res1 eq {key1}}
assert {$res2 eq {key2}}
assert {$res1 eq {key1{t}}}
assert {$res2 eq {key2{t}}}
}
test {Different clients using different protocols can track the same key} {
......@@ -356,9 +356,9 @@ start_server {tags {"tracking network"}} {
test {Tracking gets notification on tracking table key eviction} {
r CLIENT TRACKING off
r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
r MSET key1 1 key2 2
r MSET key1{t} 1 key2{t} 2
# Let the server track the two keys for us
r MGET key1 key2
r MGET key1{t} key2{t}
# Force the eviction of all the keys but one:
r config set tracking-table-max-keys 1
# Note that we may have other keys in the table for this client,
......@@ -368,11 +368,11 @@ start_server {tags {"tracking network"}} {
# otherwise the test will die for timeout.
while 1 {
set keys [lindex [$rd_redirection read] 2]
if {$keys eq {key1} || $keys eq {key2}} break
if {$keys eq {key1{t}} || $keys eq {key2{t}}} break
}
# We should receive an expire notification for one of
# the two keys (only one must remain)
assert {$keys eq {key1} || $keys eq {key2}}
assert {$keys eq {key1{t}} || $keys eq {key2{t}}}
}
test {Invalidation message received for flushall} {
......
......@@ -61,8 +61,8 @@ start_server {tags {"hash"}} {
set res [r hrandfield myhash 3]
assert_equal [llength $res] 3
assert_equal [llength [lindex $res 1]] 1
r hello 2
}
r hello 2
test "HRANDFIELD count of 0 is handled correctly" {
r hrandfield myhash 0
......@@ -445,7 +445,7 @@ start_server {tags {"hash"}} {
test {Is a ziplist encoded Hash promoted on big payload?} {
r hset smallhash foo [string repeat a 1024]
r debug object smallhash
} {*hashtable*}
} {*hashtable*} {needs:debug}
test {HINCRBY against non existing database key} {
r del htest
......@@ -709,7 +709,7 @@ start_server {tags {"hash"}} {
for {set i 0} {$i < 64} {incr i} {
r hset myhash [randomValue] [randomValue]
}
assert {[r object encoding myhash] eq {hashtable}}
assert_encoding hashtable myhash
}
}
......@@ -733,8 +733,8 @@ start_server {tags {"hash"}} {
test {Hash ziplist of various encodings} {
r del k
r config set hash-max-ziplist-entries 1000000000
r config set hash-max-ziplist-value 1000000000
config_set hash-max-ziplist-entries 1000000000
config_set hash-max-ziplist-value 1000000000
r hset k ZIP_INT_8B 127
r hset k ZIP_INT_16B 32767
r hset k ZIP_INT_32B 2147483647
......@@ -748,8 +748,8 @@ start_server {tags {"hash"}} {
set dump [r dump k]
# will be converted to dict at RESTORE
r config set hash-max-ziplist-entries 2
r config set sanitize-dump-payload no
config_set hash-max-ziplist-entries 2
config_set sanitize-dump-payload no mayfail
r restore kk 0 $dump
set kk [r hgetall kk]
......@@ -765,7 +765,7 @@ start_server {tags {"hash"}} {
} {ZIP_INT_8B 127 ZIP_INT_16B 32767 ZIP_INT_32B 2147483647 ZIP_INT_64B 9223372036854775808 ZIP_INT_IMM_MIN 0 ZIP_INT_IMM_MAX 12}
test {Hash ziplist of various encodings - sanitize dump} {
r config set sanitize-dump-payload yes
config_set sanitize-dump-payload yes mayfail
r restore kk 0 $dump replace
set k [r hgetall k]
set kk [r hgetall kk]
......
......@@ -63,7 +63,7 @@ start_server {tags {"incr"}} {
assert {[r object refcount foo] > 1}
r incr foo
assert {[r object refcount foo] == 1}
}
} {} {needs:debug}
test {INCR can modify objects in-place} {
r set foo 20000
......@@ -75,7 +75,7 @@ start_server {tags {"incr"}} {
assert {[string range $old 0 2] eq "at:"}
assert {[string range $new 0 2] eq "at:"}
assert {$old eq $new}
}
} {} {needs:debug}
test {INCRBYFLOAT against non existing key} {
r del novar
......
start_server {
tags {list ziplist}
tags {"list ziplist"}
overrides {
"list-max-ziplist-size" 16
}
......
proc wait_for_blocked_client {} {
wait_for_condition 50 100 {
[s blocked_clients] ne 0
} else {
fail "no blocked clients"
}
}
start_server {
tags {"list"}
overrides {
......@@ -172,75 +164,75 @@ start_server {
test "BLPOP, BRPOP: multiple existing lists - $type" {
set rd [redis_deferring_client]
create_list blist1 "a $large c"
create_list blist2 "d $large f"
$rd blpop blist1 blist2 1
assert_equal {blist1 a} [$rd read]
$rd brpop blist1 blist2 1
assert_equal {blist1 c} [$rd read]
assert_equal 1 [r llen blist1]
assert_equal 3 [r llen blist2]
$rd blpop blist2 blist1 1
assert_equal {blist2 d} [$rd read]
$rd brpop blist2 blist1 1
assert_equal {blist2 f} [$rd read]
assert_equal 1 [r llen blist1]
assert_equal 1 [r llen blist2]
create_list blist1{t} "a $large c"
create_list blist2{t} "d $large f"
$rd blpop blist1{t} blist2{t} 1
assert_equal {blist1{t} a} [$rd read]
$rd brpop blist1{t} blist2{t} 1
assert_equal {blist1{t} c} [$rd read]
assert_equal 1 [r llen blist1{t}]
assert_equal 3 [r llen blist2{t}]
$rd blpop blist2{t} blist1{t} 1
assert_equal {blist2{t} d} [$rd read]
$rd brpop blist2{t} blist1{t} 1
assert_equal {blist2{t} f} [$rd read]
assert_equal 1 [r llen blist1{t}]
assert_equal 1 [r llen blist2{t}]
}
test "BLPOP, BRPOP: second list has an entry - $type" {
set rd [redis_deferring_client]
r del blist1
create_list blist2 "d $large f"
$rd blpop blist1 blist2 1
assert_equal {blist2 d} [$rd read]
$rd brpop blist1 blist2 1
assert_equal {blist2 f} [$rd read]
assert_equal 0 [r llen blist1]
assert_equal 1 [r llen blist2]
r del blist1{t}
create_list blist2{t} "d $large f"
$rd blpop blist1{t} blist2{t} 1
assert_equal {blist2{t} d} [$rd read]
$rd brpop blist1{t} blist2{t} 1
assert_equal {blist2{t} f} [$rd read]
assert_equal 0 [r llen blist1{t}]
assert_equal 1 [r llen blist2{t}]
}
test "BRPOPLPUSH - $type" {
r del target
r rpush target bar
r del target{t}
r rpush target{t} bar
set rd [redis_deferring_client]
create_list blist "a b $large c d"
create_list blist{t} "a b $large c d"
$rd brpoplpush blist target 1
$rd brpoplpush blist{t} target{t} 1
assert_equal d [$rd read]
assert_equal d [r lpop target]
assert_equal "a b $large c" [r lrange blist 0 -1]
assert_equal d [r lpop target{t}]
assert_equal "a b $large c" [r lrange blist{t} 0 -1]
}
foreach wherefrom {left right} {
foreach whereto {left right} {
test "BLMOVE $wherefrom $whereto - $type" {
r del target
r rpush target bar
r del target{t}
r rpush target{t} bar
set rd [redis_deferring_client]
create_list blist "a b $large c d"
create_list blist{t} "a b $large c d"
$rd blmove blist target $wherefrom $whereto 1
$rd blmove blist{t} target{t} $wherefrom $whereto 1
set poppedelement [$rd read]
if {$wherefrom eq "right"} {
assert_equal d $poppedelement
assert_equal "a b $large c" [r lrange blist 0 -1]
assert_equal "a b $large c" [r lrange blist{t} 0 -1]
} else {
assert_equal a $poppedelement
assert_equal "b $large c d" [r lrange blist 0 -1]
assert_equal "b $large c d" [r lrange blist{t} 0 -1]
}
if {$whereto eq "right"} {
assert_equal $poppedelement [r rpop target]
assert_equal $poppedelement [r rpop target{t}]
} else {
assert_equal $poppedelement [r lpop target]
assert_equal $poppedelement [r lpop target{t}]
}
}
}
......@@ -280,23 +272,23 @@ start_server {
test "BLPOP with same key multiple times should work (issue #801)" {
set rd [redis_deferring_client]
r del list1 list2
r del list1{t} list2{t}
# Data arriving after the BLPOP.
$rd blpop list1 list2 list2 list1 0
r lpush list1 a
assert_equal [$rd read] {list1 a}
$rd blpop list1 list2 list2 list1 0
r lpush list2 b
assert_equal [$rd read] {list2 b}
$rd blpop list1{t} list2{t} list2{t} list1{t} 0
r lpush list1{t} a
assert_equal [$rd read] {list1{t} a}
$rd blpop list1{t} list2{t} list2{t} list1{t} 0
r lpush list2{t} b
assert_equal [$rd read] {list2{t} b}
# Data already there.
r lpush list1 a
r lpush list2 b
$rd blpop list1 list2 list2 list1 0
assert_equal [$rd read] {list1 a}
$rd blpop list1 list2 list2 list1 0
assert_equal [$rd read] {list2 b}
r lpush list1{t} a
r lpush list2{t} b
$rd blpop list1{t} list2{t} list2{t} list1{t} 0
assert_equal [$rd read] {list1{t} a}
$rd blpop list1{t} list2{t} list2{t} list1{t} 0
assert_equal [$rd read] {list2{t} b}
}
test "MULTI/EXEC is isolated from the point of view of BLPOP" {
......@@ -313,7 +305,7 @@ start_server {
test "BLPOP with variadic LPUSH" {
set rd [redis_deferring_client]
r del blist target
r del blist
if {$::valgrind} {after 100}
$rd blpop blist 0
if {$::valgrind} {after 100}
......@@ -325,37 +317,29 @@ start_server {
test "BRPOPLPUSH with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd brpoplpush blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
r del blist{t} target{t}
r rpush target{t} bar
$rd brpoplpush blist{t} target{t} 0
wait_for_blocked_clients_count 1
r rpush blist{t} foo
assert_equal foo [$rd read]
assert_equal {foo bar} [r lrange target 0 -1]
assert_equal {foo bar} [r lrange target{t} 0 -1]
}
foreach wherefrom {left right} {
foreach whereto {left right} {
test "BLMOVE $wherefrom $whereto with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd blmove blist target $wherefrom $whereto 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
r del blist{t} target{t}
r rpush target{t} bar
$rd blmove blist{t} target{t} $wherefrom $whereto 0
wait_for_blocked_clients_count 1
r rpush blist{t} foo
assert_equal foo [$rd read]
if {$whereto eq "right"} {
assert_equal {bar foo} [r lrange target 0 -1]
assert_equal {bar foo} [r lrange target{t} 0 -1]
} else {
assert_equal {foo bar} [r lrange target 0 -1]
assert_equal {foo bar} [r lrange target{t} 0 -1]
}
}
}
......@@ -366,146 +350,138 @@ start_server {
test "BLMOVE ($wherefrom, $whereto) with a client BLPOPing the target list" {
set rd [redis_deferring_client]
set rd2 [redis_deferring_client]
r del blist target
$rd2 blpop target 0
$rd blmove blist target $wherefrom $whereto 0
wait_for_condition 100 10 {
[s blocked_clients] == 2
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
r del blist{t} target{t}
$rd2 blpop target{t} 0
$rd blmove blist{t} target{t} $wherefrom $whereto 0
wait_for_blocked_clients_count 2
r rpush blist{t} foo
assert_equal foo [$rd read]
assert_equal {target foo} [$rd2 read]
assert_equal 0 [r exists target]
assert_equal {target{t} foo} [$rd2 read]
assert_equal 0 [r exists target{t}]
}
}
}
test "BRPOPLPUSH with wrong source type" {
set rd [redis_deferring_client]
r del blist target
r set blist nolist
$rd brpoplpush blist target 1
r del blist{t} target{t}
r set blist{t} nolist
$rd brpoplpush blist{t} target{t} 1
assert_error "WRONGTYPE*" {$rd read}
}
test "BRPOPLPUSH with wrong destination type" {
set rd [redis_deferring_client]
r del blist target
r set target nolist
r lpush blist foo
$rd brpoplpush blist target 1
r del blist{t} target{t}
r set target{t} nolist
r lpush blist{t} foo
$rd brpoplpush blist{t} target{t} 1
assert_error "WRONGTYPE*" {$rd read}
set rd [redis_deferring_client]
r del blist target
r set target nolist
$rd brpoplpush blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
r del blist{t} target{t}
r set target{t} nolist
$rd brpoplpush blist{t} target{t} 0
wait_for_blocked_clients_count 1
r rpush blist{t} foo
assert_error "WRONGTYPE*" {$rd read}
assert_equal {foo} [r lrange blist 0 -1]
assert_equal {foo} [r lrange blist{t} 0 -1]
}
test "BRPOPLPUSH maintains order of elements after failure" {
set rd [redis_deferring_client]
r del blist target
r set target nolist
$rd brpoplpush blist target 0
r rpush blist a b c
r del blist{t} target{t}
r set target{t} nolist
$rd brpoplpush blist{t} target{t} 0
r rpush blist{t} a b c
assert_error "WRONGTYPE*" {$rd read}
r lrange blist 0 -1
r lrange blist{t} 0 -1
} {a b c}
test "BRPOPLPUSH with multiple blocked clients" {
set rd1 [redis_deferring_client]
set rd2 [redis_deferring_client]
r del blist target1 target2
r set target1 nolist
$rd1 brpoplpush blist target1 0
$rd2 brpoplpush blist target2 0
r lpush blist foo
r del blist{t} target1{t} target2{t}
r set target1{t} nolist
$rd1 brpoplpush blist{t} target1{t} 0
$rd2 brpoplpush blist{t} target2{t} 0
r lpush blist{t} foo
assert_error "WRONGTYPE*" {$rd1 read}
assert_equal {foo} [$rd2 read]
assert_equal {foo} [r lrange target2 0 -1]
assert_equal {foo} [r lrange target2{t} 0 -1]
}
test "Linked LMOVEs" {
set rd1 [redis_deferring_client]
set rd2 [redis_deferring_client]
r del list1 list2 list3
r del list1{t} list2{t} list3{t}
$rd1 blmove list1 list2 right left 0
$rd2 blmove list2 list3 left right 0
$rd1 blmove list1{t} list2{t} right left 0
$rd2 blmove list2{t} list3{t} left right 0
r rpush list1 foo
r rpush list1{t} foo
assert_equal {} [r lrange list1 0 -1]
assert_equal {} [r lrange list2 0 -1]
assert_equal {foo} [r lrange list3 0 -1]
assert_equal {} [r lrange list1{t} 0 -1]
assert_equal {} [r lrange list2{t} 0 -1]
assert_equal {foo} [r lrange list3{t} 0 -1]
}
test "Circular BRPOPLPUSH" {
set rd1 [redis_deferring_client]
set rd2 [redis_deferring_client]
r del list1 list2
r del list1{t} list2{t}
$rd1 brpoplpush list1 list2 0
$rd2 brpoplpush list2 list1 0
$rd1 brpoplpush list1{t} list2{t} 0
$rd2 brpoplpush list2{t} list1{t} 0
r rpush list1 foo
r rpush list1{t} foo
assert_equal {foo} [r lrange list1 0 -1]
assert_equal {} [r lrange list2 0 -1]
assert_equal {foo} [r lrange list1{t} 0 -1]
assert_equal {} [r lrange list2{t} 0 -1]
}
test "Self-referential BRPOPLPUSH" {
set rd [redis_deferring_client]
r del blist
r del blist{t}
$rd brpoplpush blist blist 0
$rd brpoplpush blist{t} blist{t} 0
r rpush blist foo
r rpush blist{t} foo
assert_equal {foo} [r lrange blist 0 -1]
assert_equal {foo} [r lrange blist{t} 0 -1]
}
test "BRPOPLPUSH inside a transaction" {
r del xlist target
r lpush xlist foo
r lpush xlist bar
r del xlist{t} target{t}
r lpush xlist{t} foo
r lpush xlist{t} bar
r multi
r brpoplpush xlist target 0
r brpoplpush xlist target 0
r brpoplpush xlist target 0
r lrange xlist 0 -1
r lrange target 0 -1
r brpoplpush xlist{t} target{t} 0
r brpoplpush xlist{t} target{t} 0
r brpoplpush xlist{t} target{t} 0
r lrange xlist{t} 0 -1
r lrange target{t} 0 -1
r exec
} {foo bar {} {} {bar foo}}
test "PUSH resulting from BRPOPLPUSH affect WATCH" {
set blocked_client [redis_deferring_client]
set watching_client [redis_deferring_client]
r del srclist dstlist somekey
r set somekey somevalue
$blocked_client brpoplpush srclist dstlist 0
$watching_client watch dstlist
r del srclist{t} dstlist{t} somekey{t}
r set somekey{t} somevalue
$blocked_client brpoplpush srclist{t} dstlist{t} 0
$watching_client watch dstlist{t}
$watching_client read
$watching_client multi
$watching_client read
$watching_client get somekey
$watching_client get somekey{t}
$watching_client read
r lpush srclist element
r lpush srclist{t} element
$watching_client exec
$watching_client read
} {}
......@@ -513,60 +489,52 @@ start_server {
test "BRPOPLPUSH does not affect WATCH while still blocked" {
set blocked_client [redis_deferring_client]
set watching_client [redis_deferring_client]
r del srclist dstlist somekey
r set somekey somevalue
$blocked_client brpoplpush srclist dstlist 0
$watching_client watch dstlist
r del srclist{t} dstlist{t} somekey{t}
r set somekey{t} somevalue
$blocked_client brpoplpush srclist{t} dstlist{t} 0
$watching_client watch dstlist{t}
$watching_client read
$watching_client multi
$watching_client read
$watching_client get somekey
$watching_client get somekey{t}
$watching_client read
$watching_client exec
# Blocked BLPOPLPUSH may create problems, unblock it.
r lpush srclist element
r lpush srclist{t} element
$watching_client read
} {somevalue}
test {BRPOPLPUSH timeout} {
set rd [redis_deferring_client]
$rd brpoplpush foo_list bar_list 1
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked client"
}
wait_for_condition 500 10 {
[s blocked_clients] == 0
} else {
fail "Timeout waiting for client to unblock"
}
$rd brpoplpush foo_list{t} bar_list{t} 1
wait_for_blocked_clients_count 1
wait_for_blocked_clients_count 0 500 10
$rd read
} {}
test "BLPOP when new key is moved into place" {
set rd [redis_deferring_client]
$rd blpop foo 5
r lpush bob abc def hij
r rename bob foo
$rd blpop foo{t} 5
r lpush bob{t} abc def hij
r rename bob{t} foo{t}
$rd read
} {foo hij}
} {foo{t} hij}
test "BLPOP when result key is created by SORT..STORE" {
set rd [redis_deferring_client]
# zero out list from previous test without explicit delete
r lpop foo
r lpop foo
r lpop foo
r lpop foo{t}
r lpop foo{t}
r lpop foo{t}
$rd blpop foo 5
r lpush notfoo hello hola aguacate konichiwa zanzibar
r sort notfoo ALPHA store foo
$rd blpop foo{t} 5
r lpush notfoo{t} hello hola aguacate konichiwa zanzibar
r sort notfoo{t} ALPHA store foo{t}
$rd read
} {foo aguacate}
} {foo{t} aguacate}
foreach {pop} {BLPOP BRPOP} {
test "$pop: with single empty list argument" {
......@@ -605,34 +573,34 @@ start_server {
test "$pop: second argument is not a list" {
set rd [redis_deferring_client]
r del blist1 blist2
r set blist2 nolist
$rd $pop blist1 blist2 1
r del blist1{t} blist2{t}
r set blist2{t} nolist{t}
$rd $pop blist1{t} blist2{t} 1
assert_error "WRONGTYPE*" {$rd read}
}
test "$pop: timeout" {
set rd [redis_deferring_client]
r del blist1 blist2
$rd $pop blist1 blist2 1
r del blist1{t} blist2{t}
$rd $pop blist1{t} blist2{t} 1
assert_equal {} [$rd read]
}
test "$pop: arguments are empty" {
set rd [redis_deferring_client]
r del blist1 blist2
$rd $pop blist1 blist2 1
r rpush blist1 foo
assert_equal {blist1 foo} [$rd read]
assert_equal 0 [r exists blist1]
assert_equal 0 [r exists blist2]
$rd $pop blist1 blist2 1
r rpush blist2 foo
assert_equal {blist2 foo} [$rd read]
assert_equal 0 [r exists blist1]
assert_equal 0 [r exists blist2]
r del blist1{t} blist2{t}
$rd $pop blist1{t} blist2{t} 1
r rpush blist1{t} foo
assert_equal {blist1{t} foo} [$rd read]
assert_equal 0 [r exists blist1{t}]
assert_equal 0 [r exists blist2{t}]
$rd $pop blist1{t} blist2{t} 1
r rpush blist2{t} foo
assert_equal {blist2{t} foo} [$rd read]
assert_equal 0 [r exists blist1{t}]
assert_equal 0 [r exists blist2{t}]
}
}
......@@ -726,7 +694,7 @@ start_server {
assert_encoding $type mylist
check_numbered_list_consistency mylist
check_random_access_consistency mylist
}
} {} {needs:debug}
}
test {LLEN against non-list value error} {
......@@ -757,60 +725,60 @@ start_server {
foreach {type large} [array get largevalue] {
test "RPOPLPUSH base case - $type" {
r del mylist1 mylist2
create_list mylist1 "a $large c d"
assert_equal d [r rpoplpush mylist1 mylist2]
assert_equal c [r rpoplpush mylist1 mylist2]
assert_equal "a $large" [r lrange mylist1 0 -1]
assert_equal "c d" [r lrange mylist2 0 -1]
assert_encoding quicklist mylist2
r del mylist1{t} mylist2{t}
create_list mylist1{t} "a $large c d"
assert_equal d [r rpoplpush mylist1{t} mylist2{t}]
assert_equal c [r rpoplpush mylist1{t} mylist2{t}]
assert_equal "a $large" [r lrange mylist1{t} 0 -1]
assert_equal "c d" [r lrange mylist2{t} 0 -1]
assert_encoding quicklist mylist2{t}
}
foreach wherefrom {left right} {
foreach whereto {left right} {
test "LMOVE $wherefrom $whereto base case - $type" {
r del mylist1 mylist2
r del mylist1{t} mylist2{t}
if {$wherefrom eq "right"} {
create_list mylist1 "c d $large a"
create_list mylist1{t} "c d $large a"
} else {
create_list mylist1 "a $large c d"
create_list mylist1{t} "a $large c d"
}
assert_equal a [r lmove mylist1 mylist2 $wherefrom $whereto]
assert_equal $large [r lmove mylist1 mylist2 $wherefrom $whereto]
assert_equal "c d" [r lrange mylist1 0 -1]
assert_equal a [r lmove mylist1{t} mylist2{t} $wherefrom $whereto]
assert_equal $large [r lmove mylist1{t} mylist2{t} $wherefrom $whereto]
assert_equal "c d" [r lrange mylist1{t} 0 -1]
if {$whereto eq "right"} {
assert_equal "a $large" [r lrange mylist2 0 -1]
assert_equal "a $large" [r lrange mylist2{t} 0 -1]
} else {
assert_equal "$large a" [r lrange mylist2 0 -1]
assert_equal "$large a" [r lrange mylist2{t} 0 -1]
}
assert_encoding quicklist mylist2
assert_encoding quicklist mylist2{t}
}
}
}
test "RPOPLPUSH with the same list as src and dst - $type" {
create_list mylist "a $large c"
assert_equal "a $large c" [r lrange mylist 0 -1]
assert_equal c [r rpoplpush mylist mylist]
assert_equal "c a $large" [r lrange mylist 0 -1]
create_list mylist{t} "a $large c"
assert_equal "a $large c" [r lrange mylist{t} 0 -1]
assert_equal c [r rpoplpush mylist{t} mylist{t}]
assert_equal "c a $large" [r lrange mylist{t} 0 -1]
}
foreach wherefrom {left right} {
foreach whereto {left right} {
test "LMOVE $wherefrom $whereto with the same list as src and dst - $type" {
if {$wherefrom eq "right"} {
create_list mylist "a $large c"
assert_equal "a $large c" [r lrange mylist 0 -1]
create_list mylist{t} "a $large c"
assert_equal "a $large c" [r lrange mylist{t} 0 -1]
} else {
create_list mylist "c a $large"
assert_equal "c a $large" [r lrange mylist 0 -1]
create_list mylist{t} "c a $large"
assert_equal "c a $large" [r lrange mylist{t} 0 -1]
}
assert_equal c [r lmove mylist mylist $wherefrom $whereto]
assert_equal c [r lmove mylist{t} mylist{t} $wherefrom $whereto]
if {$whereto eq "right"} {
assert_equal "a $large c" [r lrange mylist 0 -1]
assert_equal "a $large c" [r lrange mylist{t} 0 -1]
} else {
assert_equal "c a $large" [r lrange mylist 0 -1]
assert_equal "c a $large" [r lrange mylist{t} 0 -1]
}
}
}
......@@ -818,44 +786,44 @@ start_server {
foreach {othertype otherlarge} [array get largevalue] {
test "RPOPLPUSH with $type source and existing target $othertype" {
create_list srclist "a b c $large"
create_list dstlist "$otherlarge"
assert_equal $large [r rpoplpush srclist dstlist]
assert_equal c [r rpoplpush srclist dstlist]
assert_equal "a b" [r lrange srclist 0 -1]
assert_equal "c $large $otherlarge" [r lrange dstlist 0 -1]
create_list srclist{t} "a b c $large"
create_list dstlist{t} "$otherlarge"
assert_equal $large [r rpoplpush srclist{t} dstlist{t}]
assert_equal c [r rpoplpush srclist{t} dstlist{t}]
assert_equal "a b" [r lrange srclist{t} 0 -1]
assert_equal "c $large $otherlarge" [r lrange dstlist{t} 0 -1]
# When we rpoplpush'ed a large value, dstlist should be
# converted to the same encoding as srclist.
if {$type eq "linkedlist"} {
assert_encoding quicklist dstlist
assert_encoding quicklist dstlist{t}
}
}
foreach wherefrom {left right} {
foreach whereto {left right} {
test "LMOVE $wherefrom $whereto with $type source and existing target $othertype" {
create_list dstlist "$otherlarge"
create_list dstlist{t} "$otherlarge"
if {$wherefrom eq "right"} {
create_list srclist "a b c $large"
create_list srclist{t} "a b c $large"
} else {
create_list srclist "$large c a b"
create_list srclist{t} "$large c a b"
}
assert_equal $large [r lmove srclist dstlist $wherefrom $whereto]
assert_equal c [r lmove srclist dstlist $wherefrom $whereto]
assert_equal "a b" [r lrange srclist 0 -1]
assert_equal $large [r lmove srclist{t} dstlist{t} $wherefrom $whereto]
assert_equal c [r lmove srclist{t} dstlist{t} $wherefrom $whereto]
assert_equal "a b" [r lrange srclist{t} 0 -1]
if {$whereto eq "right"} {
assert_equal "$otherlarge $large c" [r lrange dstlist 0 -1]
assert_equal "$otherlarge $large c" [r lrange dstlist{t} 0 -1]
} else {
assert_equal "c $large $otherlarge" [r lrange dstlist 0 -1]
assert_equal "c $large $otherlarge" [r lrange dstlist{t} 0 -1]
}
# When we lmoved a large value, dstlist should be
# converted to the same encoding as srclist.
if {$type eq "linkedlist"} {
assert_encoding quicklist dstlist
assert_encoding quicklist dstlist{t}
}
}
}
......@@ -864,31 +832,31 @@ start_server {
}
test {RPOPLPUSH against non existing key} {
r del srclist dstlist
assert_equal {} [r rpoplpush srclist dstlist]
assert_equal 0 [r exists srclist]
assert_equal 0 [r exists dstlist]
r del srclist{t} dstlist{t}
assert_equal {} [r rpoplpush srclist{t} dstlist{t}]
assert_equal 0 [r exists srclist{t}]
assert_equal 0 [r exists dstlist{t}]
}
test {RPOPLPUSH against non list src key} {
r del srclist dstlist
r set srclist x
assert_error WRONGTYPE* {r rpoplpush srclist dstlist}
assert_type string srclist
assert_equal 0 [r exists newlist]
r del srclist{t} dstlist{t}
r set srclist{t} x
assert_error WRONGTYPE* {r rpoplpush srclist{t} dstlist{t}}
assert_type string srclist{t}
assert_equal 0 [r exists newlist{t}]
}
test {RPOPLPUSH against non list dst key} {
create_list srclist {a b c d}
r set dstlist x
assert_error WRONGTYPE* {r rpoplpush srclist dstlist}
assert_type string dstlist
assert_equal {a b c d} [r lrange srclist 0 -1]
create_list srclist{t} {a b c d}
r set dstlist{t} x
assert_error WRONGTYPE* {r rpoplpush srclist{t} dstlist{t}}
assert_type string dstlist{t}
assert_equal {a b c d} [r lrange srclist{t} 0 -1]
}
test {RPOPLPUSH against non existing src key} {
r del srclist dstlist
assert_equal {} [r rpoplpush srclist dstlist]
r del srclist{t} dstlist{t}
assert_equal {} [r rpoplpush srclist{t} dstlist{t}]
} {}
foreach {type large} [array get largevalue] {
......@@ -1121,7 +1089,7 @@ start_server {
set k [r lrange k 0 -1]
set dump [r dump k]
r config set sanitize-dump-payload no
config_set sanitize-dump-payload no mayfail
r restore kk 0 $dump
set kk [r lrange kk 0 -1]
......@@ -1141,7 +1109,7 @@ start_server {
} {12 0 9223372036854775808 2147483647 32767 127}
test {List ziplist of various encodings - sanitize dump} {
r config set sanitize-dump-payload yes
config_set sanitize-dump-payload yes mayfail
r restore kk 0 $dump replace
set k [r lrange k 0 -1]
set kk [r lrange kk 0 -1]
......
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