2014-08-29 08:52:27 -04:00
|
|
|
|
# encoding: utf-8
|
2014-12-30 15:54:58 -05:00
|
|
|
|
require_relative 'helper'
|
2012-05-25 23:21:42 -04:00
|
|
|
|
require 'sidekiq/scheduled'
|
2012-03-17 21:22:56 -04:00
|
|
|
|
require 'sidekiq/middleware/server/retry_jobs'
|
|
|
|
|
|
2013-09-22 17:38:33 -04:00
|
|
|
|
class TestRetry < Sidekiq::Test
|
2012-03-17 21:22:56 -04:00
|
|
|
|
describe 'middleware' do
|
|
|
|
|
before do
|
2013-05-12 17:25:30 -04:00
|
|
|
|
@redis = Minitest::Mock.new
|
2012-03-17 21:22:56 -04:00
|
|
|
|
# Ugh, this is terrible.
|
|
|
|
|
Sidekiq.instance_variable_set(:@redis, @redis)
|
|
|
|
|
|
|
|
|
|
def @redis.with; yield self; end
|
2014-03-23 18:20:52 -04:00
|
|
|
|
def @redis.multi; yield self; end
|
2012-03-17 21:22:56 -04:00
|
|
|
|
end
|
|
|
|
|
|
2014-05-17 23:47:58 -04:00
|
|
|
|
after do
|
|
|
|
|
Sidekiq.redis = REDIS
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-25 11:07:45 -04:00
|
|
|
|
let(:worker) do
|
|
|
|
|
Class.new do
|
|
|
|
|
include ::Sidekiq::Worker
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-04-01 22:53:45 -04:00
|
|
|
|
it 'allows disabling retry' do
|
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => false }
|
|
|
|
|
msg2 = msg.dup
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg2, 'default') do
|
2012-04-01 22:53:45 -04:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
assert_equal msg, msg2
|
|
|
|
|
end
|
|
|
|
|
|
2012-11-10 00:18:02 -05:00
|
|
|
|
it 'allows a numeric retry' do
|
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => 2 }
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2015-07-10 06:45:18 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2012-11-10 00:18:02 -05:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-07-10 06:45:18 -04:00
|
|
|
|
msg.delete('failed_at')
|
|
|
|
|
assert_equal({"class"=>"Bob", "args"=>[1, 2, "foo"], "retry"=>2, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "retry_count"=>0}, msg)
|
2012-11-10 00:18:02 -05:00
|
|
|
|
@redis.verify
|
|
|
|
|
end
|
|
|
|
|
|
2015-07-10 06:45:18 -04:00
|
|
|
|
it 'allows 0 retry => no retry and dead queue' do
|
|
|
|
|
@redis.expect :zadd, 1, ['dead', Float, String]
|
|
|
|
|
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
|
|
|
|
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => 0 }
|
|
|
|
|
msg2 = msg.dup
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
|
handler.call(worker, msg, 'default') do
|
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
msg.delete('failed_at')
|
|
|
|
|
expected = msg2.merge "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "retry_count"=>0
|
|
|
|
|
assert_equal expected, msg
|
|
|
|
|
@redis.verify # not called
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-27 12:31:55 -04:00
|
|
|
|
it 'handles zany characters in error message, #1705' do
|
2014-08-29 08:52:27 -04:00
|
|
|
|
skip 'skipped! test requires ruby 2.1+' if RUBY_VERSION <= '2.1.0'
|
2014-08-27 12:31:55 -04:00
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => 2 }
|
|
|
|
|
msg2 = msg.dup
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
|
handler.call(worker, msg2, 'default') do
|
|
|
|
|
raise "kerblammo! #{195.chr}"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
msg2.delete('failed_at')
|
|
|
|
|
assert_equal({"class"=>"Bob", "args"=>[1, 2, "foo"], "retry"=>2, "queue"=>"default", "error_message"=>"kerblammo! <20>", "error_class"=>"RuntimeError", "retry_count"=>0}, msg2)
|
|
|
|
|
@redis.verify
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2013-08-01 14:54:30 -04:00
|
|
|
|
it 'allows a max_retries option in initializer' do
|
|
|
|
|
max_retries = 7
|
|
|
|
|
1.upto(max_retries) do
|
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
|
|
|
|
end
|
2014-03-23 18:20:52 -04:00
|
|
|
|
@redis.expect :zadd, 1, ['dead', Float, String]
|
|
|
|
|
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
|
|
|
|
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
2013-08-01 14:54:30 -04:00
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new({:max_retries => max_retries})
|
|
|
|
|
1.upto(max_retries + 1) do
|
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
|
handler.call(worker, msg, 'default') do
|
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@redis.verify
|
|
|
|
|
end
|
|
|
|
|
|
2012-04-27 23:25:46 -04:00
|
|
|
|
it 'saves backtraces' do
|
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'backtrace' => true }
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
c = nil
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2012-04-27 23:25:46 -04:00
|
|
|
|
c = caller(0); raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
assert msg["error_backtrace"]
|
2012-11-01 19:08:27 -04:00
|
|
|
|
assert_equal c[0], msg["error_backtrace"][0]
|
2012-11-10 00:18:02 -05:00
|
|
|
|
@redis.verify
|
2012-04-27 23:25:46 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'saves partial backtraces' do
|
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'backtrace' => 3 }
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
c = nil
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2015-01-10 00:07:01 -05:00
|
|
|
|
c = caller(0)[0...3]; raise "kerblammo!"
|
2012-04-27 23:25:46 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
assert msg["error_backtrace"]
|
|
|
|
|
assert_equal c, msg["error_backtrace"]
|
2015-01-10 00:07:01 -05:00
|
|
|
|
assert_equal 3, c.size
|
|
|
|
|
assert_equal 3, msg["error_backtrace"].size
|
2012-04-27 23:25:46 -04:00
|
|
|
|
end
|
|
|
|
|
|
2012-03-17 21:22:56 -04:00
|
|
|
|
it 'handles a new failed message' do
|
2012-03-18 02:04:31 -04:00
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
2012-04-01 22:53:45 -04:00
|
|
|
|
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
|
2012-03-17 21:22:56 -04:00
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2012-03-17 21:22:56 -04:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
assert_equal 'default', msg["queue"]
|
|
|
|
|
assert_equal 'kerblammo!', msg["error_message"]
|
|
|
|
|
assert_equal 'RuntimeError', msg["error_class"]
|
|
|
|
|
assert_equal 0, msg["retry_count"]
|
2012-04-27 23:25:46 -04:00
|
|
|
|
refute msg["error_backtrace"]
|
2012-03-17 21:22:56 -04:00
|
|
|
|
assert msg["failed_at"]
|
|
|
|
|
@redis.verify
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-30 02:58:19 -04:00
|
|
|
|
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
|
2014-06-30 03:09:44 -04:00
|
|
|
|
skip('Not supported in Ruby < 2.1.0') if RUBY_VERSION < '2.1.0'
|
|
|
|
|
|
2014-06-30 02:58:19 -04:00
|
|
|
|
@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
|
2014-06-30 03:09:44 -04:00
|
|
|
|
skip('Not supported in Ruby < 2.1.0') if RUBY_VERSION < '2.1.0'
|
|
|
|
|
|
2014-06-30 02:58:19 -04:00
|
|
|
|
@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
|
|
|
|
|
|
2013-01-15 20:28:52 -05:00
|
|
|
|
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' }
|
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2013-01-15 20:28:52 -05:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
assert_equal 'retry', msg["queue"]
|
|
|
|
|
assert_equal 'kerblammo!', msg["error_message"]
|
|
|
|
|
assert_equal 'RuntimeError', msg["error_class"]
|
|
|
|
|
assert_equal 0, msg["retry_count"]
|
|
|
|
|
refute msg["error_backtrace"]
|
|
|
|
|
assert msg["failed_at"]
|
|
|
|
|
@redis.verify
|
|
|
|
|
end
|
|
|
|
|
|
2012-03-17 21:22:56 -04:00
|
|
|
|
it 'handles a recurring failed message' do
|
2012-03-18 02:04:31 -04:00
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
2014-02-09 18:08:21 -05:00
|
|
|
|
now = Time.now.to_f
|
2012-04-01 22:53:45 -04:00
|
|
|
|
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], 'retry' => true, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>10}
|
2012-03-17 21:22:56 -04:00
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2012-03-17 21:22:56 -04:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
assert_equal 'default', msg["queue"]
|
|
|
|
|
assert_equal 'kerblammo!', msg["error_message"]
|
|
|
|
|
assert_equal 'RuntimeError', msg["error_class"]
|
|
|
|
|
assert_equal 11, msg["retry_count"]
|
|
|
|
|
assert msg["failed_at"]
|
|
|
|
|
@redis.verify
|
|
|
|
|
end
|
2012-03-18 02:04:31 -04:00
|
|
|
|
|
2012-10-17 18:51:26 -04:00
|
|
|
|
it 'handles a recurring failed message before reaching user-specifed max' do
|
|
|
|
|
@redis.expect :zadd, 1, ['retry', String, String]
|
2014-02-09 18:08:21 -05:00
|
|
|
|
now = Time.now.to_f
|
2012-11-10 00:18:02 -05:00
|
|
|
|
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], 'retry' => 10, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>8}
|
2012-10-17 18:51:26 -04:00
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2012-10-17 18:51:26 -04:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
assert_equal 'default', msg["queue"]
|
|
|
|
|
assert_equal 'kerblammo!', msg["error_message"]
|
|
|
|
|
assert_equal 'RuntimeError', msg["error_class"]
|
2012-11-10 00:18:02 -05:00
|
|
|
|
assert_equal 9, msg["retry_count"]
|
2012-10-17 18:51:26 -04:00
|
|
|
|
assert msg["failed_at"]
|
|
|
|
|
@redis.verify
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'throws away old messages after too many retries (using the default)' do
|
2014-02-09 18:08:21 -05:00
|
|
|
|
now = Time.now.to_f
|
2012-10-16 09:55:04 -04:00
|
|
|
|
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry"=>true, "retry_count"=>25}
|
2014-03-23 18:20:52 -04:00
|
|
|
|
@redis.expect :zadd, 1, ['dead', Float, String]
|
|
|
|
|
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
|
|
|
|
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
2012-03-18 02:04:31 -04:00
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2012-03-18 02:04:31 -04:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-03-23 18:20:52 -04:00
|
|
|
|
@redis.verify
|
2012-03-18 02:04:31 -04:00
|
|
|
|
end
|
2012-10-17 18:51:26 -04:00
|
|
|
|
|
|
|
|
|
it 'throws away old messages after too many retries (using user-specified max)' do
|
2014-02-09 18:08:21 -05:00
|
|
|
|
now = Time.now.to_f
|
2012-10-17 18:51:26 -04:00
|
|
|
|
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry"=>3, "retry_count"=>3}
|
2014-03-23 18:20:52 -04:00
|
|
|
|
@redis.expect :zadd, 1, ['dead', Float, String]
|
|
|
|
|
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
|
|
|
|
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
2012-10-17 18:51:26 -04:00
|
|
|
|
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
|
|
|
|
assert_raises RuntimeError do
|
2013-06-25 11:07:45 -04:00
|
|
|
|
handler.call(worker, msg, 'default') do
|
2012-10-17 18:51:26 -04:00
|
|
|
|
raise "kerblammo!"
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-03-23 18:20:52 -04:00
|
|
|
|
@redis.verify
|
2013-03-18 17:20:28 -04:00
|
|
|
|
end
|
2013-06-25 11:07:45 -04:00
|
|
|
|
|
|
|
|
|
describe "custom retry delay" do
|
2013-06-25 12:35:11 -04:00
|
|
|
|
before do
|
|
|
|
|
@old_logger = Sidekiq.logger
|
|
|
|
|
@tmp_log_path = '/tmp/sidekiq-retries.log'
|
|
|
|
|
Sidekiq.logger = Logger.new(@tmp_log_path)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after do
|
|
|
|
|
Sidekiq.logger = @old_logger
|
|
|
|
|
Sidekiq.options.delete(:logfile)
|
2014-03-19 20:41:11 -04:00
|
|
|
|
File.unlink @tmp_log_path if File.exist?(@tmp_log_path)
|
2013-06-25 12:35:11 -04:00
|
|
|
|
end
|
2013-06-25 11:07:45 -04:00
|
|
|
|
|
|
|
|
|
let(:custom_worker) do
|
|
|
|
|
Class.new do
|
|
|
|
|
include ::Sidekiq::Worker
|
|
|
|
|
|
|
|
|
|
sidekiq_retry_in do |count|
|
|
|
|
|
count * 2
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-25 12:35:11 -04:00
|
|
|
|
let(:error_worker) do
|
|
|
|
|
Class.new do
|
|
|
|
|
include ::Sidekiq::Worker
|
|
|
|
|
|
|
|
|
|
sidekiq_retry_in do |count|
|
|
|
|
|
count / 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-25 14:11:19 -04:00
|
|
|
|
let(:handler) { Sidekiq::Middleware::Server::RetryJobs.new }
|
2013-06-25 11:07:45 -04:00
|
|
|
|
|
|
|
|
|
it "retries with a default delay" do
|
2014-02-14 09:43:34 -05:00
|
|
|
|
refute_equal 4, handler.__send__(:delay_for, worker, 2)
|
2013-06-25 11:07:45 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "retries with a custom delay" do
|
2014-02-14 09:43:34 -05:00
|
|
|
|
assert_equal 4, handler.__send__(:delay_for, custom_worker, 2)
|
2013-06-25 11:07:45 -04:00
|
|
|
|
end
|
2013-06-25 12:35:11 -04:00
|
|
|
|
|
|
|
|
|
it "falls back to the default retry on exception" do
|
2014-02-14 09:43:34 -05:00
|
|
|
|
refute_equal 4, handler.__send__(:delay_for, error_worker, 2)
|
2013-06-25 12:35:11 -04:00
|
|
|
|
assert_match(/Failure scheduling retry using the defined `sidekiq_retry_in`/,
|
|
|
|
|
File.read(@tmp_log_path), 'Log entry missing for sidekiq_retry_in')
|
|
|
|
|
end
|
2013-06-25 11:07:45 -04:00
|
|
|
|
end
|
2015-04-08 07:08:29 -04:00
|
|
|
|
|
2015-04-08 13:34:49 -04:00
|
|
|
|
describe 'handles errors withouth cause' do
|
|
|
|
|
before do
|
|
|
|
|
@error = nil
|
|
|
|
|
begin
|
|
|
|
|
raise ::StandardError, 'Error'
|
|
|
|
|
rescue ::StandardError => e
|
|
|
|
|
@error = e
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not recurse infinitely checking if it's a shutdown" do
|
|
|
|
|
assert(!Sidekiq::Middleware::Server::RetryJobs.new.send(
|
|
|
|
|
:exception_caused_by_shutdown?, @error))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-08 07:08:29 -04:00
|
|
|
|
describe 'handles errors with circular causes' do
|
|
|
|
|
before do
|
|
|
|
|
@error = nil
|
|
|
|
|
begin
|
|
|
|
|
begin
|
|
|
|
|
raise ::StandardError, 'Error 1'
|
|
|
|
|
rescue ::StandardError => e1
|
|
|
|
|
begin
|
|
|
|
|
raise ::StandardError, 'Error 2'
|
2015-06-22 14:07:28 -04:00
|
|
|
|
rescue ::StandardError
|
2015-04-08 07:08:29 -04:00
|
|
|
|
raise e1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
rescue ::StandardError => e
|
|
|
|
|
@error = e
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-08 13:34:49 -04:00
|
|
|
|
it "does not recurse infinitely checking if it's a shutdown" do
|
2015-04-08 07:08:29 -04:00
|
|
|
|
assert(!Sidekiq::Middleware::Server::RetryJobs.new.send(
|
|
|
|
|
:exception_caused_by_shutdown?, @error))
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-03-17 21:22:56 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|