未验证 提交 08cbf442 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #38686 from Edouard-chin/ec-job-test-adapter

AJ `perform_enqueued_jobs` shouldn't perform job retries: 
* `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*
......
......@@ -602,7 +602,7 @@ def clear_performed_jobs
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
......@@ -641,8 +641,8 @@ def performed_jobs_with(only: nil, except: nil, queue: nil, &block)
def flush_enqueued_jobs(only: nil, except: nil, queue: nil, at: nil)
enqueued_jobs_with(only: only, except: except, queue: queue, at: at) do |payload|
instantiate_job(payload).perform_now
queue_adapter.performed_jobs << payload
instantiate_job(payload).perform_now
end
end
......
......@@ -909,6 +909,27 @@ def test_perform_enqueued_jobs_block_with_at_with_job_wait_in_future
assert_performed_jobs 0
end
def test_perform_enqueued_jobs_properly_count_job_that_raises
RaisingJob.perform_later("NotImplementedError")
assert_raises(NotImplementedError) do
perform_enqueued_jobs(only: RaisingJob)
end
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
......@@ -1867,13 +1888,13 @@ def test_assert_performed_with_without_block_does_not_change_jobs_count
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
......
......@@ -5,7 +5,7 @@ class RaisingJob < ActiveJob::Base
retry_on(MyError, attempts: 2)
def perform
raise MyError
def perform(error = "RaisingJob::MyError")
raise error.constantize
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册