diff options
Diffstat (limited to 'activejob/test')
-rw-r--r-- | activejob/test/cases/callbacks_test.rb | 25 | ||||
-rw-r--r-- | activejob/test/cases/exceptions_test.rb | 20 | ||||
-rw-r--r-- | activejob/test/cases/logging_test.rb | 8 | ||||
-rw-r--r-- | activejob/test/cases/queuing_test.rb | 20 | ||||
-rw-r--r-- | activejob/test/integration/queuing_test.rb | 28 | ||||
-rw-r--r-- | activejob/test/jobs/abort_before_enqueue_job.rb | 9 | ||||
-rw-r--r-- | activejob/test/support/integration/test_case_helpers.rb | 10 |
7 files changed, 69 insertions, 51 deletions
diff --git a/activejob/test/cases/callbacks_test.rb b/activejob/test/cases/callbacks_test.rb index df6ce16858..895edb34a5 100644 --- a/activejob/test/cases/callbacks_test.rb +++ b/activejob/test/cases/callbacks_test.rb @@ -2,6 +2,7 @@ require "helper" require "jobs/callback_job" +require "jobs/abort_before_enqueue_job" require "active_support/core_ext/object/inclusion" @@ -22,4 +23,28 @@ class CallbacksTest < ActiveSupport::TestCase assert "CallbackJob ran around_enqueue_start".in? enqueued_callback_job.history assert "CallbackJob ran around_enqueue_stop".in? enqueued_callback_job.history end + + test "#enqueue returns false when before_enqueue aborts callback chain and return_false_on_aborted_enqueue = true" do + prev = ActiveJob::Base.return_false_on_aborted_enqueue + ActiveJob::Base.return_false_on_aborted_enqueue = true + assert_equal false, AbortBeforeEnqueueJob.new.enqueue + ensure + ActiveJob::Base.return_false_on_aborted_enqueue = prev + end + + test "#enqueue returns self when before_enqueue aborts callback chain and return_false_on_aborted_enqueue = false" do + prev = ActiveJob::Base.return_false_on_aborted_enqueue + ActiveJob::Base.return_false_on_aborted_enqueue = false + job = AbortBeforeEnqueueJob.new + assert_deprecated do + assert_equal job, job.enqueue + end + ensure + ActiveJob::Base.return_false_on_aborted_enqueue = prev + end + + test "#enqueue returns self when the job was enqueued" do + job = CallbackJob.new + assert_equal job, job.enqueue + end end diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index b5328b8d6a..67327e0bbd 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -54,23 +54,19 @@ class ExceptionsTest < ActiveJob::TestCase test "failed retry job when exception kept occurring against defaults" do perform_enqueued_jobs do - begin - RetryJob.perform_later "DefaultsError", 6 - assert_equal "Raised DefaultsError for the 5th time", JobBuffer.last_value - rescue DefaultsError - pass - end + RetryJob.perform_later "DefaultsError", 6 + assert_equal "Raised DefaultsError for the 5th time", JobBuffer.last_value + rescue DefaultsError + pass end end test "failed retry job when exception kept occurring against higher limit" do perform_enqueued_jobs do - begin - RetryJob.perform_later "ShortWaitTenAttemptsError", 11 - assert_equal "Raised ShortWaitTenAttemptsError for the 10th time", JobBuffer.last_value - rescue ShortWaitTenAttemptsError - pass - end + RetryJob.perform_later "ShortWaitTenAttemptsError", 11 + assert_equal "Raised ShortWaitTenAttemptsError for the 10th time", JobBuffer.last_value + rescue ShortWaitTenAttemptsError + pass end end diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index 48ef39aaca..6154ba301d 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -187,11 +187,9 @@ class LoggingTest < ActiveSupport::TestCase def test_retry_stopped_logging_without_block perform_enqueued_jobs do - begin - RetryJob.perform_later "DefaultsError", 6 - rescue DefaultsError - assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\./, @logger.messages) - end + RetryJob.perform_later "DefaultsError", 6 + rescue DefaultsError + assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\./, @logger.messages) end end diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb index 0e843b7215..e7bad83400 100644 --- a/activejob/test/cases/queuing_test.rb +++ b/activejob/test/cases/queuing_test.rb @@ -20,12 +20,10 @@ class QueuingTest < ActiveSupport::TestCase end test "run queued job later" do - begin - result = HelloJob.set(wait_until: 1.second.ago).perform_later "Jamie" - assert result - rescue NotImplementedError - skip - end + result = HelloJob.set(wait_until: 1.second.ago).perform_later "Jamie" + assert result + rescue NotImplementedError + skip end test "job returned by enqueue has the arguments available" do @@ -34,11 +32,9 @@ class QueuingTest < ActiveSupport::TestCase end test "job returned by perform_at has the timestamp available" do - begin - job = HelloJob.set(wait_until: Time.utc(2014, 1, 1)).perform_later - assert_equal Time.utc(2014, 1, 1).to_f, job.scheduled_at - rescue NotImplementedError - skip - end + job = HelloJob.set(wait_until: Time.utc(2014, 1, 1)).perform_later + assert_equal Time.utc(2014, 1, 1).to_f, job.scheduled_at + rescue NotImplementedError + skip end end diff --git a/activejob/test/integration/queuing_test.rb b/activejob/test/integration/queuing_test.rb index 96253773c7..1fa68a8ad5 100644 --- a/activejob/test/integration/queuing_test.rb +++ b/activejob/test/integration/queuing_test.rb @@ -60,25 +60,21 @@ class QueuingTest < ActiveSupport::TestCase end test "should not run job enqueued in the future" do - begin - TestJob.set(wait: 10.minutes).perform_later @id - wait_for_jobs_to_finish_for(5.seconds) - assert_not job_executed - rescue NotImplementedError - skip - end + TestJob.set(wait: 10.minutes).perform_later @id + wait_for_jobs_to_finish_for(5.seconds) + assert_not job_executed + rescue NotImplementedError + skip end test "should run job enqueued in the future at the specified time" do - begin - TestJob.set(wait: 5.seconds).perform_later @id - wait_for_jobs_to_finish_for(2.seconds) - assert_not job_executed - wait_for_jobs_to_finish_for(10.seconds) - assert job_executed - rescue NotImplementedError - skip - end + TestJob.set(wait: 5.seconds).perform_later @id + wait_for_jobs_to_finish_for(2.seconds) + assert_not job_executed + wait_for_jobs_to_finish_for(10.seconds) + assert job_executed + rescue NotImplementedError + skip end test "should supply a provider_job_id when available for immediate jobs" do diff --git a/activejob/test/jobs/abort_before_enqueue_job.rb b/activejob/test/jobs/abort_before_enqueue_job.rb new file mode 100644 index 0000000000..fd278eccf4 --- /dev/null +++ b/activejob/test/jobs/abort_before_enqueue_job.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AbortBeforeEnqueueJob < ActiveJob::Base + before_enqueue { throw(:abort) } + + def perform + raise "This should never be called" + end +end diff --git a/activejob/test/support/integration/test_case_helpers.rb b/activejob/test/support/integration/test_case_helpers.rb index 3d9b265b66..973ee07764 100644 --- a/activejob/test/support/integration/test_case_helpers.rb +++ b/activejob/test/support/integration/test_case_helpers.rb @@ -33,14 +33,12 @@ module TestCaseHelpers end def wait_for_jobs_to_finish_for(seconds = 60) - begin - Timeout.timeout(seconds) do - while !job_executed do - sleep 0.25 - end + Timeout.timeout(seconds) do + while !job_executed do + sleep 0.25 end - rescue Timeout::Error end + rescue Timeout::Error end def job_file(id) |