Browse files

Don't yield the block on timeouts.

  • Loading branch information...
1 parent 1afba24 commit fc1a60918378a531ce8a6578fb68b727dbdef494 @djanowski djanowski committed Mar 20, 2012
Showing with 18 additions and 0 deletions.
  1. +2 −0 lib/ost.rb
  2. +16 −0 test/ost_test.rb
View
2 lib/ost.rb
@@ -25,6 +25,8 @@ def each(&block)
item = @key.brpoplpush(@backup, TIMEOUT)
+ next unless item
+
block.call(item)
@backup.lpop
View
16 test/ost_test.rb
@@ -53,6 +53,22 @@ def enqueue(id)
assert_equal ["1"], results
end
+ test "doesn't yield the block on timeout" do |redis|
+ results = []
+
+ Thread.new do
+ sleep 2
+ enqueue(1)
+ end
+
+ ost do |item|
+ results << item
+ end
+
+ assert_equal [], Ost[:events].items
+ assert_equal ["1"], results
+ end
+
test "halt processing a queue" do
Thread.new do
sleep 0.5

0 comments on commit fc1a609

Please sign in to comment.