Skip to content

Commit 369f5f6

Browse files
committed
add tests
1 parent d4e50f0 commit 369f5f6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/publish_subscribe_test.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,46 @@ def test_psubscribe_and_punsubscribe
8787
assert_equal "s1", @message
8888
end
8989

90+
def test_pubsub_with_numpat_subcommand
91+
@subscribed = false
92+
wire = Wire.new do
93+
r.psubscribe("f*") do |on|
94+
on.psubscribe { |channel, total| @subscribed = true }
95+
on.pmessage { |pattern, channel, message| r.punsubscribe }
96+
end
97+
end
98+
Wire.pass while !@subscribed
99+
redis = Redis.new(OPTIONS)
100+
numpat_result = redis.pubsub(:numpat)
101+
102+
redis.publish("foo", "s1")
103+
wire.join
104+
105+
assert_equal redis.pubsub(:numpat), 0
106+
assert_equal numpat_result, 1
107+
end
108+
109+
110+
def test_pubsub_with_channels_and_numsub_subcommnads
111+
@subscribed = false
112+
wire = Wire.new do
113+
r.subscribe("foo") do |on|
114+
on.subscribe { |channel, total| @subscribed = true }
115+
on.message { |channel, message| r.unsubscribe }
116+
end
117+
end
118+
Wire.pass while !@subscribed
119+
redis = Redis.new(OPTIONS)
120+
channels_result = redis.pubsub(:channels)
121+
numsub_result = redis.pubsub(:numsub, 'foo', 'boo')
122+
123+
redis.publish("foo", "s1")
124+
wire.join
125+
126+
assert_equal channels_result, ['foo']
127+
assert_equal numsub_result, ['foo', '1', 'boo', '0']
128+
end
129+
90130
def test_subscribe_connection_usable_after_raise
91131
@subscribed = false
92132

0 commit comments

Comments
 (0)