summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/acl.tcl14
-rw-r--r--tests/unit/aofrw.tcl2
-rw-r--r--tests/unit/client-eviction.tcl4
-rw-r--r--tests/unit/cluster/cli.tcl6
-rw-r--r--tests/unit/cluster/links.tcl4
-rw-r--r--tests/unit/expire.tcl14
-rw-r--r--tests/unit/info.tcl63
-rw-r--r--tests/unit/introspection-2.tcl4
-rw-r--r--tests/unit/introspection.tcl15
-rw-r--r--tests/unit/maxmemory.tcl4
-rw-r--r--tests/unit/moduleapi/cluster.tcl4
-rw-r--r--tests/unit/moduleapi/misc.tcl2
-rw-r--r--tests/unit/moduleapi/rdbloadsave.tcl200
-rw-r--r--tests/unit/moduleapi/reply.tcl11
-rw-r--r--tests/unit/moduleapi/stream.tcl17
-rw-r--r--tests/unit/moduleapi/testrdb.tcl8
-rw-r--r--tests/unit/moduleapi/zset.tcl20
-rw-r--r--tests/unit/multi.tcl6
-rw-r--r--tests/unit/querybuf.tcl32
-rw-r--r--tests/unit/shutdown.tcl30
-rw-r--r--tests/unit/slowlog.tcl9
-rw-r--r--tests/unit/type/hash.tcl11
-rw-r--r--tests/unit/type/incr.tcl11
-rw-r--r--tests/unit/type/list.tcl10
-rw-r--r--tests/unit/type/string.tcl16
-rw-r--r--tests/unit/type/zset.tcl40
-rw-r--r--tests/unit/wait.tcl66
27 files changed, 566 insertions, 57 deletions
diff --git a/tests/unit/acl.tcl b/tests/unit/acl.tcl
index 555fb5a34..4d8c77b9f 100644
--- a/tests/unit/acl.tcl
+++ b/tests/unit/acl.tcl
@@ -289,6 +289,20 @@ start_server {tags {"acl external:skip"}} {
$rd close
} {0}
+ test {Subscribers are killed when revoked of allchannels permission} {
+ set rd [redis_deferring_client]
+ r ACL setuser psuser allchannels
+ $rd AUTH psuser pspass
+ $rd read
+ $rd CLIENT SETNAME deathrow
+ $rd read
+ $rd PSUBSCRIBE foo
+ $rd read
+ r ACL setuser psuser resetchannels
+ assert_no_match {*deathrow*} [r CLIENT LIST]
+ $rd close
+ } {0}
+
test {Subscribers are pardoned if literal permissions are retained and/or gaining allchannels} {
set rd [redis_deferring_client]
r ACL setuser psuser resetchannels &foo:1 &bar:* &orders
diff --git a/tests/unit/aofrw.tcl b/tests/unit/aofrw.tcl
index fe07351a3..cc7545265 100644
--- a/tests/unit/aofrw.tcl
+++ b/tests/unit/aofrw.tcl
@@ -1,6 +1,6 @@
# This unit has the potential to create huge .reqres files, causing log-req-res-validator.py to run for a very long time...
# Since this unit doesn't do anything worth validating, reply_schema-wise, we decided to skip it
-start_server {tags {"aofrw external:skip logreqres:skip"}} {
+start_server {tags {"aofrw external:skip logreqres:skip"} overrides {save {}}} {
# Enable the AOF
r config set appendonly yes
r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite.
diff --git a/tests/unit/client-eviction.tcl b/tests/unit/client-eviction.tcl
index 76f7bf0f2..1fc7c02ca 100644
--- a/tests/unit/client-eviction.tcl
+++ b/tests/unit/client-eviction.tcl
@@ -347,12 +347,12 @@ start_server {} {
# We use two obuf-clients to make sure that even if client eviction is attempted
# between two command processing (with no sleep) we don't perform any client eviction
# because the obuf limit is enforced with precedence.
- exec kill -SIGSTOP $server_pid
+ pause_process $server_pid
$rr2 get k
$rr2 flush
$rr3 get k
$rr3 flush
- exec kill -SIGCONT $server_pid
+ resume_process $server_pid
r ping ;# make sure a full event loop cycle is processed before issuing CLIENT LIST
# Validate obuf-clients were disconnected (because of obuf limit)
diff --git a/tests/unit/cluster/cli.tcl b/tests/unit/cluster/cli.tcl
index 7131ee20f..5b7f24927 100644
--- a/tests/unit/cluster/cli.tcl
+++ b/tests/unit/cluster/cli.tcl
@@ -64,7 +64,7 @@ start_multiple_servers 3 [list overrides $base_conf] {
}
test "Wait for cluster to be stable" {
- # Cluster check just verifies the the config state is self-consistent,
+ # Cluster check just verifies the config state is self-consistent,
# waiting for cluster_state to be okay is an independent check that all the
# nodes actually believe each other are healthy, prevent cluster down error.
wait_for_condition 1000 50 {
@@ -116,7 +116,7 @@ start_multiple_servers 3 [list overrides $base_conf] {
test "Kill a cluster node and wait for fail state" {
# kill node3 in cluster
- exec kill -SIGSTOP $node3_pid
+ pause_process $node3_pid
wait_for_condition 1000 50 {
[CI 0 cluster_state] eq {fail} &&
@@ -134,7 +134,7 @@ start_multiple_servers 3 [list overrides $base_conf] {
assert_equal [s -1 blocked_clients] {0}
}
- exec kill -SIGCONT $node3_pid
+ resume_process $node3_pid
$node1_rd close
} ;# stop servers
diff --git a/tests/unit/cluster/links.tcl b/tests/unit/cluster/links.tcl
index 63c2b143c..a202c378b 100644
--- a/tests/unit/cluster/links.tcl
+++ b/tests/unit/cluster/links.tcl
@@ -200,7 +200,7 @@ start_cluster 3 0 {tags {external:skip cluster}} {
# To manufacture an ever-growing send buffer from primary1 to primary2,
# make primary2 unresponsive.
set primary2_pid [srv [expr -1*$primary2_id] pid]
- exec kill -SIGSTOP $primary2_pid
+ pause_process $primary2_pid
# On primary1, send 128KB Pubsub messages in a loop until the send buffer of the link from
# primary1 to primary2 exceeds buffer limit therefore be dropped.
@@ -226,7 +226,7 @@ start_cluster 3 0 {tags {external:skip cluster}} {
assert {[dict get $same_link_p1_from_p2 create-time] eq [dict get $orig_link_p1_from_p2 create-time]}
# Revive primary2
- exec kill -SIGCONT $primary2_pid
+ resume_process $primary2_pid
# Reset configs on primary1 so config changes don't leak out to other tests
$primary1 CONFIG set cluster-node-timeout $oldtimeout
diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl
index 5ee4488b3..ec9d73cc2 100644
--- a/tests/unit/expire.tcl
+++ b/tests/unit/expire.tcl
@@ -76,20 +76,22 @@ start_server {tags {"expire"}} {
# This test is very likely to do a false positive if the
# server is under pressure, so if it does not work give it a few more
# chances.
- for {set j 0} {$j < 10} {incr j} {
+ for {set j 0} {$j < 30} {incr j} {
r del x
r setex x 1 somevalue
- after 900
+ after 800
set a [r get x]
- after 1100
+ if {$a ne {somevalue}} continue
+ after 300
set b [r get x]
- if {$a eq {somevalue} && $b eq {}} break
+ if {$b eq {}} break
}
if {$::verbose} {
puts "millisecond expire test attempts: $j"
}
- list $a $b
- } {somevalue {}}
+ assert_equal $a {somevalue}
+ assert_equal $b {}
+ }
test "PSETEX can set sub-second expires" {
# This test is very likely to do a false positive if the server is
diff --git a/tests/unit/info.tcl b/tests/unit/info.tcl
index 759e5bc0b..2f3ad8d6f 100644
--- a/tests/unit/info.tcl
+++ b/tests/unit/info.tcl
@@ -274,5 +274,68 @@ start_server {tags {"info" "external:skip"}} {
$rd close
}
+ test {stats: eventloop metrics} {
+ set info1 [r info stats]
+ set cycle1 [getInfoProperty $info1 eventloop_cycles]
+ set el_sum1 [getInfoProperty $info1 eventloop_duration_sum]
+ set cmd_sum1 [getInfoProperty $info1 eventloop_duration_cmd_sum]
+ assert_morethan $cycle1 0
+ assert_morethan $el_sum1 0
+ assert_morethan $cmd_sum1 0
+ after 110 ;# default hz is 10, wait for a cron tick.
+ set info2 [r info stats]
+ set cycle2 [getInfoProperty $info2 eventloop_cycles]
+ set el_sum2 [getInfoProperty $info2 eventloop_duration_sum]
+ set cmd_sum2 [getInfoProperty $info2 eventloop_duration_cmd_sum]
+ assert_morethan $cycle2 $cycle1
+ assert_lessthan $cycle2 [expr $cycle1+10] ;# we expect 2 or 3 cycles here, but allow some tolerance
+ assert_morethan $el_sum2 $el_sum1
+ assert_lessthan $el_sum2 [expr $el_sum1+5000] ;# we expect roughly 100ms here, but allow some tolerance
+ assert_morethan $cmd_sum2 $cmd_sum1
+ assert_lessthan $cmd_sum2 [expr $cmd_sum1+3000] ;# we expect about tens of ms here, but allow some tolerance
+ }
+
+ test {stats: instantaneous metrics} {
+ r config resetstat
+ after 1600 ;# hz is 10, wait for 16 cron tick so that sample array is fulfilled
+ set value [s instantaneous_eventloop_cycles_per_sec]
+ assert_morethan $value 0
+ assert_lessthan $value 15 ;# default hz is 10
+ set value [s instantaneous_eventloop_duration_usec]
+ assert_morethan $value 0
+ assert_lessthan $value 22000 ;# default hz is 10, so duration < 1000 / 10, allow some tolerance
+ }
+
+ test {stats: debug metrics} {
+ # make sure debug info is hidden
+ set info [r info]
+ assert_equal [getInfoProperty $info eventloop_duration_aof_sum] {}
+ set info_all [r info all]
+ assert_equal [getInfoProperty $info_all eventloop_duration_aof_sum] {}
+
+ set info1 [r info debug]
+
+ set aof1 [getInfoProperty $info1 eventloop_duration_aof_sum]
+ assert {$aof1 >= 0}
+ set cron1 [getInfoProperty $info1 eventloop_duration_cron_sum]
+ assert {$cron1 > 0}
+ set cycle_max1 [getInfoProperty $info1 eventloop_cmd_per_cycle_max]
+ assert {$cycle_max1 > 0}
+ set duration_max1 [getInfoProperty $info1 eventloop_duration_max]
+ assert {$duration_max1 > 0}
+
+ after 110 ;# hz is 10, wait for a cron tick.
+ set info2 [r info debug]
+
+ set aof2 [getInfoProperty $info2 eventloop_duration_aof_sum]
+ assert {$aof2 >= $aof1} ;# AOF is disabled, we expect $aof2 == $aof1, but allow some tolerance.
+ set cron2 [getInfoProperty $info2 eventloop_duration_cron_sum]
+ assert_morethan $cron2 $cron1
+ set cycle_max2 [getInfoProperty $info2 eventloop_cmd_per_cycle_max]
+ assert {$cycle_max2 >= $cycle_max1}
+ set duration_max2 [getInfoProperty $info2 eventloop_duration_max]
+ assert {$duration_max2 >= $duration_max1}
+ }
+
}
}
diff --git a/tests/unit/introspection-2.tcl b/tests/unit/introspection-2.tcl
index a0cf0c30f..52a13edf7 100644
--- a/tests/unit/introspection-2.tcl
+++ b/tests/unit/introspection-2.tcl
@@ -118,6 +118,10 @@ start_server {tags {"introspection"}} {
assert_match {*calls=1,*} [cmdstat geoadd]
} {} {needs:config-resetstat}
+ test {COMMAND COUNT get total number of Redis commands} {
+ assert_morethan [r command count] 0
+ }
+
test {COMMAND GETKEYS GET} {
assert_equal {key} [r command getkeys get key]
}
diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl
index 4452de6b1..76d56ee65 100644
--- a/tests/unit/introspection.tcl
+++ b/tests/unit/introspection.tcl
@@ -340,10 +340,10 @@ start_server {tags {"introspection"}} {
r client info
} {*lib-name=redis.py lib-ver=1.2.3*}
- test {RESET doesn NOT clean library name} {
+ test {RESET does NOT clean library name} {
r reset
r client info
- } {*lib-name=redis.py*}
+ } {*lib-name=redis.py*} {needs:reset}
test {CLIENT SETINFO can clear library name} {
r CLIENT SETINFO lib-name ""
@@ -362,18 +362,13 @@ start_server {tags {"introspection"}} {
assert_match [r config get save] {save {100 100}}
}
- # First "save" keyword in default config file
- start_server {config "default.conf"} {
- assert_match [r config get save] {save {900 1}}
- }
-
# First "save" keyword appends default from config file
- start_server {config "default.conf" args {--save 100 100}} {
+ start_server {config "default.conf" overrides {save {900 1}} args {--save 100 100}} {
assert_match [r config get save] {save {900 1 100 100}}
}
# Empty "save" keyword resets all
- start_server {config "default.conf" args {--save {}}} {
+ start_server {config "default.conf" overrides {save {900 1}} args {--save {}}} {
assert_match [r config get save] {save {}}
}
} {} {external:skip}
@@ -789,7 +784,7 @@ start_server {config "minimal.conf" tags {"introspection external:skip"} overrid
}
test {config during loading} {
- start_server [list overrides [list key-load-delay 50 loading-process-events-interval-bytes 1024 rdbcompression no]] {
+ start_server [list overrides [list key-load-delay 50 loading-process-events-interval-bytes 1024 rdbcompression no save "900 1"]] {
# create a big rdb that will take long to load. it is important
# for keys to be big since the server processes events only once in 2mb.
# 100mb of rdb, 100k keys will load in more than 5 seconds
diff --git a/tests/unit/maxmemory.tcl b/tests/unit/maxmemory.tcl
index 564250f2e..54aba6715 100644
--- a/tests/unit/maxmemory.tcl
+++ b/tests/unit/maxmemory.tcl
@@ -350,7 +350,7 @@ proc test_slave_buffers {test_name cmd_count payload_len limit_memory pipeline}
# put the slave to sleep
set rd_slave [redis_deferring_client]
- exec kill -SIGSTOP $slave_pid
+ pause_process $slave_pid
# send some 10mb worth of commands that don't increase the memory usage
if {$pipeline == 1} {
@@ -399,7 +399,7 @@ proc test_slave_buffers {test_name cmd_count payload_len limit_memory pipeline}
}
# unfreeze slave process (after the 'test' succeeded or failed, but before we attempt to terminate the server
- exec kill -SIGCONT $slave_pid
+ resume_process $slave_pid
}
}
}
diff --git a/tests/unit/moduleapi/cluster.tcl b/tests/unit/moduleapi/cluster.tcl
index 43356f77d..807508387 100644
--- a/tests/unit/moduleapi/cluster.tcl
+++ b/tests/unit/moduleapi/cluster.tcl
@@ -132,7 +132,7 @@ start_cluster 3 0 [list config_lines $modules] {
test "Kill a cluster node and wait for fail state" {
# kill node3 in cluster
- exec kill -SIGSTOP $node3_pid
+ pause_process $node3_pid
wait_for_condition 1000 50 {
[CI 0 cluster_state] eq {fail} &&
@@ -158,7 +158,7 @@ start_cluster 3 0 [list config_lines $modules] {
assert_error "ERR Can not execute a command 'set' while the cluster is down" {$node1 do_rm_call set x 1}
}
- exec kill -SIGCONT $node3_pid
+ resume_process $node3_pid
$node1_rd close
$node2_rd close
}
diff --git a/tests/unit/moduleapi/misc.tcl b/tests/unit/moduleapi/misc.tcl
index 6bf7b8c2a..9b0989149 100644
--- a/tests/unit/moduleapi/misc.tcl
+++ b/tests/unit/moduleapi/misc.tcl
@@ -1,6 +1,6 @@
set testmodule [file normalize tests/modules/misc.so]
-start_server {tags {"modules"}} {
+start_server {overrides {save {900 1}} tags {"modules"}} {
r module load $testmodule
test {test RM_Call} {
diff --git a/tests/unit/moduleapi/rdbloadsave.tcl b/tests/unit/moduleapi/rdbloadsave.tcl
new file mode 100644
index 000000000..9319c9385
--- /dev/null
+++ b/tests/unit/moduleapi/rdbloadsave.tcl
@@ -0,0 +1,200 @@
+set testmodule [file normalize tests/modules/rdbloadsave.so]
+
+start_server {tags {"modules"}} {
+ r module load $testmodule
+
+ test "Module rdbloadsave sanity" {
+ r test.sanity
+
+ # Try to load non-existing file
+ assert_error {*No such file or directory*} {r test.rdbload sanity.rdb}
+
+ r set x 1
+ assert_equal OK [r test.rdbsave sanity.rdb]
+
+ r flushdb
+ assert_equal OK [r test.rdbload sanity.rdb]
+ assert_equal 1 [r get x]
+ }
+
+ test "Module rdbloadsave test with pipelining" {
+ r config set save ""
+ r config set loading-process-events-interval-bytes 1024
+ r config set key-load-delay 50
+ r flushdb
+
+ populate 3000 a 1024
+ r set x 111
+ assert_equal [r dbsize] 3001
+
+ assert_equal OK [r test.rdbsave blabla.rdb]
+ r flushdb
+ assert_equal [r dbsize] 0
+
+ # Send commands with pipeline. First command will call RM_RdbLoad() in
+ # the command callback. While loading RDB, Redis can go to networking to
+ # reply -LOADING. By sending commands in pipeline, we verify it doesn't
+ # cause a problem.
+ # e.g. Redis won't try to process next message of the current client
+ # while it is in the command callback for that client .
+ set rd1 [redis_deferring_client]
+ $rd1 test.rdbload blabla.rdb
+
+ wait_for_condition 50 100 {
+ [s loading] eq 1
+ } else {
+ fail "Redis did not start loading or loaded RDB too fast"
+ }
+
+ $rd1 get x
+ $rd1 dbsize
+
+ assert_equal OK [$rd1 read]
+ assert_equal 111 [$rd1 read]
+ assert_equal 3001 [$rd1 read]
+ r flushdb
+ r config set key-load-delay 0
+ }
+
+ test "Module rdbloadsave with aof" {
+ r config set save ""
+
+ # Enable the AOF
+ r config set appendonly yes
+ r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite.
+ waitForBgrewriteaof r
+
+ r set k v1
+ assert_equal OK [r test.rdbsave aoftest.rdb]
+
+ r set k v2
+ r config set rdb-key-save-delay 10000000
+ r bgrewriteaof
+
+ # RM_RdbLoad() should kill aof fork
+ assert_equal OK [r test.rdbload aoftest.rdb]
+
+ wait_for_condition 50 100 {
+ [string match {*Killing*AOF*child*} [exec tail -20 < [srv 0 stdout]]]
+ } else {
+ fail "Can't find 'Killing AOF child' in recent log lines"
+ }
+
+ # Verify the value in the loaded rdb
+ assert_equal v1 [r get k]
+
+ r flushdb
+ r config set rdb-key-save-delay 0
+ r config set appendonly no
+ }
+
+ test "Module rdbloadsave with bgsave" {
+ r flushdb
+ r config set save ""
+
+ r set k v1
+ assert_equal OK [r test.rdbsave bgsave.rdb]
+
+ r set k v2
+ r config set rdb-key-save-delay 500000
+ r bgsave
+
+ # RM_RdbLoad() should kill RDB fork
+ assert_equal OK [r test.rdbload bgsave.rdb]
+
+ wait_for_condition 10 1000 {
+ [string match {*Background*saving*terminated*} [exec tail -20 < [srv 0 stdout]]]
+ } else {
+ fail "Can't find 'Background saving terminated' in recent log lines"
+ }
+
+ assert_equal v1 [r get k]
+ r flushall
+ waitForBgsave r
+ r config set rdb-key-save-delay 0
+ }
+
+ test "Module rdbloadsave calls rdbsave in a module fork" {
+ r flushdb
+ r config set save ""
+ r config set rdb-key-save-delay 500000
+
+ r set k v1
+
+ # Module will call RM_Fork() before calling RM_RdbSave()
+ assert_equal OK [r test.rdbsave_fork rdbfork.rdb]
+ assert_equal [s module_fork_in_progress] 1
+
+ wait_for_condition 10 1000 {
+ [status r module_fork_in_progress] == "0"
+ } else {
+ fail "Module fork didn't finish"
+ }
+
+ r set k v2
+ assert_equal OK [r test.rdbload rdbfork.rdb]
+ assert_equal v1 [r get k]
+
+ r config set rdb-key-save-delay 0
+ }
+
+ test "Unload the module - rdbloadsave" {
+ assert_equal {OK} [r module unload rdbloadsave]
+ }
+
+ tags {repl} {
+ test {Module rdbloadsave on master and replica} {
+ start_server [list overrides [list loadmodule "$testmodule"]] {
+ set replica [srv 0 client]
+ set replica_host [srv 0 host]
+ set replica_port [srv 0 port]
+ start_server [list overrides [list loadmodule "$testmodule"]] {
+ set master [srv 0 client]
+ set master_host [srv 0 host]
+ set master_port [srv 0 port]
+
+ $master set x 10000
+
+ # Start the replication process...
+ $replica replicaof $master_host $master_port
+
+ wait_for_condition 100 100 {
+ [status $master sync_full] == 1
+ } else {
+ fail "Master <-> Replica didn't start the full sync"
+ }
+
+ # RM_RdbSave() is allowed on replicas
+ assert_equal OK [$replica test.rdbsave rep.rdb]
+
+ # RM_RdbLoad() is not allowed on replicas
+ assert_error {*supported*} {$replica test.rdbload rep.rdb}
+
+ assert_equal OK [$master test.rdbsave master.rdb]
+ $master set x 20000
+
+ wait_for_condition 100 100 {
+ [$replica get x] == 20000
+ } else {
+ fail "Replica didn't get the update"
+ }
+
+ # Loading RDB on master will drop replicas
+ assert_equal OK [$master test.rdbload master.rdb]
+
+ wait_for_condition 100 100 {
+ [status $master sync_full] == 2
+ } else {
+ fail "Master <-> Replica didn't start the full sync"
+ }
+
+ wait_for_condition 100 100 {
+ [$replica get x] == 10000
+ } else {
+ fail "Replica didn't get the update"
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/unit/moduleapi/reply.tcl b/tests/unit/moduleapi/reply.tcl
index 291253d3c..547be21c0 100644
--- a/tests/unit/moduleapi/reply.tcl
+++ b/tests/unit/moduleapi/reply.tcl
@@ -126,6 +126,17 @@ start_server {tags {"modules"}} {
assert_match "An error" $e
}
+ test "RESP$proto: RM_ReplyWithErrorFormat: error format reply" {
+ catch {r rw.error_format "An error: %s" foo} e
+ assert_match "ERR An error: foo" $e
+
+ catch {r rw.error_format "-ERR An error: %s" foo2} e
+ assert_match "ERR An error: foo2" $e
+
+ catch {r rw.error_format "-WRONGTYPE A type error: %s" foo3} e
+ assert_match "WRONGTYPE A type error: foo3" $e
+ }
+
r hello 2
}
diff --git a/tests/unit/moduleapi/stream.tcl b/tests/unit/moduleapi/stream.tcl
index 80c24ff6c..7ad1a3059 100644
--- a/tests/unit/moduleapi/stream.tcl
+++ b/tests/unit/moduleapi/stream.tcl
@@ -61,6 +61,23 @@ start_server {tags {"modules"}} {
assert_equal $result $n
}
+ test {Module stream XADD big fields doesn't create empty key} {
+ set original_proto [config_get_set proto-max-bulk-len 2147483647] ;#2gb
+ set original_query [config_get_set client-query-buffer-limit 2147483647] ;#2gb
+
+ r del mystream
+ r write "*4\r\n\$10\r\nstream.add\r\n\$8\r\nmystream\r\n\$5\r\nfield\r\n"
+ catch {
+ write_big_bulk 1073741824 ;#1gb
+ } err
+ assert {$err eq "ERR StreamAdd failed"}
+ assert_equal 0 [r exists mystream]
+
+ # restore defaults
+ r config set proto-max-bulk-len $original_proto
+ r config set client-query-buffer-limit $original_query
+ } {OK} {large-memory}
+
test {Module stream iterator} {
r del mystream
set streamid1 [r xadd mystream * item 1 value a]
diff --git a/tests/unit/moduleapi/testrdb.tcl b/tests/unit/moduleapi/testrdb.tcl
index 2545a8ad2..ae3036f70 100644
--- a/tests/unit/moduleapi/testrdb.tcl
+++ b/tests/unit/moduleapi/testrdb.tcl
@@ -61,13 +61,13 @@ tags "modules" {
# 7 == 0111 - use aux_save2 before and after key space with data
test {modules are able to persist globals before and after} {
set server_path [tmpdir "server.module-testrdb"]
- start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path] keep_persistence true] {
+ start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path "save" "900 1"] keep_persistence true] {
r testrdb.set.before global1
r testrdb.set.after global2
assert_equal "global1" [r testrdb.get.before]
assert_equal "global2" [r testrdb.get.after]
}
- start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path]] {
+ start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path "save" "900 1"]] {
assert_equal "global1" [r testrdb.get.before]
assert_equal "global2" [r testrdb.get.after]
}
@@ -80,11 +80,11 @@ tags "modules" {
# 5 == 0101 - use aux_save2 after key space with data
test {modules are able to persist globals just after} {
set server_path [tmpdir "server.module-testrdb"]
- start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path] keep_persistence true] {
+ start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path "save" "900 1"] keep_persistence true] {
r testrdb.set.after global2
assert_equal "global2" [r testrdb.get.after]
}
- start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path]] {
+ start_server [list overrides [list loadmodule "$testmodule $test_case" "dir" $server_path "save" "900 1"]] {
assert_equal "global2" [r testrdb.get.after]
}
}
diff --git a/tests/unit/moduleapi/zset.tcl b/tests/unit/moduleapi/zset.tcl
index 1c146eaf4..b6ab41d5f 100644
--- a/tests/unit/moduleapi/zset.tcl
+++ b/tests/unit/moduleapi/zset.tcl
@@ -14,6 +14,26 @@ start_server {tags {"modules"}} {
assert_equal 0 [r exists k]
}
+ test {Module zset add} {
+ r del k
+ # Check that failure does not create empty key
+ assert_error "ERR ZsetAdd failed" {r zset.add k nan hello}
+ assert_equal 0 [r exists k]
+
+ r zset.add k 100 hello
+ assert_equal {hello 100} [r zrange k 0 -1 withscores]
+ }
+
+ test {Module zset incrby} {
+ r del k
+ # Check that failure does not create empty key
+ assert_error "ERR ZsetIncrby failed" {r zset.incrby k hello nan}
+ assert_equal 0 [r exists k]
+
+ r zset.incrby k hello 100
+ assert_equal {hello 100} [r zrange k 0 -1 withscores]
+ }
+
test "Unload the module - zset" {
assert_equal {OK} [r module unload zset]
}
diff --git a/tests/unit/multi.tcl b/tests/unit/multi.tcl
index bdf398150..851e02247 100644
--- a/tests/unit/multi.tcl
+++ b/tests/unit/multi.tcl
@@ -891,14 +891,14 @@ start_server {tags {"multi"}} {
set res [r read]
assert_equal $res "+OK"
set res [r read]
- r readraw 1
+ r readraw 0
set _ $res
} {*CONFIG SET failed*}
test "Flushall while watching several keys by one client" {
r flushall
- r mset a a b b
- r watch b a
+ r mset a{t} a b{t} b
+ r watch b{t} a{t}
r flushall
r ping
}
diff --git a/tests/unit/querybuf.tcl b/tests/unit/querybuf.tcl
index bbbea12f4..f4859dd27 100644
--- a/tests/unit/querybuf.tcl
+++ b/tests/unit/querybuf.tcl
@@ -5,7 +5,7 @@ proc client_idle_sec {name} {
return $idle
}
-# Calculate query buffer memory of slave
+# Calculate query buffer memory of client
proc client_query_buffer {name} {
set clients [split [r client list] "\r\n"]
set c [lsearch -inline $clients *name=$name*]
@@ -18,6 +18,9 @@ proc client_query_buffer {name} {
}
start_server {tags {"querybuf slow"}} {
+ # increase the execution frequency of clientsCron
+ r config set hz 100
+
# The test will run at least 2s to check if client query
# buffer will be resized when client idle 2s.
test "query buffer resized correctly" {
@@ -38,6 +41,9 @@ start_server {tags {"querybuf slow"}} {
}
test "query buffer resized correctly when not idle" {
+ # Pause cron to prevent premature shrinking (timing issue).
+ r debug pause-cron 1
+
# Memory will increase by more than 32k due to client query buffer.
set rd [redis_client]
$rd client setname test_client
@@ -49,6 +55,8 @@ start_server {tags {"querybuf slow"}} {
set orig_test_client_qbuf [client_query_buffer test_client]
assert {$orig_test_client_qbuf > 32768}
+ r debug pause-cron 0
+
# Wait for qbuf to shrink due to lower peak
set t [clock milliseconds]
while true {
@@ -62,5 +70,27 @@ start_server {tags {"querybuf slow"}} {
# Validate qbuf shrunk but isn't 0 since we maintain room based on latest peak
assert {[client_query_buffer test_client] > 0 && [client_query_buffer test_client] < $orig_test_client_qbuf}
$rd close
+ } {0} {needs:debug}
+
+ test "query buffer resized correctly with fat argv" {
+ set rd [redis_client]
+ $rd client setname test_client
+ $rd write "*3\r\n\$3\r\nset\r\n\$1\r\na\r\n\$1000000\r\n"
+ $rd flush
+
+ after 20
+ if {[client_query_buffer test_client] < 1000000} {
+ fail "query buffer should not be resized when client idle time smaller than 2s"
+ }
+
+ # Check that the query buffer is resized after 2 sec
+ wait_for_condition 1000 10 {
+ [client_idle_sec test_client] >= 3 && [client_query_buffer test_client] < 1000000
+ } else {
+ fail "query buffer should be resized when client idle time bigger than 2s"
+ }
+
+ $rd close
}
+
}
diff --git a/tests/unit/shutdown.tcl b/tests/unit/shutdown.tcl
index b419c83a1..7504851a1 100644
--- a/tests/unit/shutdown.tcl
+++ b/tests/unit/shutdown.tcl
@@ -30,7 +30,7 @@ start_server {tags {"shutdown external:skip"}} {
}
}
-start_server {tags {"shutdown external:skip"}} {
+start_server {tags {"shutdown external:skip"} overrides {save {900 1}}} {
test {SHUTDOWN ABORT can cancel SIGTERM} {
r debug pause-cron 1
set pid [s process_id]
@@ -48,7 +48,7 @@ start_server {tags {"shutdown external:skip"}} {
}
# It will cost 2s (20 * 100ms) to dump rdb
r config set rdb-key-save-delay 100000
-
+
set pid [s process_id]
set temp_rdb [file join [lindex [r config get dir] 1] temp-${pid}.rdb]
@@ -72,7 +72,7 @@ start_server {tags {"shutdown external:skip"}} {
}
}
-start_server {tags {"shutdown external:skip"}} {
+start_server {tags {"shutdown external:skip"} overrides {save {900 1}}} {
set pid [s process_id]
set dump_rdb [file join [lindex [r config get dir] 1] dump.rdb]
@@ -107,3 +107,27 @@ start_server {tags {"shutdown external:skip"}} {
exec rm -r $dump_rdb
}
}
+
+
+start_server {tags {"shutdown external:skip"} overrides {appendonly no}} {
+ test {SHUTDOWN SIGTERM will abort if there's an initial AOFRW - default} {
+ r config set shutdown-on-sigterm default
+ r config set rdb-key-save-delay 10000000
+ for {set i 0} {$i < 10} {incr i} {
+ r set $i $i
+ }
+
+ r config set appendonly yes
+ wait_for_condition 1000 10 {
+ [s aof_rewrite_in_progress] eq 1
+ } else {
+ fail "aof rewrite did not start in time"
+ }
+
+ set pid [s process_id]
+ exec kill -SIGTERM $pid
+ wait_for_log_messages 0 {"*Writing initial AOF, can't exit*"} 0 1000 10
+
+ r config set shutdown-on-sigterm force
+ }
+}
diff --git a/tests/unit/slowlog.tcl b/tests/unit/slowlog.tcl
index bc15c6411..3c547b924 100644
--- a/tests/unit/slowlog.tcl
+++ b/tests/unit/slowlog.tcl
@@ -24,8 +24,11 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
} {10}
test {SLOWLOG - GET optional argument to limit output len works} {
- llength [r slowlog get 5]
- } {5}
+
+ assert_equal 5 [llength [r slowlog get 5]]
+ assert_equal 10 [llength [r slowlog get -1]]
+ assert_equal 10 [llength [r slowlog get 20]]
+ }
test {SLOWLOG - RESET subcommand works} {
r config set slowlog-log-slower-than 100000
@@ -39,7 +42,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
set e [lindex [r slowlog get] 0]
assert_equal [llength $e] 6
if {!$::external} {
- assert_equal [lindex $e 0] 105
+ assert_equal [lindex $e 0] 107
}
assert_equal [expr {[lindex $e 2] > 100000}] 1
assert_equal [lindex $e 3] {debug sleep 0.2}
diff --git a/tests/unit/type/hash.tcl b/tests/unit/type/hash.tcl
index 17e3ba40b..4cff0f244 100644
--- a/tests/unit/type/hash.tcl
+++ b/tests/unit/type/hash.tcl
@@ -350,9 +350,16 @@ start_server {tags {"hash"}} {
set _ $rv
} {{{} {}} {{} {}} {{} {}}}
- test {HMGET against wrong type} {
+ test {HMGET HRANDFIELD HGET HGETALL HDEL HINCRBY HINCRBYFLOAT HSTRLEN against wrong type} {
r set wrongtype somevalue
- assert_error "*wrong*" {r hmget wrongtype field1 field2}
+ assert_error "WRONGTYPE Operation against a key*" {r hmget wrongtype field1 field2}
+ assert_error "WRONGTYPE Operation against a key*" {r hrandfield wrongtype}
+ assert_error "WRONGTYPE Operation against a key*" {r hget wrongtype field1}
+ assert_error "WRONGTYPE Operation against a key*" {r hgetall wrongtype}
+ assert_error "WRONGTYPE Operation against a key*" {r hdel wrongtype field1}
+ assert_error "WRONGTYPE Operation against a key*" {r hincrby wrongtype field1 2}
+ assert_error "WRONGTYPE Operation against a key*" {r hincrbyfloat wrongtype field1 2.5}
+ assert_error "WRONGTYPE Operation against a key*" {r hstrlen wrongtype field1}
}
test {HMGET - small hash} {
diff --git a/tests/unit/type/incr.tcl b/tests/unit/type/incr.tcl
index a64f357ae..c09f2e8b2 100644
--- a/tests/unit/type/incr.tcl
+++ b/tests/unit/type/incr.tcl
@@ -13,6 +13,12 @@ start_server {tags {"incr"}} {
r decr novar
} {1}
+ test {DECR against key is not exist and incr} {
+ r del novar_not_exist
+ assert_equal {-1} [r decr novar_not_exist]
+ assert_equal {0} [r incr novar_not_exist]
+ }
+
test {INCR against key originally set with SET} {
r set novar 100
r incr novar
@@ -64,6 +70,11 @@ start_server {tags {"incr"}} {
r decrby novar 17179869185
} {-1}
+ test {DECRBY against key is not exist} {
+ r del key_not_exist
+ assert_equal {-1} [r decrby key_not_exist 1]
+ }
+
test {INCR uses shared objects in the 0-9999 range} {
r set foo -1
r incr foo
diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl
index d970b0278..a57e5df3e 100644
--- a/tests/unit/type/list.tcl
+++ b/tests/unit/type/list.tcl
@@ -464,6 +464,7 @@ foreach {type large} [array get largevalue] {
assert {[r LPOS mylist c RANK -1] == 7}
assert {[r LPOS mylist c RANK -2] == 6}
assert_error "*RANK can't be zero: use 1 to start from the first match, 2 from the second ... or use negative to start*" {r LPOS mylist c RANK 0}
+ assert_error "*value is out of range*" {r LPOS mylist c RANK -9223372036854775808}
}
test {LPOS COUNT option} {
@@ -1416,6 +1417,15 @@ foreach {pop} {BLPOP BLMPOP_LEFT} {
set e
} {*ERR*syntax*error*}
+ test {LINSERT against non-list value error} {
+ r set k1 v1
+ assert_error {WRONGTYPE Operation against a key holding the wrong kind of value*} {r linsert k1 after 0 0}
+ }
+
+ test {LINSERT against non existing key} {
+ assert_equal 0 [r linsert not-a-key before 0 0]
+ }
+
foreach type {listpack quicklist} {
foreach {num} {250 500} {
if {$type == "quicklist"} {
diff --git a/tests/unit/type/string.tcl b/tests/unit/type/string.tcl
index b25a14f4c..68c360b97 100644
--- a/tests/unit/type/string.tcl
+++ b/tests/unit/type/string.tcl
@@ -151,6 +151,14 @@ start_server {tags {"string"}} {
set ex
} {*syntax*}
+ test "GETEX and GET expired key or not exist" {
+ r del foo
+ r set foo bar px 1
+ after 2
+ assert_equal {} [r getex foo]
+ assert_equal {} [r get foo]
+ }
+
test "GETEX no arguments" {
set ex {}
catch {r getex} ex
@@ -438,6 +446,11 @@ start_server {tags {"string"}} {
assert_equal "" [r getrange mykey 0 -1]
}
+ test "GETRANGE against wrong key type" {
+ r lpush lkey1 "list"
+ assert_error {WRONGTYPE Operation against a key holding the wrong kind of value*} {r getrange lkey1 0 -1}
+ }
+
test "GETRANGE against string value" {
r set mykey "Hello World"
assert_equal "Hell" [r getrange mykey 0 3]
@@ -474,6 +487,9 @@ start_server {tags {"string"}} {
assert_equal "a" [r substr key 0 0]
assert_equal "abcd" [r substr key 0 3]
assert_equal "bcde" [r substr key -4 -1]
+ assert_equal "" [r substr key -1 -3]
+ assert_equal "" [r substr key 7 8]
+ assert_equal "" [r substr nokey 0 1]
}
if {[string match {*jemalloc*} [s mem_allocator]]} {
diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl
index a52a77f24..d1da02778 100644
--- a/tests/unit/type/zset.tcl
+++ b/tests/unit/type/zset.tcl
@@ -755,6 +755,46 @@ start_server {tags {"zset"}} {
assert_equal 0 [r exists zset]
}
+ test "ZREMRANGEBYLEX basics - $encoding" {
+ proc remrangebylex {min max} {
+ create_default_lex_zset
+ assert_equal 1 [r exists zset]
+ r zremrangebylex zset $min $max
+ }
+
+ # inclusive range
+ assert_equal 3 [remrangebylex - \[cool]
+ assert_equal {down elephant foo great hill omega} [r zrange zset 0 -1]
+ assert_equal 3 [remrangebylex \[bar \[down]
+ assert_equal {alpha elephant foo great hill omega} [r zrange zset 0 -1]
+ assert_equal 3 [remrangebylex \[g +]
+ assert_equal {alpha bar cool down elephant foo} [r zrange zset 0 -1]
+ assert_equal 6 [r zcard zset]
+
+ # exclusive range
+ assert_equal 2 [remrangebylex - (cool]
+ assert_equal {cool down elephant foo great hill omega} [r zrange zset 0 -1]
+ assert_equal 1 [remrangebylex (bar (down]
+ assert_equal {alpha bar down elephant foo great hill omega} [r zrange zset 0 -1]
+ assert_equal 2 [remrangebylex (great +]
+ assert_equal {alpha bar cool down elephant foo great} [r zrange zset 0 -1]
+ assert_equal 7 [r zcard zset]
+
+ # inclusive and exclusive
+ assert_equal 0 [remrangebylex (az (b]
+ assert_equal {alpha bar cool down elephant foo great hill omega} [r zrange zset 0 -1]
+ assert_equal 0 [remrangebylex (z +]
+ assert_equal {alpha bar cool down elephant foo great hill omega} [r zrange zset 0 -1]
+ assert_equal 0 [remrangebylex - \[aaaa]
+ assert_equal {alpha bar cool down elephant foo great hill omega} [r zrange zset 0 -1]
+ assert_equal 9 [r zcard zset]
+
+ # destroy when empty
+ assert_equal 9 [remrangebylex - +]
+ assert_equal 0 [r zcard zset]
+ assert_equal 0 [r exists zset]
+ }
+
test "ZUNIONSTORE against non-existing key doesn't set destination - $encoding" {
r del zseta{t}
assert_equal 0 [r zunionstore dst_key{t} 1 zseta{t}]
diff --git a/tests/unit/wait.tcl b/tests/unit/wait.tcl
index 08a7a71f6..8c6010afb 100644
--- a/tests/unit/wait.tcl
+++ b/tests/unit/wait.tcl
@@ -47,25 +47,25 @@ start_server {} {
}
test {WAIT should not acknowledge 1 additional copy if slave is blocked} {
- exec kill -SIGSTOP $slave_pid
+ pause_process $slave_pid
$master set foo 0
$master incr foo
$master incr foo
$master incr foo
assert {[$master wait 1 1000] == 0}
- exec kill -SIGCONT $slave_pid
+ resume_process $slave_pid
assert {[$master wait 1 1000] == 1}
}
test {WAIT implicitly blocks on client pause since ACKs aren't sent} {
- exec kill -SIGSTOP $slave_pid
+ pause_process $slave_pid
$master multi
$master incr foo
$master client pause 10000 write
$master exec
assert {[$master wait 1 1000] == 0}
$master client unpause
- exec kill -SIGCONT $slave_pid
+ resume_process $slave_pid
assert {[$master wait 1 1000] == 1}
}
@@ -73,7 +73,7 @@ start_server {} {
set rd [redis_deferring_client -1]
set rd2 [redis_deferring_client -1]
- exec kill -SIGSTOP $slave_pid
+ pause_process $slave_pid
$rd incr foo
$rd read
@@ -85,7 +85,7 @@ start_server {} {
$rd2 wait 1 0
wait_for_blocked_clients_count 2 100 10 -1
- exec kill -SIGCONT $slave_pid
+ resume_process $slave_pid
assert_equal [$rd read] {1}
assert_equal [$rd2 read] {1}
@@ -175,7 +175,49 @@ tags {"wait aof network external:skip"} {
$replica config set appendfsync everysec
test {WAITAOF replica copy everysec} {
+ $replica config set appendfsync everysec
+ waitForBgrewriteaof $replica ;# Make sure there is no AOFRW
+
+ $master incr foo
+ assert_equal [$master waitaof 0 1 0] {1 1}
+ }
+
+ test {WAITAOF replica copy everysec with AOFRW} {
+ $replica config set appendfsync everysec
+
+ # When we trigger an AOFRW, a fsync is triggered when closing the old INCR file,
+ # so with the everysec, we will skip that second of fsync, and in the next second
+ # after that, we will eventually do the fsync.
+ $replica bgrewriteaof
+ waitForBgrewriteaof $replica
+
+ $master incr foo
+ assert_equal [$master waitaof 0 1 0] {1 1}
+ }
+
+ test {WAITAOF replica copy everysec with slow AOFRW} {
+ $replica config set appendfsync everysec
+ $replica config set rdb-key-save-delay 1000000 ;# 1 sec
+
+ $replica bgrewriteaof
+
+ $master incr foo
+ assert_equal [$master waitaof 0 1 0] {1 1}
+
+ $replica config set rdb-key-save-delay 0
+ waitForBgrewriteaof $replica
+ }
+
+ test {WAITAOF replica copy everysec->always with AOFRW} {
+ $replica config set appendfsync everysec
+
+ # Try to fit all of them in the same round second, although there's no way to guarantee
+ # that, it can be done on fast machine. In any case, the test shouldn't fail either.
+ $replica bgrewriteaof
$master incr foo
+ waitForBgrewriteaof $replica
+ $replica config set appendfsync always
+
assert_equal [$master waitaof 0 1 0] {1 1}
}
@@ -187,10 +229,10 @@ tags {"wait aof network external:skip"} {
}
test {WAITAOF replica copy if replica is blocked} {
- exec kill -SIGSTOP $replica_pid
+ pause_process $replica_pid
$master incr foo
assert_equal [$master waitaof 0 1 50] {1 0} ;# exits on timeout
- exec kill -SIGCONT $replica_pid
+ resume_process $replica_pid
assert_equal [$master waitaof 0 1 0] {1 1}
}
@@ -198,7 +240,7 @@ tags {"wait aof network external:skip"} {
set rd [redis_deferring_client -1]
set rd2 [redis_deferring_client -1]
- exec kill -SIGSTOP $replica_pid
+ pause_process $replica_pid
$rd incr foo
$rd read
@@ -210,7 +252,7 @@ tags {"wait aof network external:skip"} {
$rd2 waitaof 0 1 0
wait_for_blocked_clients_count 2 100 10 -1
- exec kill -SIGCONT $replica_pid
+ resume_process $replica_pid
assert_equal [$rd read] {1 1}
assert_equal [$rd2 read] {1 1}
@@ -396,7 +438,7 @@ start_server {} {
waitForBgrewriteaof $replica1
waitForBgrewriteaof $replica2
- exec kill -SIGSTOP $replica1_pid
+ pause_process $replica1_pid
$rd incr foo
$rd read
@@ -409,7 +451,7 @@ start_server {} {
wait_for_blocked_clients_count 2
- exec kill -SIGCONT $replica1_pid
+ resume_process $replica1_pid
# WAIT will unblock the client first.
assert_equal [$rd2 read] {2}