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

While using perform_enqueued_jobs enqueued jobs must be stored as well #38584

This commit is contained in:
dmitry 2020-02-28 13:28:27 +01:00
parent 12e8c537c5
commit 7e6e6eb56f
3 changed files with 28 additions and 6 deletions

View file

@ -78,5 +78,9 @@
*Anthony Ross*
* While using `perform_enqueued_jobs` test helper enqueued jobs must be stored for the later check with `assert_enqueued_with`.
*Dmitry Polushkin*
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activejob/CHANGELOG.md) for previous changes.

View file

@ -26,15 +26,11 @@ module ActiveJob
end
def enqueue(job) #:nodoc:
return if filtered?(job)
job_data = job_to_hash(job)
perform_or_enqueue(perform_enqueued_jobs, job, job_data)
end
def enqueue_at(job, timestamp) #:nodoc:
return if filtered?(job)
job_data = job_to_hash(job, at: timestamp)
perform_or_enqueue(perform_enqueued_at_jobs, job, job_data)
end
@ -49,9 +45,9 @@ module ActiveJob
end
def perform_or_enqueue(perform, job, job_data)
if perform
if perform && !filtered?(job)
performed_jobs << job_data
Base.execute job.serialize
Base.execute(job.serialize)
else
enqueued_jobs << job_data
end

View file

@ -633,6 +633,17 @@ class EnqueuedJobsTest < ActiveJob::TestCase
assert_enqueued_with(job: HelloJob, at: Date.tomorrow.noon)
end
def test_assert_enqueued_with_wait_until_with_performed
assert_enqueued_with(job: LoggingJob) do
perform_enqueued_jobs(only: HelloJob) do
HelloJob.set(wait_until: Date.tomorrow.noon).perform_later("david")
LoggingJob.set(wait_until: Date.tomorrow.noon).perform_later("enqueue")
end
end
assert_enqueued_jobs 1
assert_performed_jobs 1
end
def test_assert_enqueued_with_with_hash_arg
assert_enqueued_with(job: MultipleKwargsJob, args: [{ argument1: 1, argument2: { a: 1, b: 2 } }]) do
MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
@ -692,6 +703,17 @@ class EnqueuedJobsTest < ActiveJob::TestCase
assert_equal 2, queue_adapter.enqueued_jobs.count
end
def test_assert_enqueued_jobs_with_performed
assert_enqueued_with(job: LoggingJob) do
perform_enqueued_jobs(only: HelloJob) do
HelloJob.perform_later("david")
LoggingJob.perform_later("enqueue")
end
end
assert_enqueued_jobs 1
assert_performed_jobs 1
end
end
class PerformedJobsTest < ActiveJob::TestCase