* Refactor CLI test
Extracted 3 main parts:
- parse
- run
- signal handling
* Move demonization and pid write from parse to run phase
* Move queues default from validate to setup options phase
* Add pry-byebug gem
* Drop Sidekiq::Test
* Require launcher in CLI
* Remove TODOs
Trying to emulate the real behavior, the job obtains an enqueued_at
attribute when it's placed in a queue.
Since using perform_in or perform_at does not put the job in the queue
when run, the attribute is not set for those methods.
The queue-based testing hash (@jobs_by_queue) stores the queue name as a string. Therefore, when a worker is given a symbol as queue name, deleting the job from the @jobs_by_queue silently fails, leaving the job in @jobs_by_queue (even though deleting succeded from the @jobs_by_worker). Sidekiq::Worker.drain_all gets the jobs through @jobs_by_queue, but since the josb are not removed after execution, calling drain_all will result in an endless loop.
When using the Sidekiq::Client API to push jobs on to the queue, it's
not ideal to assert the size of the queue from the perspective of a
worker because the worker may not exist in the application.
This API implements a testing API from the perspective of a queue. The
existing Worker-based testing API remains unchanged, but leverages the
job hash implemented through the Sidekiq::Queues class.
Examples:
assert_equal 1, Sidekiq::Queues["default"].size
assert_equal "SpecialWorker", Sidekiq::Queues["default"].first["class"]
Sidekiq::Queues["default"].clear
Sidekiq::Queues.clear_all
In addition to requiring 'sidekiq/testing' and 'sidekiq/testing/inline',
a user can also call the following methods to control the test harness:
Sidekiq::Testing.fake!
Sidekiq::Testing.inline!
Sidekiq::Testing.disable!
Each of the above methods also accepts a block to execute within that
context before reverting to the state present before method invocation.
To query the current state, use the following methods:
Sidekiq::Testing.enabled?
Sidekiq::Testing.disabled?
Sidekiq::Testing.fake?
Sidekiq::Testing.inline?
Closes#1053