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

Merge pull request #38779 from etiennebarrie/fix-perform_enqueued_jobs-inside-assert_enqueued_with

Fix perform_enqueued_jobs without a block inside other helpers
......@@ -119,15 +119,15 @@ def queue_adapter_for_test
# end
def assert_enqueued_jobs(number, only: nil, except: nil, queue: nil, &block)
if block_given?
original_count = enqueued_jobs_with(only: only, except: except, queue: queue)
original_jobs = enqueued_jobs_with(only: only, except: except, queue: queue)
assert_nothing_raised(&block)
new_count = enqueued_jobs_with(only: only, except: except, queue: queue)
new_jobs = enqueued_jobs_with(only: only, except: except, queue: queue)
actual_count = new_count - original_count
actual_count = (new_jobs - original_jobs).count
else
actual_count = enqueued_jobs_with(only: only, except: except, queue: queue)
actual_count = enqueued_jobs_with(only: only, except: except, queue: queue).count
end
assert_equal number, actual_count, "#{number} jobs expected, but #{actual_count} were enqueued"
......@@ -279,7 +279,7 @@ def assert_performed_jobs(number, only: nil, except: nil, queue: nil, &block)
performed_jobs_size = new_count - original_count
else
performed_jobs_size = performed_jobs_with(only: only, except: except, queue: queue)
performed_jobs_size = performed_jobs_with(only: only, except: except, queue: queue).count
end
assert_equal number, performed_jobs_size, "#{number} jobs expected, but #{performed_jobs_size} were performed"
......@@ -385,11 +385,11 @@ def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil, &block)
potential_matches = []
if block_given?
original_enqueued_jobs_count = enqueued_jobs.count
original_enqueued_jobs = enqueued_jobs.dup
assert_nothing_raised(&block)
jobs = enqueued_jobs.drop(original_enqueued_jobs_count)
jobs = enqueued_jobs - original_enqueued_jobs
else
jobs = enqueued_jobs
end
......@@ -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.dup.count do |job|
jobs.dup.select do |job|
job_class = job.fetch(:job)
if only
......@@ -644,7 +644,7 @@ def flush_enqueued_jobs(only: nil, except: nil, queue: nil, at: nil)
queue_adapter.enqueued_jobs.delete(payload)
queue_adapter.performed_jobs << payload
instantiate_job(payload).perform_now
end
end.count
end
def prepare_args_for_assertion(args)
......
......@@ -961,6 +961,19 @@ def test_perform_enqueued_jobs_without_block_removes_from_enqueued_jobs
assert_equal(0, enqueued_jobs.size)
end
def test_perform_enqueued_jobs_without_block_works_with_other_helpers
NestedJob.perform_later
assert_equal(0, performed_jobs.size)
assert_equal(1, enqueued_jobs.size)
assert_enqueued_jobs(1) do
assert_enqueued_with(job: LoggingJob) do
perform_enqueued_jobs
end
end
assert_equal(1, performed_jobs.size)
assert_equal(1, enqueued_jobs.size)
end
def test_perform_enqueued_jobs_without_block_only_performs_once
JobBuffer.clear
RescueJob.perform_later("no exception")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册