diff --git a/test/test_retry.rb b/test/test_retry.rb index 726220f4..e4d8e096 100644 --- a/test/test_retry.rb +++ b/test/test_retry.rb @@ -117,6 +117,60 @@ class TestRetry < Sidekiq::Test @redis.verify end + it 'shuts down without retrying work-in-progress, which will resume' do + @redis.expect :zadd, 1, ['retry', String, String] + msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true } + handler = Sidekiq::Middleware::Server::RetryJobs.new + assert_raises Sidekiq::Shutdown do + handler.call(worker, msg, 'default') do + raise Sidekiq::Shutdown + end + end + assert_raises(MockExpectationError, "zadd should not be called") do + @redis.verify + end + end + + it 'shuts down cleanly when shutdown causes exception' do + @redis.expect :zadd, 1, ['retry', String, String] + msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true } + handler = Sidekiq::Middleware::Server::RetryJobs.new + assert_raises Sidekiq::Shutdown do + handler.call(worker, msg, 'default') do + begin + raise Sidekiq::Shutdown + rescue Interrupt + raise "kerblammo!" + end + end + end + assert_raises(MockExpectationError, "zadd should not be called") do + @redis.verify + end + end + + it 'shuts down cleanly when shutdown causes chained exceptions' do + @redis.expect :zadd, 1, ['retry', String, String] + msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true } + handler = Sidekiq::Middleware::Server::RetryJobs.new + assert_raises Sidekiq::Shutdown do + handler.call(worker, msg, 'default') do + begin + raise Sidekiq::Shutdown + rescue Interrupt + begin + raise "kerblammo!" + rescue + raise "kablooie!" + end + end + end + end + assert_raises(MockExpectationError, "zadd should not be called") do + @redis.verify + end + end + it 'allows a retry queue' do @redis.expect :zadd, 1, ['retry', String, String] msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'retry_queue' => 'retry' }