1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use descriptive exception names

This commit is contained in:
David Heinemeier Hansson 2016-08-01 16:09:16 -07:00
parent a4fc7dc957
commit 08a92d47b0
2 changed files with 20 additions and 20 deletions

View file

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

View file

@ -1,14 +1,14 @@
require_relative '../support/job_buffer' require_relative '../support/job_buffer'
require 'active_support/core_ext/integer/inflections' require 'active_support/core_ext/integer/inflections'
class SeriousError < StandardError; end class DefaultsError < StandardError; end
class VerySeriousError < StandardError; end class ShortWaitTenAttemptsError < StandardError; end
class NotSeriousError < StandardError; end class DiscardableError < StandardError; end
class RetryJob < ActiveJob::Base class RetryJob < ActiveJob::Base
retry_on SeriousError retry_on DefaultsError
retry_on VerySeriousError, wait: 1.second, attempts: 10 retry_on ShortWaitTenAttemptsError, wait: 1.second, attempts: 10
discard_on NotSeriousError discard_on DiscardableError
def perform(raising, attempts) def perform(raising, attempts)
if executions < attempts if executions < attempts