diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index 1a754a070b..c3b813d123 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,3 +1,13 @@ +* `ActiveJob::TestCase#perform_enqueued_jobs` will no longer perform retries: + + When calling `perform_enqueued_jobs` without a block, the adapter will + now perform jobs that are **already** in the queue. Jobs that will end up in + the queue afterwards won't be performed. + + This change only affects `perform_enqueued_jobs` when no block is given. + + *Edouard Chin* + * Add queue name support to Que adapter *Brad Nauta*, *Wojciech Wnętrzak* diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 2d1e0dd103..b21993283e 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -602,7 +602,7 @@ module ActiveJob def jobs_with(jobs, only: nil, except: nil, queue: nil, at: nil) validate_option(only: only, except: except) - jobs.count do |job| + jobs.dup.count do |job| job_class = job.fetch(:job) if only diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 9cf829b2aa..0b70708b45 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -919,6 +919,17 @@ class PerformedJobsTest < ActiveJob::TestCase assert_equal(1, performed_jobs.size) end + def test_perform_enqueued_jobs_dont_perform_retries + RaisingJob.perform_later + + assert_nothing_raised do + perform_enqueued_jobs(only: RaisingJob) + end + + assert_equal(1, performed_jobs.size) + assert_equal(2, enqueued_jobs.size) + end + def test_assert_performed_jobs assert_nothing_raised do assert_performed_jobs 1 do @@ -1877,13 +1888,13 @@ class PerformedJobsTest < ActiveJob::TestCase end test "TestAdapter respect max attempts" do - RaisingJob.perform_later - - assert_raises(RaisingJob::MyError) do - perform_enqueued_jobs + perform_enqueued_jobs(only: RaisingJob) do + assert_raises(RaisingJob::MyError) do + RaisingJob.perform_later + end end - assert_equal 2, queue_adapter.enqueued_jobs.count + assert_equal 2, queue_adapter.performed_jobs.count end end