Skip to content

Commit 6bd5bd8

Browse files
authored
test: add sharded pub/sub cases (#179)
1 parent 82538be commit 6bd5bd8

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/redis_client/test_cluster.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_pipelined_with_many_commands
168168
results.each_with_index { |got, i| assert_equal(i.to_s, got) }
169169
end
170170

171-
def test_pubsub
171+
def test_global_pubsub
172172
10.times do |i|
173173
pubsub = @client.pubsub
174174
pubsub.call('SUBSCRIBE', "channel#{i}")
@@ -189,6 +189,28 @@ def test_pubsub
189189
assert_equal(['message', channel, 'hello world'], sub.resume)
190190
end
191191

192+
def test_sharded_pubsub
193+
if TEST_REDIS_MAJOR_VERSION < 7
194+
skip('Sharded Pub/Sub is supported by Redis 7+.')
195+
return
196+
end
197+
198+
10.times do |i|
199+
sub = Fiber.new do |client|
200+
channel = "my-channel-#{i}"
201+
pubsub = client.pubsub
202+
pubsub.call('SSUBSCRIBE', channel)
203+
assert_equal(['ssubscribe', channel, 1], pubsub.next_event(TEST_TIMEOUT_SEC))
204+
Fiber.yield(channel)
205+
Fiber.yield(pubsub.next_event(TEST_TIMEOUT_SEC))
206+
end
207+
208+
channel = sub.resume(@client)
209+
@client.call('SPUBLISH', channel, "hello world #{i}")
210+
assert_equal(['smessage', channel, "hello world #{i}"], sub.resume)
211+
end
212+
end
213+
192214
def test_close
193215
assert_nil(@client.close)
194216
end

0 commit comments

Comments
 (0)