summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorguybe7 <guy.benoish@redislabs.com>2023-03-11 09:14:16 +0100
committerGitHub <noreply@github.com>2023-03-11 10:14:16 +0200
commit4ba47d2d2163ea77aacc9f719db91af2d7298905 (patch)
tree1290c23d28b91fbd237506faf31878918826a40c /tests/unit
parentc46d68d6d273e7c86fd1f1d10caca4e47a3294f8 (diff)
downloadredis-4ba47d2d2163ea77aacc9f719db91af2d7298905.tar.gz
Add reply_schema to command json files (internal for now) (#10273)
Work in progress towards implementing a reply schema as part of COMMAND DOCS, see #9845 Since ironing the details of the reply schema of each and every command can take a long time, we would like to merge this PR when the infrastructure is ready, and let this mature in the unstable branch. Meanwhile the changes of this PR are internal, they are part of the repo, but do not affect the produced build. ### Background In #9656 we add a lot of information about Redis commands, but we are missing information about the replies ### Motivation 1. Documentation. This is the primary goal. 2. It should be possible, based on the output of COMMAND, to be able to generate client code in typed languages. In order to do that, we need Redis to tell us, in detail, what each reply looks like. 3. We would like to build a fuzzer that verifies the reply structure (for now we use the existing testsuite, see the "Testing" section) ### Schema The idea is to supply some sort of schema for the various replies of each command. The schema will describe the conceptual structure of the reply (for generated clients), as defined in RESP3. Note that the reply structure itself may change, depending on the arguments (e.g. `XINFO STREAM`, with and without the `FULL` modifier) We decided to use the standard json-schema (see https://json-schema.org/) as the reply-schema. Example for `BZPOPMIN`: ``` "reply_schema": { "oneOf": [ { "description": "Timeout reached and no elements were popped.", "type": "null" }, { "description": "The keyname, popped member, and its score.", "type": "array", "minItems": 3, "maxItems": 3, "items": [ { "description": "Keyname", "type": "string" }, { "description": "Member", "type": "string" }, { "description": "Score", "type": "number" } ] } ] } ``` #### Notes 1. It is ok that some commands' reply structure depends on the arguments and it's the caller's responsibility to know which is the relevant one. this comes after looking at other request-reply systems like OpenAPI, where the reply schema can also be oneOf and the caller is responsible to know which schema is the relevant one. 2. The reply schemas will describe RESP3 replies only. even though RESP3 is structured, we want to use reply schema for documentation (and possibly to create a fuzzer that validates the replies) 3. For documentation, the description field will include an explanation of the scenario in which the reply is sent, including any relation to arguments. for example, for `ZRANGE`'s two schemas we will need to state that one is with `WITHSCORES` and the other is without. 4. For documentation, there will be another optional field "notes" in which we will add a short description of the representation in RESP2, in case it's not trivial (RESP3's `ZRANGE`'s nested array vs. RESP2's flat array, for example) Given the above: 1. We can generate the "return" section of all commands in [redis-doc](https://redis.io/commands/) (given that "description" and "notes" are comprehensive enough) 2. We can generate a client in a strongly typed language (but the return type could be a conceptual `union` and the caller needs to know which schema is relevant). see the section below for RESP2 support. 3. We can create a fuzzer for RESP3. ### Limitations (because we are using the standard json-schema) The problem is that Redis' replies are more diverse than what the json format allows. This means that, when we convert the reply to a json (in order to validate the schema against it), we lose information (see the "Testing" section below). The other option would have been to extend the standard json-schema (and json format) to include stuff like sets, bulk-strings, error-string, etc. but that would mean also extending the schema-validator - and that seemed like too much work, so we decided to compromise. Examples: 1. We cannot tell the difference between an "array" and a "set" 2. We cannot tell the difference between simple-string and bulk-string 3. we cannot verify true uniqueness of items in commands like ZRANGE: json-schema doesn't cover the case of two identical members with different scores (e.g. `[["m1",6],["m1",7]]`) because `uniqueItems` compares (member,score) tuples and not just the member name. ### Testing This commit includes some changes inside Redis in order to verify the schemas (existing and future ones) are indeed correct (i.e. describe the actual response of Redis). To do that, we added a debugging feature to Redis that causes it to produce a log of all the commands it executed and their replies. For that, Redis needs to be compiled with `-DLOG_REQ_RES` and run with `--reg-res-logfile <file> --client-default-resp 3` (the testsuite already does that if you run it with `--log-req-res --force-resp3`) You should run the testsuite with the above args (and `--dont-clean`) in order to make Redis generate `.reqres` files (same dir as the `stdout` files) which contain request-response pairs. These files are later on processed by `./utils/req-res-log-validator.py` which does: 1. Goes over req-res files, generated by redis-servers, spawned by the testsuite (see logreqres.c) 2. For each request-response pair, it validates the response against the request's reply_schema (obtained from the extended COMMAND DOCS) 5. In order to get good coverage of the Redis commands, and all their different replies, we chose to use the existing redis test suite, rather than attempt to write a fuzzer. #### Notes about RESP2 1. We will not be able to use the testing tool to verify RESP2 replies (we are ok with that, it's time to accept RESP3 as the future RESP) 2. Since the majority of the test suite is using RESP2, and we want the server to reply with RESP3 so that we can validate it, we will need to know how to convert the actual reply to the one expected. - number and boolean are always strings in RESP2 so the conversion is easy - objects (maps) are always a flat array in RESP2 - others (nested array in RESP3's `ZRANGE` and others) will need some special per-command handling (so the client will not be totally auto-generated) Example for ZRANGE: ``` "reply_schema": { "anyOf": [ { "description": "A list of member elements", "type": "array", "uniqueItems": true, "items": { "type": "string" } }, { "description": "Members and their scores. Returned in case `WITHSCORES` was used.", "notes": "In RESP2 this is returned as a flat array", "type": "array", "uniqueItems": true, "items": { "type": "array", "minItems": 2, "maxItems": 2, "items": [ { "description": "Member", "type": "string" }, { "description": "Score", "type": "number" } ] } } ] } ``` ### Other changes 1. Some tests that behave differently depending on the RESP are now being tested for both RESP, regardless of the special log-req-res mode ("Pub/Sub PING" for example) 2. Update the history field of CLIENT LIST 3. Added basic tests for commands that were not covered at all by the testsuite ### TODO - [x] (maybe a different PR) add a "condition" field to anyOf/oneOf schemas that refers to args. e.g. when `SET` return NULL, the condition is `arguments.get||arguments.condition`, for `OK` the condition is `!arguments.get`, and for `string` the condition is `arguments.get` - https://github.com/redis/redis/issues/11896 - [x] (maybe a different PR) also run `runtest-cluster` in the req-res logging mode - [x] add the new tests to GH actions (i.e. compile with `-DLOG_REQ_RES`, run the tests, and run the validator) - [x] (maybe a different PR) figure out a way to warn about (sub)schemas that are uncovered by the output of the tests - https://github.com/redis/redis/issues/11897 - [x] (probably a separate PR) add all missing schemas - [x] check why "SDOWN is triggered by misconfigured instance replying with errors" fails with --log-req-res - [x] move the response transformers to their own file (run both regular, cluster, and sentinel tests - need to fight with the tcl including mechanism a bit) - [x] issue: module API - https://github.com/redis/redis/issues/11898 - [x] (probably a separate PR): improve schemas: add `required` to `object`s - https://github.com/redis/redis/issues/11899 Co-authored-by: Ozan Tezcan <ozantezcan@gmail.com> Co-authored-by: Hanna Fadida <hanna.fadida@redislabs.com> Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: Shaya Potter <shaya@redislabs.com>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/acl.tcl4
-rw-r--r--tests/unit/aofrw.tcl4
-rw-r--r--tests/unit/client-eviction.tcl2
-rw-r--r--tests/unit/cluster/misc.tcl11
-rw-r--r--tests/unit/geo.tcl14
-rw-r--r--tests/unit/introspection.tcl41
-rw-r--r--tests/unit/moduleapi/basics.tcl17
-rw-r--r--tests/unit/moduleapi/blockedclient.tcl6
-rw-r--r--tests/unit/moduleapi/cmdintrospection.tcl3
-rw-r--r--tests/unit/moduleapi/reply.tcl7
-rw-r--r--tests/unit/networking.tcl9
-rw-r--r--tests/unit/obuf-limits.tcl2
-rw-r--r--tests/unit/other.tcl24
-rw-r--r--tests/unit/protocol.tcl9
-rw-r--r--tests/unit/pubsub.tcl46
-rw-r--r--tests/unit/scripting.tcl12
-rw-r--r--tests/unit/tracking.tcl28
-rw-r--r--tests/unit/type/incr.tcl4
-rw-r--r--tests/unit/type/list.tcl6
-rw-r--r--tests/unit/type/string.tcl7
-rw-r--r--tests/unit/type/zset.tcl26
21 files changed, 239 insertions, 43 deletions
diff --git a/tests/unit/acl.tcl b/tests/unit/acl.tcl
index 59626caaf..13eea86de 100644
--- a/tests/unit/acl.tcl
+++ b/tests/unit/acl.tcl
@@ -7,6 +7,10 @@ start_server {tags {"acl external:skip"}} {
r ACL setuser newuser
}
+ test {Coverage: ACL USERS} {
+ r ACL USERS
+ } {default newuser}
+
test {Usernames can not contain spaces or null characters} {
catch {r ACL setuser "a a"} err
set err
diff --git a/tests/unit/aofrw.tcl b/tests/unit/aofrw.tcl
index 00fc9e3bd..fe07351a3 100644
--- a/tests/unit/aofrw.tcl
+++ b/tests/unit/aofrw.tcl
@@ -1,4 +1,6 @@
-start_server {tags {"aofrw external:skip"}} {
+# 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"}} {
# 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 db6a22499..76f7bf0f2 100644
--- a/tests/unit/client-eviction.tcl
+++ b/tests/unit/client-eviction.tcl
@@ -1,4 +1,4 @@
-tags {"external:skip"} {
+tags {"external:skip logreqres:skip"} {
# Get info about a redis client connection:
# name - name of client we want to query
diff --git a/tests/unit/cluster/misc.tcl b/tests/unit/cluster/misc.tcl
index 35308b81a..3ff21010a 100644
--- a/tests/unit/cluster/misc.tcl
+++ b/tests/unit/cluster/misc.tcl
@@ -12,5 +12,16 @@ start_cluster 2 2 {tags {external:skip cluster}} {
assert_error {ASK*} {R 0 GET FOO}
R 0 ping
} {PONG}
+
+ test "Coverage: Basic cluster commands" {
+ assert_equal {OK} [R 0 CLUSTER saveconfig]
+
+ set id [R 0 CLUSTER MYID]
+ assert_equal {0} [R 0 CLUSTER count-failure-reports $id]
+ assert_match "*shard-id*" [R 0 CLUSTER slaves $id]
+
+ R 0 flushall
+ assert_equal {OK} [R 0 CLUSTER flushslots]
+ }
}
diff --git a/tests/unit/geo.tcl b/tests/unit/geo.tcl
index e07a6784c..85c9485e4 100644
--- a/tests/unit/geo.tcl
+++ b/tests/unit/geo.tcl
@@ -222,6 +222,10 @@ start_server {tags {"geo"}} {
r georadius nyc -73.9798091 40.7598464 3 km asc
} {{central park n/q/r} 4545 {union square}}
+ test {GEORADIUS_RO simple (sorted)} {
+ r georadius_ro nyc -73.9798091 40.7598464 3 km asc
+ } {{central park n/q/r} 4545 {union square}}
+
test {GEOSEARCH simple (sorted)} {
r geosearch nyc fromlonlat -73.9798091 40.7598464 bybox 6 6 km asc
} {{central park n/q/r} 4545 {union square} {lic market}}
@@ -263,6 +267,12 @@ start_server {tags {"geo"}} {
r georadius nyc -73.9798091 40.7598464 10 km COUNT 3
} {{central park n/q/r} 4545 {union square}}
+ test {GEORADIUS with multiple WITH* tokens} {
+ assert_match {{{central park n/q/r} 1791875761332224 {-73.97334* 40.76480*}} {4545 1791875796750882 {-73.95641* 40.74809*}}} [r georadius nyc -73.9798091 40.7598464 10 km WITHCOORD WITHHASH COUNT 2]
+ assert_match {{{central park n/q/r} 1791875761332224 {-73.97334* 40.76480*}} {4545 1791875796750882 {-73.95641* 40.74809*}}} [r georadius nyc -73.9798091 40.7598464 10 km WITHHASH WITHCOORD COUNT 2]
+ assert_match {{{central park n/q/r} 0.7750 1791875761332224 {-73.97334* 40.76480*}} {4545 2.3651 1791875796750882 {-73.95641* 40.74809*}}} [r georadius nyc -73.9798091 40.7598464 10 km WITHDIST WITHHASH WITHCOORD COUNT 2]
+ }
+
test {GEORADIUS with ANY not sorted by default} {
r georadius nyc -73.9798091 40.7598464 10 km COUNT 3 ANY
} {{wtc one} {union square} {central park n/q/r}}
@@ -293,6 +303,10 @@ start_server {tags {"geo"}} {
test {GEORADIUSBYMEMBER simple (sorted)} {
r georadiusbymember nyc "wtc one" 7 km
} {{wtc one} {union square} {central park n/q/r} 4545 {lic market}}
+
+ test {GEORADIUSBYMEMBER_RO simple (sorted)} {
+ r georadiusbymember_ro nyc "wtc one" 7 km
+ } {{wtc one} {union square} {central park n/q/r} 4545 {lic market}}
test {GEORADIUSBYMEMBER search areas contain satisfied points in oblique direction} {
r del k1
diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl
index 4617334e7..097074047 100644
--- a/tests/unit/introspection.tcl
+++ b/tests/unit/introspection.tcl
@@ -7,7 +7,7 @@ start_server {tags {"introspection"}} {
test {CLIENT LIST} {
r client list
- } {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N db=* sub=0 psub=0 ssub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|list user=* redir=-1 resp=2*}
+ } {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N db=* sub=0 psub=0 ssub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|list user=* redir=-1 resp=*}
test {CLIENT LIST with IDs} {
set myid [r client id]
@@ -17,7 +17,7 @@ start_server {tags {"introspection"}} {
test {CLIENT INFO} {
r client info
- } {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N db=* sub=0 psub=0 ssub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|info user=* redir=-1 resp=2*}
+ } {id=* addr=*:* laddr=*:* fd=* name=* age=* idle=* flags=N db=* sub=0 psub=0 ssub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* multi-mem=0 rbs=* rbp=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client|info user=* redir=-1 resp=*}
test {CLIENT KILL with illegal arguments} {
assert_error "ERR wrong number of arguments for 'client|kill' command" {r client kill}
@@ -138,14 +138,22 @@ start_server {tags {"introspection"}} {
r migrate [srv 0 host] [srv 0 port] key 9 5000 AUTH2 user password
catch {r auth not-real} _
catch {r auth not-real not-a-password} _
- catch {r hello 2 AUTH not-real not-a-password} _
-
+
assert_match {*"key"*"9"*"5000"*} [$rd read]
assert_match {*"key"*"9"*"5000"*"(redacted)"*} [$rd read]
assert_match {*"key"*"9"*"5000"*"(redacted)"*"(redacted)"*} [$rd read]
assert_match {*"auth"*"(redacted)"*} [$rd read]
assert_match {*"auth"*"(redacted)"*"(redacted)"*} [$rd read]
- assert_match {*"hello"*"2"*"AUTH"*"(redacted)"*"(redacted)"*} [$rd read]
+
+ foreach resp {3 2} {
+ if {[lsearch $::denytags "resp3"] >= 0} {
+ if {$resp == 3} {continue}
+ } elseif {$::force_resp3} {
+ if {$resp == 2} {continue}
+ }
+ catch {r hello $resp AUTH not-real not-a-password} _
+ assert_match "*\"hello\"*\"$resp\"*\"AUTH\"*\"(redacted)\"*\"(redacted)\"*" [$rd read]
+ }
$rd close
} {0} {needs:repl}
@@ -225,6 +233,27 @@ start_server {tags {"introspection"}} {
r client list
} {*name= *}
+ test {Coverage: Basic CLIENT CACHING} {
+ set rd_redirection [redis_deferring_client]
+ $rd_redirection client id
+ set redir_id [$rd_redirection read]
+ r CLIENT TRACKING on OPTIN REDIRECT $redir_id
+ r CLIENT CACHING yes
+ r CLIENT TRACKING off
+ } {OK}
+
+ test {Coverage: Basic CLIENT REPLY} {
+ r CLIENT REPLY on
+ } {OK}
+
+ test {Coverage: Basic CLIENT TRACKINGINFO} {
+ r CLIENT TRACKINGINFO
+ } {flags off redirect -1 prefixes {}}
+
+ test {Coverage: Basic CLIENT GETREDIR} {
+ r CLIENT GETREDIR
+ } {-1}
+
test {CLIENT SETNAME does not accept spaces} {
catch {r client setname "foo bar"} e
set e
@@ -325,6 +354,8 @@ start_server {tags {"introspection"}} {
logfile
dir
socket-mark-id
+ req-res-logfile
+ client-default-resp
}
if {!$::tls} {
diff --git a/tests/unit/moduleapi/basics.tcl b/tests/unit/moduleapi/basics.tcl
index be606ced0..042e3474a 100644
--- a/tests/unit/moduleapi/basics.tcl
+++ b/tests/unit/moduleapi/basics.tcl
@@ -21,12 +21,17 @@ start_server {tags {"modules"}} {
}
test {test get resp} {
- r hello 2
- set reply [r test.getresp]
- assert_equal $reply 2
- r hello 3
- set reply [r test.getresp]
- assert_equal $reply 3
+ foreach resp {3 2} {
+ if {[lsearch $::denytags "resp3"] >= 0} {
+ if {$resp == 3} {continue}
+ } elseif {$::force_resp3} {
+ if {$resp == 2} {continue}
+ }
+ r hello $resp
+ set reply [r test.getresp]
+ assert_equal $reply $resp
+ r hello 2
+ }
}
test "Unload the module - test" {
diff --git a/tests/unit/moduleapi/blockedclient.tcl b/tests/unit/moduleapi/blockedclient.tcl
index 2cb44788e..f0faea5c3 100644
--- a/tests/unit/moduleapi/blockedclient.tcl
+++ b/tests/unit/moduleapi/blockedclient.tcl
@@ -91,6 +91,11 @@ start_server {tags {"modules"}} {
test {RESP version carries through to blocked client} {
for {set client_proto 2} {$client_proto <= 3} {incr client_proto} {
+ if {[lsearch $::denytags "resp3"] >= 0} {
+ if {$client_proto == 3} {continue}
+ } elseif {$::force_resp3} {
+ if {$client_proto == 2} {continue}
+ }
r hello $client_proto
r readraw 1
set ret [r do_fake_bg_true]
@@ -100,6 +105,7 @@ start_server {tags {"modules"}} {
assert_equal $ret "#t"
}
r readraw 0
+ r hello 2
}
}
diff --git a/tests/unit/moduleapi/cmdintrospection.tcl b/tests/unit/moduleapi/cmdintrospection.tcl
index 4d67af1e1..6ba69a1ed 100644
--- a/tests/unit/moduleapi/cmdintrospection.tcl
+++ b/tests/unit/moduleapi/cmdintrospection.tcl
@@ -37,6 +37,9 @@ start_server {tags {"modules"}} {
dict unset redis_reply group
dict unset module_reply group
dict unset module_reply module
+ if {$::log_req_res} {
+ dict unset redis_reply reply_schema
+ }
assert_equal $redis_reply $module_reply
}
diff --git a/tests/unit/moduleapi/reply.tcl b/tests/unit/moduleapi/reply.tcl
index 356d1a0ed..291253d3c 100644
--- a/tests/unit/moduleapi/reply.tcl
+++ b/tests/unit/moduleapi/reply.tcl
@@ -5,6 +5,11 @@ start_server {tags {"modules"}} {
# test all with hello 2/3
for {set proto 2} {$proto <= 3} {incr proto} {
+ if {[lsearch $::denytags "resp3"] >= 0} {
+ if {$proto == 3} {continue}
+ } elseif {$::force_resp3} {
+ if {$proto == 2} {continue}
+ }
r hello $proto
test "RESP$proto: RM_ReplyWithString: an string reply" {
@@ -120,6 +125,8 @@ start_server {tags {"modules"}} {
catch {r rw.error} e
assert_match "An error" $e
}
+
+ r hello 2
}
test "Unload the module - replywith" {
diff --git a/tests/unit/networking.tcl b/tests/unit/networking.tcl
index 559a88e74..79d6e399d 100644
--- a/tests/unit/networking.tcl
+++ b/tests/unit/networking.tcl
@@ -121,7 +121,14 @@ start_server {config "minimal.conf" tags {"external:skip"}} {
# Make sure bind parameter is as expected and server handles binding
# accordingly.
- assert_equal {bind {}} [rediscli_exec 0 config get bind]
+ # (it seems that rediscli_exec behaves differently in RESP3, possibly
+ # because CONFIG GET returns a dict instead of a list so redis-cli emits
+ # it in a single line)
+ if {$::force_resp3} {
+ assert_equal {{bind }} [rediscli_exec 0 config get bind]
+ } else {
+ assert_equal {bind {}} [rediscli_exec 0 config get bind]
+ }
catch {reconnect 0} err
assert_match {*connection refused*} $err
diff --git a/tests/unit/obuf-limits.tcl b/tests/unit/obuf-limits.tcl
index 7eb6def58..45efc26b4 100644
--- a/tests/unit/obuf-limits.tcl
+++ b/tests/unit/obuf-limits.tcl
@@ -1,4 +1,4 @@
-start_server {tags {"obuf-limits external:skip"}} {
+start_server {tags {"obuf-limits external:skip logreqres:skip"}} {
test {CONFIG SET client-output-buffer-limit} {
set oldval [lindex [r config get client-output-buffer-limit] 1]
diff --git a/tests/unit/other.tcl b/tests/unit/other.tcl
index 2ae09b5b7..41e550890 100644
--- a/tests/unit/other.tcl
+++ b/tests/unit/other.tcl
@@ -6,6 +6,30 @@ start_server {tags {"other"}} {
} {ok}
}
+ test {Coverage: HELP commands} {
+ assert_match "*OBJECT <subcommand> *" [r OBJECT HELP]
+ assert_match "*MEMORY <subcommand> *" [r MEMORY HELP]
+ assert_match "*PUBSUB <subcommand> *" [r PUBSUB HELP]
+ assert_match "*SLOWLOG <subcommand> *" [r SLOWLOG HELP]
+ assert_match "*CLIENT <subcommand> *" [r CLIENT HELP]
+ assert_match "*COMMAND <subcommand> *" [r COMMAND HELP]
+ assert_match "*CONFIG <subcommand> *" [r CONFIG HELP]
+ assert_match "*FUNCTION <subcommand> *" [r FUNCTION HELP]
+ assert_match "*MODULE <subcommand> *" [r MODULE HELP]
+ }
+
+ test {Coverage: MEMORY MALLOC-STATS} {
+ if {[string match {*jemalloc*} [s mem_allocator]]} {
+ assert_match "*jemalloc*" [r memory malloc-stats]
+ }
+ }
+
+ test {Coverage: MEMORY PURGE} {
+ if {[string match {*jemalloc*} [s mem_allocator]]} {
+ assert_equal {OK} [r memory purge]
+ }
+ }
+
test {SAVE - make sure there are all the types as values} {
# Wait for a background saving in progress to terminate
waitForBgsave r
diff --git a/tests/unit/protocol.tcl b/tests/unit/protocol.tcl
index 50305bd27..e3b4115a8 100644
--- a/tests/unit/protocol.tcl
+++ b/tests/unit/protocol.tcl
@@ -110,16 +110,21 @@ start_server {tags {"protocol network"}} {
# raw RESP response tests
r readraw 1
+ set nullres {*-1}
+ if {$::force_resp3} {
+ set nullres {_}
+ }
+
test "raw protocol response" {
r srandmember nonexisting_key
- } {*-1}
+ } "$nullres"
r deferred 1
test "raw protocol response - deferred" {
r srandmember nonexisting_key
r read
- } {*-1}
+ } "$nullres"
test "raw protocol response - multiline" {
r sadd ss a
diff --git a/tests/unit/pubsub.tcl b/tests/unit/pubsub.tcl
index ea8964cf3..fe486edf3 100644
--- a/tests/unit/pubsub.tcl
+++ b/tests/unit/pubsub.tcl
@@ -5,21 +5,41 @@ start_server {tags {"pubsub network"}} {
set db 9
}
- test "Pub/Sub PING" {
+ foreach resp {2 3} {
set rd1 [redis_deferring_client]
- subscribe $rd1 somechannel
- # While subscribed to non-zero channels PING works in Pub/Sub mode.
- $rd1 ping
- $rd1 ping "foo"
- set reply1 [$rd1 read]
- set reply2 [$rd1 read]
- unsubscribe $rd1 somechannel
- # Now we are unsubscribed, PING should just return PONG.
- $rd1 ping
- set reply3 [$rd1 read]
+ if {[lsearch $::denytags "resp3"] >= 0} {
+ if {$resp == 3} {continue}
+ } elseif {$::force_resp3} {
+ if {$resp == 2} {continue}
+ }
+
+ $rd1 hello $resp
+ $rd1 read
+
+ test "Pub/Sub PING on RESP$resp" {
+ subscribe $rd1 somechannel
+ # While subscribed to non-zero channels PING works in Pub/Sub mode.
+ $rd1 ping
+ $rd1 ping "foo"
+ # In RESP3, the SUBSCRIBEd client can issue any command and get a reply, so the PINGs are standard
+ # In RESP2, only a handful of commands are allowed after a client is SUBSCRIBED (PING is one of them).
+ # For some reason, the reply in that case is an array with two elements: "pong" and argv[1] or an empty string
+ # God knows why. Done in commit 2264b981
+ if {$resp == 3} {
+ assert_equal {PONG} [$rd1 read]
+ assert_equal {foo} [$rd1 read]
+ } else {
+ assert_equal {pong {}} [$rd1 read]
+ assert_equal {pong foo} [$rd1 read]
+ }
+ unsubscribe $rd1 somechannel
+ # Now we are unsubscribed, PING should just return PONG.
+ $rd1 ping
+ assert_equal {PONG} [$rd1 read]
+
+ }
$rd1 close
- list $reply1 $reply2 $reply3
- } {{pong {}} {pong foo} PONG}
+ }
test "PUBLISH/SUBSCRIBE basics" {
set rd1 [redis_deferring_client]
diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl
index e3b1a620b..02459354a 100644
--- a/tests/unit/scripting.tcl
+++ b/tests/unit/scripting.tcl
@@ -119,6 +119,10 @@ start_server {tags {"scripting"}} {
r evalsha fd758d1589d044dd850a6f05d52f2eefd27f033f 1 mykey
} {myval}
+ test {EVALSHA_RO - Can we call a SHA1 if already defined?} {
+ r evalsha_ro fd758d1589d044dd850a6f05d52f2eefd27f033f 1 mykey
+ } {myval}
+
test {EVALSHA - Can we call a SHA1 in uppercase?} {
r evalsha FD758D1589D044DD850A6F05D52F2EEFD27F033F 1 mykey
} {myval}
@@ -703,6 +707,7 @@ start_server {tags {"scripting"}} {
assert_equal $res $expected_list
} {} {resp3}
+ if {!$::log_req_res} { # this test creates a huge nested array which python can't handle (RecursionError: maximum recursion depth exceeded in comparison)
test {Script return recursive object} {
r readraw 1
set res [run_script {local a = {}; local b = {a}; a[1] = b; return a} 0]
@@ -718,6 +723,7 @@ start_server {tags {"scripting"}} {
# make sure the connection is still valid
assert_equal [r ping] {PONG}
}
+ }
test {Script check unpack with massive arguments} {
run_script {
@@ -1257,9 +1263,10 @@ start_server {tags {"scripting needs:debug"}} {
for {set client_proto 2} {$client_proto <= 3} {incr client_proto} {
if {[lsearch $::denytags "resp3"] >= 0} {
if {$client_proto == 3} {continue}
- } else {
- r hello $client_proto
+ } elseif {$::force_resp3} {
+ if {$client_proto == 2} {continue}
}
+ r hello $client_proto
set extra "RESP$i/$client_proto"
r readraw 1
@@ -1367,6 +1374,7 @@ start_server {tags {"scripting needs:debug"}} {
}
r readraw 0
+ r hello 2
}
}
diff --git a/tests/unit/tracking.tcl b/tests/unit/tracking.tcl
index 13ca8f278..21036352f 100644
--- a/tests/unit/tracking.tcl
+++ b/tests/unit/tracking.tcl
@@ -1,4 +1,5 @@
-start_server {tags {"tracking network"}} {
+# logreqres:skip because it seems many of these tests rely heavily on RESP2
+start_server {tags {"tracking network logreqres:skip"}} {
# Create a deferred client we'll use to redirect invalidation
# messages to.
set rd_redirection [redis_deferring_client]
@@ -783,3 +784,28 @@ start_server {tags {"tracking network"}} {
$rd_redirection close
$rd close
}
+
+# Just some extra covergae for --log-req-res, because we do not
+# run the full tracking unit in that mode
+start_server {tags {"tracking network"}} {
+ test {Coverage: Basic CLIENT CACHING} {
+ set rd_redirection [redis_deferring_client]
+ $rd_redirection client id
+ set redir_id [$rd_redirection read]
+ assert_equal {OK} [r CLIENT TRACKING on OPTIN REDIRECT $redir_id]
+ assert_equal {OK} [r CLIENT CACHING yes]
+ r CLIENT TRACKING off
+ } {OK}
+
+ test {Coverage: Basic CLIENT REPLY} {
+ r CLIENT REPLY on
+ } {OK}
+
+ test {Coverage: Basic CLIENT TRACKINGINFO} {
+ r CLIENT TRACKINGINFO
+ } {flags off redirect -1 prefixes {}}
+
+ test {Coverage: Basic CLIENT GETREDIR} {
+ r CLIENT GETREDIR
+ } {-1}
+}
diff --git a/tests/unit/type/incr.tcl b/tests/unit/type/incr.tcl
index 7732921d9..a64f357ae 100644
--- a/tests/unit/type/incr.tcl
+++ b/tests/unit/type/incr.tcl
@@ -9,6 +9,10 @@ start_server {tags {"incr"}} {
r incr novar
} {2}
+ test {DECR against key created by incr} {
+ r decr novar
+ } {1}
+
test {INCR against key originally set with SET} {
r set novar 100
r incr novar
diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl
index dee8482bf..dad5e595a 100644
--- a/tests/unit/type/list.tcl
+++ b/tests/unit/type/list.tcl
@@ -558,9 +558,10 @@ foreach {type large} [array get largevalue] {
foreach resp {3 2} {
if {[lsearch $::denytags "resp3"] >= 0} {
if {$resp == 3} {continue}
- } else {
- r hello $resp
+ } elseif {$::force_resp3} {
+ if {$resp == 2} {continue}
}
+ r hello $resp
# Make sure we can distinguish between an empty array and a null response
r readraw 1
@@ -589,6 +590,7 @@ foreach {type large} [array get largevalue] {
}
r readraw 0
+ r hello 2
}
test {Variadic RPUSH/LPUSH} {
diff --git a/tests/unit/type/string.tcl b/tests/unit/type/string.tcl
index 3734d1f50..a9fa894dc 100644
--- a/tests/unit/type/string.tcl
+++ b/tests/unit/type/string.tcl
@@ -459,6 +459,13 @@ start_server {tags {"string"}} {
assert_equal [string range $bin $_start $_end] [r getrange bin $start $end]
}
}
+
+ test "Coverage: SUBSTR" {
+ r set key abcde
+ assert_equal "a" [r substr key 0 0]
+ assert_equal "abcd" [r substr key 0 3]
+ assert_equal "bcde" [r substr key -4 -1]
+ }
if {[string match {*jemalloc*} [s mem_allocator]]} {
test {trim on SET with big value} {
diff --git a/tests/unit/type/zset.tcl b/tests/unit/type/zset.tcl
index 7a9721905..a52a77f24 100644
--- a/tests/unit/type/zset.tcl
+++ b/tests/unit/type/zset.tcl
@@ -431,6 +431,10 @@ start_server {tags {"zset"}} {
}
test "ZRANK/ZREVRANK basics - $encoding" {
+ set nullres {$-1}
+ if {$::force_resp3} {
+ set nullres {_}
+ }
r del zranktmp
r zadd zranktmp 10 x
r zadd zranktmp 20 y
@@ -442,11 +446,15 @@ start_server {tags {"zset"}} {
assert_equal 1 [r zrevrank zranktmp y]
assert_equal 0 [r zrevrank zranktmp z]
r readraw 1
- assert_equal {$-1} [r zrank zranktmp foo]
- assert_equal {$-1} [r zrevrank zranktmp foo]
+ assert_equal $nullres [r zrank zranktmp foo]
+ assert_equal $nullres [r zrevrank zranktmp foo]
r readraw 0
# withscores
+ set nullres {*-1}
+ if {$::force_resp3} {
+ set nullres {_}
+ }
assert_equal {0 10} [r zrank zranktmp x withscore]
assert_equal {1 20} [r zrank zranktmp y withscore]
assert_equal {2 30} [r zrank zranktmp z withscore]
@@ -454,8 +462,8 @@ start_server {tags {"zset"}} {
assert_equal {1 20} [r zrevrank zranktmp y withscore]
assert_equal {0 30} [r zrevrank zranktmp z withscore]
r readraw 1
- assert_equal {*-1} [r zrank zranktmp foo withscore]
- assert_equal {*-1} [r zrevrank zranktmp foo withscore]
+ assert_equal $nullres [r zrank zranktmp foo withscore]
+ assert_equal $nullres [r zrevrank zranktmp foo withscore]
r readraw 0
}
@@ -1243,11 +1251,12 @@ start_server {tags {"zset"}} {
if {[lsearch $::denytags "resp3"] >= 0} {
if {$resp == 3} {continue}
- } else {
- r hello $resp
- $rd hello $resp
- $rd read
+ } elseif {$::force_resp3} {
+ if {$resp == 2} {continue}
}
+ r hello $resp
+ $rd hello $resp
+ $rd read
test "ZPOPMIN/ZPOPMAX readraw in RESP$resp" {
r del zset{t}
@@ -1401,6 +1410,7 @@ start_server {tags {"zset"}} {
}
$rd close
+ r hello 2
}
test {ZINTERSTORE regression with two sets, intset+hashtable} {