Permalink
Browse files

Restore missing list tests.

  • Loading branch information...
1 parent fb72736 commit c8d81a10129eaa8dcd93f383a45a6f62f45b8343 @djanowski djanowski committed Jan 3, 2011
Showing with 40 additions and 0 deletions.
  1. +40 −0 test/lint/lists.rb
View
@@ -1,3 +1,7 @@
+require File.expand_path("./../redis_mock", File.dirname(__FILE__))
+
+include RedisMock::Helper
+
test "BLPOP" do |r|
r.lpush("foo", "s1")
r.lpush("foo", "s2")
@@ -121,3 +125,39 @@
assert "s2" == r.rpop("foo")
assert 1 == r.llen("foo")
end
+
+test "BLPOP should try to reconnect when disconnected by Redis" do
+ times = 0
+
+ replies = {
+ :blpop => lambda do |*_|
+ times += 1
+ "+OK" if times > 2
+ end
+ }
+
+ redis_mock(replies) do
+ assert_equal "OK", Redis.new(OPTIONS.merge(:port => 6380)).blpop("foo", 0)
+ end
+end
+
+test "BLPOP with a timeout should return nil when hitting the timeout" do |r|
+ assert_equal nil, r.blpop("foo", 1)
+end
+
+test "BLPOP losing connection" do
+ replies = {
+ :blpop => lambda { |*_| Process.kill(9, Process.pid) },
+ :ping => lambda { |*_| "+PONG" },
+ }
+
+ redis_mock(replies) do
+ redis = Redis.new(OPTIONS.merge(:port => 6380))
+
+ assert_equal "PONG", redis.ping
+
+ assert_raise(Errno::ECONNREFUSED) do
+ redis.blpop "foo", 1
+ end
+ end
+end

0 comments on commit c8d81a1

Please sign in to comment.