-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing jobs synchronously #435
Comments
@christianrolle always making progress on this gem 😄 You'll want to assign the entire around do |example
original_adapter = ActiveJob::Base.queue_adapter
good_job_adapter = GoodJob::Adapter.new(execution_mode: :inline)
ActiveJob::Base.queue_adapter = good_job_adapter
example.run
good_job_adapter.shutdown
ActiveJob::Base.queue_adapter = original_adapter
end Also, fyi there are some versions of Rails/Rspec that may override the adapter, but I think the above should be fairly bulletproof. Edit: added |
@christianrolle Isn't the AJ adapter set to test one? https://github.com/rails/rails/blob/main/activejob/lib/active_job/queue_adapters/test_adapter.rb I believe that's the best way of testing and you can perform jobs by using https://edgeapi.rubyonrails.org/classes/ActiveJob/TestHelper.html#method-i-perform_enqueued_jobs What's your usecase to use Good Job in tests? |
@morgoth your're right. We should expect GoodJob to be tested properly. So for for test outcome (testing the systems behavior) it shouldn't matter which AJ job adapter we use. |
Stumbled across this way of switching off asynchronicity:
and then:
|
The progres this gem makes is amazing! 🚀
For integration tests I want to have expectations no matter how the job is run (synchronously or asynchronously).
How to enforce running the enqueued job right away? I tried with:
for something like:
The job isn't performed even though the execution mode is
:inline
.Don't get me wrong. The job implementation works and in the unit test I just execute the job by
#perform_now
. But I'd rather like to test its result in the integration test.Do I misunderstand the mode?
Is there a better approach for running the jobs immediately (synchronously)?
The text was updated successfully, but these errors were encountered: