-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[ActiveJob] test adapter is override by self.enque_adapter = :sidekiq #26360
Comments
I tried to reproduce the issue but could not. See reproduction script here ~ https://gist.github.com/prathamesh-sonpatki/4dd96cee548758bf63fd37004d6404a0. Can you upload a sample application on Github that reproduces the issue? Thanks. |
@zw963 You can solve this issue by providing custom adapter for the test class by using For eg. class JobTest < ActiveJob::TestCase
def queue_adapter_for_test
ActiveJob::QueueAdapters::SidekiqAdapter
end
end You can check more documentation about this method here - http://api.rubyonrails.org/classes/ActiveJob/TestHelper.html#method-i-queue_adapter_for_test. I am giving it a close as we already have a solution. Thanks! |
I could not too, but this is not the same case as my.
Sorry not worked for me. # Running:
DEPRECATION WARNING: Passing an adapter class is deprecated and will be removed in Rails 5.1. Please pass an adapter name (.queue_adapter = :sidekiq) or an instance (.queue_adapter = ActiveJob::QueueAdapters::SidekiqAdapter.new) instead. (called from <top (required)> at /home/zw963/Xthink/ershou_web/bin/rails:9)
E
Error:
BidGoodsItemExpiredJobTest#test_in_queue:
NoMethodError: undefined method `enqueued_jobs' for #<ActiveJob::QueueAdapters::SidekiqAdapter:0x000000037cc6f0>
Error:
BidGoodsItemExpiredJobTest#test_in_queue:
NoMethodError: undefined method `each' for nil:NilClass I change to following: class JobTest < ActiveJob::TestCase
def queue_adapter_for_test
ActiveJob::QueueAdapters::SidekiqAdapter
end
end DEPRECATION WARNING is gone, but still got following error. Error:
BidGoodsItemExpiredJobTest#test_: when no one biding should change to no_dealt. :
NoMethodError: undefined method `enqueued_jobs' for #<ActiveJob::QueueAdapters::SidekiqAdapter:0x0000000375f708>
Error:
BidGoodsItemExpiredJobTest#test_: when no one biding should change to no_dealt. :
NoMethodError: undefined method `each' for nil:NilClass here is my job file: https://gist.github.com/208385fb2e6f53ef107509cc58073d68 Thanks. |
I will take a look today, thanks for the explanation. |
The `ActiveJob::TestHelper` replace the adapter to test adapter in `before_setup`. It gets the target class using the `descendants`, but if the test target job class is not loaded, will not be a replacement of the adapter. Therefore, instead of replacing with `before_setup`, modified to replace when setting adapter. Fixes rails#26360
…job (#26690) The `ActiveJob::TestHelper` replace the adapter to test adapter in `before_setup`. It gets the target class using the `descendants`, but if the test target job class is not loaded, will not be a replacement of the adapter. Therefore, instead of replacing with `before_setup`, modified to replace when setting adapter. Fixes #26360
Thank all! |
Steps to reproduce
This will result in following test code not work.
We must change job code to following to make test work.
It weired, spent me hours to found out test use
ActiveJob::QueueAdapters::TestAdapter
to make test work.Expected behavior
self.queue_adapter = :sidekiq in job should not change the default
test adapter ... it only test enque, not test enque to sidekiq.
System configuration
Rails 5.0.0
Ruby 2.2.4
The text was updated successfully, but these errors were encountered: