summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2021-07-14 19:14:31 +0300
committerGitHub <noreply@github.com>2021-07-14 19:14:31 +0300
commit6a5bac309e868deef749c36949723b415de2496f (patch)
treeed1740c8c110c2e92704c48f7558deadf622cac2 /tests
parent277e4dc2032356c7712b539e89f7e9154e0a1a86 (diff)
downloadredis-6a5bac309e868deef749c36949723b415de2496f.tar.gz
Test infra, handle RESP3 attributes and big-numbers and bools (#9235)
- promote the code in DEBUG PROTOCOL to addReplyBigNum - DEBUG PROTOCOL ATTRIB skips the attribute when client is RESP2 - networking.c addReply for push and attributes generate assertion when called on a RESP2 client, anything else would produce a broken protocol that clients can't handle.
Diffstat (limited to 'tests')
-rw-r--r--tests/support/redis.tcl52
-rw-r--r--tests/unit/protocol.tcl54
2 files changed, 88 insertions, 18 deletions
diff --git a/tests/support/redis.tcl b/tests/support/redis.tcl
index 285b53574..978163e98 100644
--- a/tests/support/redis.tcl
+++ b/tests/support/redis.tcl
@@ -247,30 +247,46 @@ proc ::redis::redis_read_null fd {
return {}
}
+proc ::redis::redis_read_bool fd {
+ set v [redis_read_line $fd]
+ if {$v == "t"} {return 1}
+ if {$v == "f"} {return 0}
+ return -code error "Bad protocol, '$v' as bool type"
+}
+
proc ::redis::redis_read_reply {id fd} {
if {$::redis::readraw($id)} {
return [redis_read_line $fd]
}
- set type [read $fd 1]
- switch -exact -- $type {
- _ {redis_read_null $fd}
- : -
- + {redis_read_line $fd}
- , {expr {double([redis_read_line $fd])}}
- - {return -code error [redis_read_line $fd]}
- $ {redis_bulk_read $fd}
- > -
- ~ -
- * {redis_multi_bulk_read $id $fd}
- % {redis_read_map $id $fd}
- default {
- if {$type eq {}} {
- catch {close $fd}
- set ::redis::fd($id) {}
- return -code error "I/O error reading reply"
+ while {1} {
+ set type [read $fd 1]
+ switch -exact -- $type {
+ _ {return [redis_read_null $fd]}
+ : -
+ ( -
+ + {return [redis_read_line $fd]}
+ , {return [expr {double([redis_read_line $fd])}]}
+ # {return [redis_read_bool $fd]}
+ - {return -code error [redis_read_line $fd]}
+ $ {return [redis_bulk_read $fd]}
+ > -
+ ~ -
+ * {return [redis_multi_bulk_read $id $fd]}
+ % {return [redis_read_map $id $fd]}
+ | {
+ # ignore attributes for now (nowhere to store them)
+ redis_read_map $id $fd
+ continue
+ }
+ default {
+ if {$type eq {}} {
+ catch {close $fd}
+ set ::redis::fd($id) {}
+ return -code error "I/O error reading reply"
+ }
+ return -code error "Bad protocol, '$type' as reply type byte"
}
- return -code error "Bad protocol, '$type' as reply type byte"
}
}
}
diff --git a/tests/unit/protocol.tcl b/tests/unit/protocol.tcl
index ffc751f8f..ed0fe6482 100644
--- a/tests/unit/protocol.tcl
+++ b/tests/unit/protocol.tcl
@@ -136,6 +136,60 @@ start_server {tags {"protocol network"}} {
# check the connection still works
assert_equal [r ping] {PONG}
+
+ test {RESP3 attributes} {
+ r hello 3
+ set res [r debug protocol attrib]
+ # currently the parser in redis.tcl ignores the attributes
+
+ # restore state
+ r hello 2
+ set _ $res
+ } {Some real reply following the attribute} {resp3}
+
+ test {RESP3 attributes readraw} {
+ r hello 3
+ r readraw 1
+ r deferred 1
+
+ r debug protocol attrib
+ assert_equal [r read] {|1}
+ assert_equal [r read] {$14}
+ assert_equal [r read] {key-popularity}
+ assert_equal [r read] {*2}
+ assert_equal [r read] {$7}
+ assert_equal [r read] {key:123}
+ assert_equal [r read] {:90}
+ assert_equal [r read] {$39}
+ assert_equal [r read] {Some real reply following the attribute}
+
+ # restore state
+ r readraw 0
+ r deferred 0
+ r hello 2
+ set _ {}
+ } {} {resp3}
+
+ test {RESP3 attributes on RESP2} {
+ r hello 2
+ set res [r debug protocol attrib]
+ set _ $res
+ } {Some real reply following the attribute}
+
+ test "test big number parsing" {
+ r hello 3
+ r debug protocol bignum
+ } {1234567999999999999999999999999999999} {needs:debug resp3}
+
+ test "test bool parsing" {
+ r hello 3
+ assert_equal [r debug protocol true] 1
+ assert_equal [r debug protocol false] 0
+ r hello 2
+ assert_equal [r debug protocol true] 1
+ assert_equal [r debug protocol false] 0
+ set _ {}
+ } {} {needs:debug resp3}
}
start_server {tags {"regression"}} {