Ruby version: 2.4.0
Sidekiq / Pro / Enterprise version(s): Sidekiq versions 4.2.10 & 5.0.2
Sorry in advance for a rather long description, but I haven't been able to generate a reproducible script to demonstrate this bug, and I don't think I'm allowed to share our code publicly...
So, we have a feature test that looks like the following
it 'updates all of the associated data' do
Sidekiq::Testing.inline! do
visit line_item_path(line_item)
click_on 'Update'
fill_in 'line_item[lines]', with: 2
fill_in 'line_item[bandwidth]', with: 10
fill_in 'line_item[cost]', with: 50_000
fill_in 'line_item[note]', with: 'Updating line item!'
click_on 'Update'
end
# assertions here
end
When I run that file on its own in RSpec (by running bundle exec rspec spec/features/feature_spec.rb), everything behaves correctly. Similarly, when I run all feature specs (by running bundle exec rspec spec/features), everything behaves correctly. However, when I run the entire suite (by running bundle exec rspec), the block isn't executed. I've confirmed this by putting a call to byebug inside the block to be executed, and when run in the context of the entire test suite, that block is never hit. When running just the file individually or all feature specs together, that debugger entry point is hit without problem.
Also, to make things even more weird, we have other tests in that same spec that use Sidekiq::Testing.inline! with a block, and those blocks are all executed without issue when we run the whole suite. It's just this one unlucky block.
This only became an issue when we upgraded to Rails 5.1. When we started that upgrade we were still on 4.2.10, but this behavior still appears on 5.0.2. If it helps, we're also using RSpec 3.6.0.
I'd be happy to provide any further information that you might need. Also, I'm not sure if your happy hour is really the right time for such things, but I think I could chat with you about this bug further during that time if it would be helpful to you.
No clue. inline! always calls its block so that behavior shouldn't be possible.
We ended up just refactoring our tests since we couldn't find why that was happening... Probably for the best, anyway 馃槈
@mperham Strange thing that this happens on our project too. When run all specs normally in default order everything works fine, but with random order one spec with inline! block fails.
When I manually call worker inside inline! block, it returns nil and doesn't execute.
Do you maybe have any idea what could be the issue? Any hint?
Regards
Had this same issue, discovered that one of my specs calls ActiveJob::Base.queue_adapter = :test. Calling Sidekiq::Testing.inline! will have no effect if this spec runs before it.
One solution is to change the adapter back after the spec in question, eg:
around do |example|
current_adapter = ActiveJob::Base.queue_adapter
ActiveJob::Base.queue_adapter = :test
example.run
ActiveJob::Base.queue_adapter = current_adapter
end
I hit this problem today, and I found that it was caused by the sidekiq-unique-jobs gem. I removed that gem from Gemfile and the job was run inline successfully.
We've been having the same issue. I think (hasn't failed for a while since) I was able to solve it by adding:
# From https://makandracards.com/makandra/28125-perform-sidekiq-jobs-immediately-in-development
# Perform jobs immediately
config.active_job.queue_adapter = :sidekiq
require "sidekiq/testing"
Sidekiq::Testing.inline! # NOTE: see https://github.com/mperham/sidekiq/wiki/Testing
to config/environments/test.rb and never change it. Previously we used fake! as the implicit default and run certain tests in Sidekiq::Testing.inline! {} just as @devonestes.
Most helpful comment
Had this same issue, discovered that one of my specs calls
ActiveJob::Base.queue_adapter = :test. CallingSidekiq::Testing.inline!will have no effect if this spec runs before it.One solution is to change the adapter back after the spec in question, eg: