Module: Wurk::Swarm::TestModeGuard
- Defined in:
- lib/wurk/swarm/test_mode_guard.rb
Overview
A worker in Sidekiq::Testing's fake or inline mode enqueues nothing: every job its jobs and cron ticks push lands in an in-memory array and is gone. The usual cause is rspec-sidekiq outside the Gemfile's test group, which turns fake mode on as it loads, and the swarm's Bundler.require of the default group is what loads it. Stock Sidekiq drops those jobs without a word; a worker has no reason to run in a test mode, so this puts it back and says so.
Except in a test environment. disable! is process-global, and a suite that
boots Embedded or the CLI in-process would lose fake mode for every test after.
Class Method Summary collapse
Class Method Details
.enforce!(logger) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/wurk/swarm/test_mode_guard.rb', line 17 def enforce!(logger) return if Testing.disabled? || test_environment? mode = Testing.mode Testing.disable! logger.error do "Sidekiq::Testing was in #{mode} mode in a worker process, where it would silently drop every " \ 'enqueue. Disabled it for this process. Move the gem or code that enables it (usually ' \ 'rspec-sidekiq) to the test group of your Gemfile.' end end |
.test_environment? ⇒ Boolean
29 |
# File 'lib/wurk/swarm/test_mode_guard.rb', line 29 def test_environment? = ENV['RAILS_ENV'] == 'test' || ENV['RACK_ENV'] == 'test' |