Browse files

Correctly handle a queue pushing to itself on exception.

  • Loading branch information...
1 parent b41c7c2 commit 8c7ef8536327b371adc7145f82177b966296da76 @xaviershay xaviershay committed May 3, 2012
Showing with 20 additions and 0 deletions.
  1. +1 −0 lib/girl_friday/work_queue.rb
  2. +19 −0 test/test_girl_friday_queue.rb
View
1 lib/girl_friday/work_queue.rb
@@ -189,6 +189,7 @@ def supervisor_loop
@busy_workers.delete(ex.actor)
ready_workers << Actor.spawn_link(&@work_loop)
handle_error(ex.reason)
+ drain
end
end
end
View
19 test/test_girl_friday_queue.rb
@@ -36,6 +36,25 @@ def test_should_handle_worker_error
end
end
+ def test_should_handle_worker_error_with_retry
+ async_test do |cb|
+ TestErrorHandler.send(:define_method, :handle) do |ex|
+ end
+
+ queue = GirlFriday::WorkQueue.new('error', :error_handler => TestErrorHandler, :size => 1) do |msg|
+ begin
+ raise 'oops' if msg == 1
+ queue.shutdown do
+ cb.call
+ end
+ ensure
+ queue.push(0)
+ end
+ end
+ queue.push(1)
+ end
+ end
+
def test_should_use_a_default_error_handler_when_none_specified
async_test do |cb|
queue = GirlFriday::WorkQueue.new('error') do |msg|

0 comments on commit 8c7ef85

Please sign in to comment.