1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/test/cases/exceptions_test.rb
2016-07-29 13:54:55 -07:00

47 lines
1.4 KiB
Ruby

require 'helper'
require 'jobs/retry_job'
class ExceptionsTest < ActiveSupport::TestCase
setup do
JobBuffer.clear
end
test "successfully retry job throwing exception against defaults" do
RetryJob.perform_later 'SeriousError', 5
assert_equal [
"Raised SeriousError for the 1st time",
"Raised SeriousError for the 2nd time",
"Raised SeriousError for the 3rd time",
"Raised SeriousError for the 4th time",
"Successfully completed job" ], JobBuffer.values
end
test "successfully retry job throwing exception against higher limit" do
RetryJob.perform_later 'VerySeriousError', 9
assert_equal 9, JobBuffer.values.count
end
test "failed retry job when exception kept occurring against defaults" do
begin
RetryJob.perform_later 'SeriousError', 6
assert_equal "Raised SeriousError for the 5th time", JobBuffer.last_value
rescue SeriousError
pass
end
end
test "failed retry job when exception kept occurring against higher limit" do
begin
RetryJob.perform_later 'VerySeriousError', 11
assert_equal "Raised VerySeriousError for the 10th time", JobBuffer.last_value
rescue SeriousError
pass
end
end
test "discard job" do
RetryJob.perform_later 'NotSeriousError', 2
assert_equal "Raised NotSeriousError for the 1st time", JobBuffer.last_value
end
end