2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
2014-12-30 15:54:58 -05:00
|
|
|
require_relative 'helper'
|
2013-05-10 23:43:53 -04:00
|
|
|
require 'sidekiq/manager'
|
|
|
|
|
2013-09-22 17:38:33 -04:00
|
|
|
class TestManager < Sidekiq::Test
|
2013-05-10 23:43:53 -04:00
|
|
|
|
|
|
|
describe 'manager' do
|
2014-04-14 06:30:59 -04:00
|
|
|
before do
|
|
|
|
Sidekiq.redis {|c| c.flushdb }
|
|
|
|
end
|
|
|
|
|
2014-11-18 13:50:42 -05:00
|
|
|
def new_manager(opts)
|
2015-10-08 12:37:37 -04:00
|
|
|
Sidekiq::Manager.new(opts)
|
2014-11-18 13:50:42 -05:00
|
|
|
end
|
|
|
|
|
2013-05-10 23:43:53 -04:00
|
|
|
it 'creates N processor instances' do
|
2014-11-18 13:50:42 -05:00
|
|
|
mgr = new_manager(options)
|
2015-10-08 12:37:37 -04:00
|
|
|
assert_equal options[:concurrency], mgr.workers.size
|
2013-05-10 23:43:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shuts down the system' do
|
2014-11-18 13:50:42 -05:00
|
|
|
mgr = new_manager(options)
|
2015-10-06 15:43:01 -04:00
|
|
|
mgr.stop(Time.now)
|
2013-05-10 23:43:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'throws away dead processors' do
|
2014-11-18 13:50:42 -05:00
|
|
|
mgr = new_manager(options)
|
2015-10-08 12:37:37 -04:00
|
|
|
init_size = mgr.workers.size
|
|
|
|
processor = mgr.workers.first
|
2015-10-21 12:29:58 -04:00
|
|
|
begin
|
|
|
|
mgr.processor_died(processor, 'ignored')
|
|
|
|
|
|
|
|
assert_equal init_size, mgr.workers.size
|
|
|
|
refute mgr.workers.include?(processor)
|
|
|
|
ensure
|
|
|
|
mgr.workers.each {|p| p.terminate(true) }
|
|
|
|
end
|
2015-08-12 13:16:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not support invalid concurrency' do
|
|
|
|
assert_raises(ArgumentError) { new_manager(concurrency: 0) }
|
|
|
|
assert_raises(ArgumentError) { new_manager(concurrency: -1) }
|
2013-05-10 23:43:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def options
|
|
|
|
{ :concurrency => 3, :queues => ['default'] }
|
|
|
|
end
|
2014-04-13 18:30:25 -04:00
|
|
|
|
2013-05-10 23:43:53 -04:00
|
|
|
end
|
|
|
|
end
|