From d7117c1ebcb177716e1891664719a09afdba6858 Mon Sep 17 00:00:00 2001 From: hwware Date: Thu, 12 Sep 2024 14:44:10 +0000 Subject: [PATCH] Update test case for subv2 version Signed-off-by: hwware --- tests/integration/valkey-cli.tcl | 36 +++++++++++++++++++++++------- tests/unit/cluster/pubsubshard.tcl | 3 --- tests/unit/pubsub.tcl | 16 ++----------- tests/unit/pubsubshard.tcl | 3 --- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/tests/integration/valkey-cli.tcl b/tests/integration/valkey-cli.tcl index 9052f8fa6a..d659fa4f95 100644 --- a/tests/integration/valkey-cli.tcl +++ b/tests/integration/valkey-cli.tcl @@ -194,6 +194,30 @@ start_server {tags {"cli"}} { assert_equal "bar" [r get key] } + test_interactive_cli "Subscribed mode -- deprecated" { + if {$::force_resp3} { + run_command $fd "hello 3" + } + + set reading "Reading messages... (press Ctrl-C to quit or any key to type command)\r" + set erase "\033\[K"; # Erases the "Reading messages..." line. + + # Subscribe to some channels. + set sub1 "1) \"subscribe\"\n2) \"ch1\"\n3) (integer) 1\n" + set sub2 "1) \"subscribe\"\n2) \"ch2\"\n3) (integer) 2\n" + set sub3 "1) \"subscribe\"\n2) \"ch3\"\n3) (integer) 3\n" + assert_equal $sub1$sub2$sub3$reading \ + [run_command $fd "subscribe ch1 ch2 ch3"] + + # Unsubscribe all. + set unsub1 "1) \"unsubscribe\"\n2) \"ch1\"\n3) (integer) 2\n" + set unsub2 "1) \"unsubscribe\"\n2) \"ch2\"\n3) (integer) 1\n" + set unsub3 "1) \"unsubscribe\"\n2) \"ch3\"\n3) (integer) 0\n" + assert_equal $erase$unsub1$unsub2$unsub3$reading \ + [run_command $fd "unsubscribe ch1 ch2 ch3"] + + } + test_interactive_cli "Subscribed mode" { if {$::force_resp3} { run_command $fd "hello 3" @@ -202,15 +226,15 @@ start_server {tags {"cli"}} { set reading "Reading messages... (press Ctrl-C to quit or any key to type command)\r" set erase "\033\[K"; # Erases the "Reading messages..." line. + run_command $fd "client capa subv2" + # Subscribe to some channels. set sub1 "1) \"subscribe\"\n2) \"ch1\"\n3) (integer) 1\n" - set sub2 "1) \"subscribe\"\n2) \"ch2\"\n3) (integer) 2\n" - set sub3 "1) \"subscribe\"\n2) \"ch3\"\n3) (integer) 3\n" + set sub2 "4) \"subscribe\"\n5) \"ch2\"\n6) (integer) 2\n" + set sub3 "7) \"subscribe\"\n8) \"ch3\"\n9) (integer) 3\n" assert_equal $sub1$sub2$sub3$reading \ [run_command $fd "subscribe ch1 ch2 ch3"] - # set sub2 "4) \"subscribe\"\n5) \"ch2\"\n6) (integer) 2\n" - # set sub3 "7) \"subscribe\"\n8) \"ch3\"\n9) (integer) 3\n" # Receive pubsub message. r publish ch2 hello set message "1) \"message\"\n2) \"ch2\"\n3) \"hello\"\n" @@ -243,10 +267,6 @@ start_server {tags {"cli"}} { [run_command $fd "subscribe ch1"] } - test_interactive_cli "Subscribed mode" { - - } - test_interactive_nontty_cli "Subscribed mode" { # Raw output and no "Reading messages..." info message. # Use RESP3 in this test case. diff --git a/tests/unit/cluster/pubsubshard.tcl b/tests/unit/cluster/pubsubshard.tcl index 74018b810c..1f68952aa4 100644 --- a/tests/unit/cluster/pubsubshard.tcl +++ b/tests/unit/cluster/pubsubshard.tcl @@ -59,9 +59,6 @@ test "sunsubscribe without specifying any channel would unsubscribe all shard ch set publishclient [valkey_client_by_addr $publishnode(host) $publishnode(port)] set subscribeclient [valkey_deferring_client_by_addr $publishnode(host) $publishnode(port)] - # assert_equal {1} [ssubscribe $subscribeclient {"\{channel.0\}1"}] - # assert_equal {2} [ssubscribe $subscribeclient {"\{channel.0\}2"}] - # assert_equal {3} [ssubscribe $subscribeclient {"\{channel.0\}3"}] set sub_res [ssubscribe $subscribeclient [list "\{channel.0\}1" "\{channel.0\}2" "\{channel.0\}3"]] assert_equal [list 1 2 3] $sub_res diff --git a/tests/unit/pubsub.tcl b/tests/unit/pubsub.tcl index c873d0276d..8925afe985 100644 --- a/tests/unit/pubsub.tcl +++ b/tests/unit/pubsub.tcl @@ -45,8 +45,6 @@ start_server {tags {"pubsub network"}} { set rd1 [valkey_deferring_client] # subscribe to two channels - #assert_equal {1} [subscribe $rd1 {chan1}] - #assert_equal {2} [subscribe $rd1 {chan2}] assert_equal {1 2} [subscribe $rd1 {chan1 chan2}] assert_equal 1 [r publish chan1 hello] assert_equal 1 [r publish chan2 world] @@ -85,9 +83,6 @@ start_server {tags {"pubsub network"}} { test "PUBLISH/SUBSCRIBE after UNSUBSCRIBE without arguments" { set rd1 [valkey_deferring_client] - #assert_equal {1} [subscribe $rd1 {chan1}] - #assert_equal {2} [subscribe $rd1 {chan2}] - #assert_equal {3} [subscribe $rd1 {chan3}] assert_equal {1 2 3} [subscribe $rd1 {chan1 chan2 chan3}] unsubscribe $rd1 # wait for the unsubscribe to take effect @@ -106,9 +101,6 @@ start_server {tags {"pubsub network"}} { test "SUBSCRIBE to one channel more than once" { set rd1 [valkey_deferring_client] - #assert_equal {1} [subscribe $rd1 {chan1}] - #assert_equal {2} [subscribe $rd1 {chan2}] - #assert_equal {3} [subscribe $rd1 {chan3}] assert_equal {1 1 1} [subscribe $rd1 {chan1 chan1 chan1}] assert_equal 1 [r publish chan1 hello] assert_equal {message chan1 hello} [$rd1 read] @@ -132,8 +124,6 @@ start_server {tags {"pubsub network"}} { # subscribe to two patterns assert_equal {1 2} [psubscribe $rd1 {foo.* bar.*}] - #assert_equal {1} [psubscribe $rd1 {foo.*}] - #assert_equal {2} [psubscribe $rd1 {bar.*}] assert_equal 1 [r publish foo.1 hello] assert_equal 1 [r publish bar.1 hello] assert_equal 0 [r publish foo1 hello] @@ -491,10 +481,8 @@ start_server {tags {"pubsub network"}} { # Note: SUBSCRIBE and UNSUBSCRIBE with multiple channels in the same command, # Only one response is returned # This update matches with Redis response: one command always returns one response - #assert_equal "subscribe foo 1 subscribe bar 2 subscribe baz 3" [r subscribe foo bar baz] - assert_equal "subscribe foo 1" [r subscribe foo bar baz] - assert_equal "subscribe bar 2" [r read] - assert_equal "subscribe baz 3" [r read] + r client capa subv2 + assert_equal "subscribe foo 1 subscribe bar 2 subscribe baz 3" [r subscribe foo bar baz] r multi r ping abc diff --git a/tests/unit/pubsubshard.tcl b/tests/unit/pubsubshard.tcl index c405773272..ee565f4177 100644 --- a/tests/unit/pubsubshard.tcl +++ b/tests/unit/pubsubshard.tcl @@ -64,9 +64,6 @@ start_server {tags {"pubsubshard external:skip"}} { test "SSUBSCRIBE to one channel more than once" { set rd1 [valkey_deferring_client] - #assert_equal {1} [ssubscribe $rd1 {chan1}] - #assert_equal {1} [ssubscribe $rd1 {chan1}] - #assert_equal {1} [ssubscribe $rd1 {chan1}] assert_equal {1 1 1} [ssubscribe $rd1 {chan1 chan1 chan1}] assert_equal 1 [r SPUBLISH chan1 hello] assert_equal {smessage chan1 hello} [$rd1 read]