Skip to content

Commit 220c364

Browse files
committed
Simplify subscribe with timeout tests.
1 parent 546ce35 commit 220c364

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

test/publish_subscribe_test.rb

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -253,40 +253,30 @@ def test_subscribe_past_a_timeout
253253
end
254254

255255
def test_subscribe_with_timeout
256-
assert_raise Redis::TimeoutError do
257-
sleep = %{sleep #{OPTIONS[:timeout] * 2}}
258-
publish = %{echo "publish foo bar\r\n" | nc localhost #{OPTIONS[:port]}}
259-
cmd = [sleep, publish].join("; ")
260-
261-
IO.popen(cmd, "r+") do |pipe|
262-
received = false
256+
received = false
263257

264-
r.subscribe_with_timeout(OPTIONS[:timeout], "foo") do |on|
265-
on.message do |channel, message|
266-
received = true
267-
r.unsubscribe
268-
end
258+
assert_raise Redis::TimeoutError do
259+
r.subscribe_with_timeout(1, "foo") do |on|
260+
on.message do |channel, message|
261+
received = true
269262
end
270263
end
271264
end
265+
266+
assert !received
272267
end
273268

274269
def test_psubscribe_with_timeout
275-
assert_raise Redis::TimeoutError do
276-
sleep = %{sleep #{OPTIONS[:timeout] * 2}}
277-
publish = %{echo "publish foo bar\r\n" | nc localhost #{OPTIONS[:port]}}
278-
cmd = [sleep, publish].join("; ")
279-
280-
IO.popen(cmd, "r+") do |pipe|
281-
received = false
270+
received = false
282271

283-
r.psubscribe_with_timeout(OPTIONS[:timeout], "f*") do |on|
284-
on.message do |channel, message|
285-
received = true
286-
r.unsubscribe
287-
end
272+
assert_raise Redis::TimeoutError do
273+
r.psubscribe_with_timeout(1, "f*") do |on|
274+
on.message do |channel, message|
275+
received = true
288276
end
289277
end
290278
end
279+
280+
assert !received
291281
end
292282
end

0 commit comments

Comments
 (0)