1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Fixed drain_all for workers with symbolized queue names in tests

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.
This commit is contained in:
Martin Sereinig 2016-01-14 15:25:03 +01:00
parent 4d6133f87a
commit ede0cdb56b
2 changed files with 11 additions and 1 deletions

View file

@ -170,7 +170,7 @@ module Sidekiq
end
def delete_for(jid, queue, klass)
jobs_by_queue[queue].delete_if { |job| job["jid"] == jid }
jobs_by_queue[queue.to_s].delete_if { |job| job["jid"] == jid }
jobs_by_worker[klass].delete_if { |job| job["jid"] == jid }
end

View file

@ -261,6 +261,16 @@ class TestTesting < Sidekiq::Test
assert_equal 1, SecondWorker.count
end
it 'drains jobs of workers with symbolized queue names' do
Sidekiq::Worker.jobs.clear
AltQueueWorker.perform_async(5,6)
assert_equal 1, AltQueueWorker.jobs.size
Sidekiq::Worker.drain_all
assert_equal 0, AltQueueWorker.jobs.size
end
it 'can execute a job' do
DirectWorker.execute_job(DirectWorker.new, [2, 3])
end