-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Assert cancelled jobs #724
Comments
@jofrly thanks for opening the issue. I'm happy to help. First, if you're using If you wanted to use GoodJob in your tests, you would use something like this: # "external" execution mode will store the records but not execute them
ActiveJob::Base.queue_adapter = GoodJob::Adapter.new(execution_mode: :external)
# "inline" will execute them immediately
ActiveJob::Base.queue_adapter = GoodJob::Adapter.new(execution_mode: :inline) Second, I want to suggest a safer way to cancel jobs: job = GoodJob::Job.find_by(active_job_id: job_id)
job.discard_job("Canceled the job because it's no longer needed") |
@bensheldon thanks so much for answering so quickly! The I noticed I was on I created a job My assumption is to see a
So I'm not quite sure what I'm doing wrong. Could you take a look at my repo? |
@jofrly aha! I think you are experiencing Rail's very aggressive ActiveJob test adapter: rails/rails#37270 In your test, if you output You need to do something like this in your Job setup (I'm not sure what the minitest equivalent is): good_job/spec/support/reset_rails_queue_adapter.rb Lines 2 to 7 in 3eb8f18
|
@bensheldon yes! logging class MyTest < ActionDispatch::IntegrationTest
setup do
descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
descendants.each(&:disable_test_adapter)
end
... and now everything works as expected. Thanks so much for helping me. Coffee is on me :) |
Hi!
My application schedules jobs and utilizes the
.set(wait: ...
alot.Sometimes, I cancel jobs when certain events occur in the application.
I do that by destroying the record in the
good_jobs
table.My application grows in complexity so I want to introduce some tests.
I'd like to test one part of the application where a job gets cancelled like explained above.
However the
assert_enqueued_jobs
helper does not "respect" the cancelled jobs.Is there another way to assert enqueued jobs?
I tried to query them like this
However that always returns 0 in the test environment somehow.
Scheduling, cancelling and querying them in the way I mentioned works fine in other environments though...
Thankful for any help / advice.
The text was updated successfully, but these errors were encountered: