Unverified Commit 98b3f525 authored by Oran Agra's avatar Oran Agra Committed by GitHub
Browse files

add test suite infra to test RESP3 attributes (#10247)

So far we only tested attributes using readraw, not the
resp parser caches them, so that after getting the reply,
you can query them if you want.
parent 91cc2059
...@@ -35,6 +35,7 @@ array set ::redis::addr {} ...@@ -35,6 +35,7 @@ array set ::redis::addr {}
array set ::redis::blocking {} array set ::redis::blocking {}
array set ::redis::deferred {} array set ::redis::deferred {}
array set ::redis::readraw {} array set ::redis::readraw {}
array set ::redis::attributes {} ;# Holds the RESP3 attributes from the last call
array set ::redis::reconnect {} array set ::redis::reconnect {}
array set ::redis::tls {} array set ::redis::tls {}
array set ::redis::callback {} array set ::redis::callback {}
...@@ -105,6 +106,7 @@ proc ::redis::__dispatch__raw__ {id method argv} { ...@@ -105,6 +106,7 @@ proc ::redis::__dispatch__raw__ {id method argv} {
set argv [lrange $argv 0 end-1] set argv [lrange $argv 0 end-1]
} }
if {[info command ::redis::__method__$method] eq {}} { if {[info command ::redis::__method__$method] eq {}} {
catch {unset ::redis::attributes($id)}
set cmd "*[expr {[llength $argv]+1}]\r\n" set cmd "*[expr {[llength $argv]+1}]\r\n"
append cmd "$[string length $method]\r\n$method\r\n" append cmd "$[string length $method]\r\n$method\r\n"
foreach a $argv { foreach a $argv {
...@@ -165,6 +167,7 @@ proc ::redis::__method__close {id fd} { ...@@ -165,6 +167,7 @@ proc ::redis::__method__close {id fd} {
catch {unset ::redis::blocking($id)} catch {unset ::redis::blocking($id)}
catch {unset ::redis::deferred($id)} catch {unset ::redis::deferred($id)}
catch {unset ::redis::readraw($id)} catch {unset ::redis::readraw($id)}
catch {unset ::redis::attributes($id)}
catch {unset ::redis::reconnect($id)} catch {unset ::redis::reconnect($id)}
catch {unset ::redis::tls($id)} catch {unset ::redis::tls($id)}
catch {unset ::redis::state($id)} catch {unset ::redis::state($id)}
...@@ -185,6 +188,10 @@ proc ::redis::__method__readraw {id fd val} { ...@@ -185,6 +188,10 @@ proc ::redis::__method__readraw {id fd val} {
set ::redis::readraw($id) $val set ::redis::readraw($id) $val
} }
proc ::redis::__method__attributes {id fd} {
set _ $::redis::attributes($id)
}
proc ::redis::redis_write {fd buf} { proc ::redis::redis_write {fd buf} {
puts -nonewline $fd $buf puts -nonewline $fd $buf
} }
...@@ -286,8 +293,8 @@ proc ::redis::redis_read_reply {id fd} { ...@@ -286,8 +293,8 @@ proc ::redis::redis_read_reply {id fd} {
* {return [redis_multi_bulk_read $id $fd]} * {return [redis_multi_bulk_read $id $fd]}
% {return [redis_read_map $id $fd]} % {return [redis_read_map $id $fd]}
| { | {
# ignore attributes for now (nowhere to store them) set attrib [redis_read_map $id $fd]
redis_read_map $id $fd set ::redis::attributes($id) $attrib
continue continue
} }
default { default {
......
...@@ -139,13 +139,17 @@ start_server {tags {"protocol network"}} { ...@@ -139,13 +139,17 @@ start_server {tags {"protocol network"}} {
test {RESP3 attributes} { test {RESP3 attributes} {
r hello 3 r hello 3
set res [r debug protocol attrib] assert_equal {Some real reply following the attribute} [r debug protocol attrib]
# currently the parser in redis.tcl ignores the attributes assert_equal {key-popularity {key:123 90}} [r attributes]
# make sure attributes are not kept from previous command
r ping
assert_error {*attributes* no such element in array} {r attributes}
# restore state # restore state
r hello 2 r hello 2
set _ $res set _ ""
} {Some real reply following the attribute} {needs:debug resp3} } {} {needs:debug resp3}
test {RESP3 attributes readraw} { test {RESP3 attributes readraw} {
r hello 3 r hello 3
......
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