Rails 7 adds the possibility to check on :priority for ActiveJob tests
source link: https://blog.saeloun.com/2021/11/10/rails-7-adds-priority-to-active-job-tests
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Rails 7 adds the possibility to check on :priority for ActiveJob tests
Nov 10, 2021 , by Swaathi Kakarla 1 minute readActiveJob was introduced so that all Rails apps have the adequate queuing infrastructure in place. It is not dependent on the actual queue adapter that is selected, allowing for easy switching between queue infrastructures in the future.
It means that queue configurations become the responsibility of the queue adapter and not ActiveJob itself. Hence, ActiveJob allows for priority levels to be set if the queue adapter supports it.
While this works great in building queueing systems, it often hinders writing tests for ActiveJob. However, the Rails team is working towards unifying that!
Before
When writing ActiveJob tests,
only minimal configurations were testable,
such as the time to queue
and queue name
.
It was not possible to write tests for jobs
that make use of the priority
parameter.
test "job is enqueued" do
assert_enqueued_with job: SampleJob, args: @user, priority: 5 do
SampleJob.perform_later(@user)
end
end
It would throw a parameter priority not found
error.
After
With Rails 7, we now can test with the priority parameter for both assert_enqueued_with and assert_performed_with test helper methods.
test "job is enqueued" do
assert_enqueued_with(job: SampleJob, priority: 10) do
SampleJob.perform_later(@user)
end
end
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK