Skip to content

Commit

Permalink
Update test case for subv2 version
Browse files Browse the repository at this point in the history
Signed-off-by: hwware <wen.hui.ware@gmail.com>
  • Loading branch information
hwware committed Sep 26, 2024
1 parent 7bb578b commit c97985f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
36 changes: 28 additions & 8 deletions tests/integration/valkey-cli.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/cluster/pubsubshard.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 2 additions & 14 deletions tests/unit/pubsub.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/pubsubshard.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit c97985f

Please sign in to comment.