-
-
Notifications
You must be signed in to change notification settings - Fork 282
Description
Problem
Problem is with unclosed sidekiq testing blocks in Rspec.
Explanation
By default Sidekiq testing block is fake and we have configure it explicitly in spec helper as well. Everything is going good, unless someone in other spec file write a test with unclosed
testing block in Disable! mode. With this the mode will be set across the files unless someone explicitly changes it to fake or other mode.
Since disable mode enqueues job to Redis it will start failing when we run spec for the project , for the test cases where someone is not testing anything under the fake! block as it is presumed that it has been set as default
Solution
We raise offense when someone keeps a testing block open.
Bad code:
Sidekiq::Testing.inline!
3.times { Sidekiq::RandomWorker.enqueue }
Good Code:
Sidekiq::Testing.disable! do
3.times { Sidekiq::GlobalWorker.enqueue }
end
Approach to fix
I have fixed this problem for our repo by allowing the ast to pass if the souce line ends with do else raise a block.
We can make this configurable as well by setting something like:
allow_unclsoed_sidekiq_testing_blocks: true/false
If the issue gets feature-request tag i am willing to raise a PR to get this feature. ❤️