2013-05-10 23:43:53 -04:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq/manager'
|
2014-04-13 18:30:25 -04:00
|
|
|
require 'sidekiq/util'
|
2013-05-10 23:43:53 -04:00
|
|
|
|
2013-09-22 17:38:33 -04:00
|
|
|
class TestManager < Sidekiq::Test
|
2013-05-10 23:43:53 -04:00
|
|
|
|
|
|
|
describe 'manager' do
|
|
|
|
it 'creates N processor instances' do
|
|
|
|
mgr = Sidekiq::Manager.new(options)
|
|
|
|
assert_equal options[:concurrency], mgr.ready.size
|
|
|
|
assert_equal [], mgr.busy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns work to a processor' do
|
2013-12-10 18:33:53 -05:00
|
|
|
uow = Object.new
|
2013-05-12 17:25:30 -04:00
|
|
|
processor = Minitest::Mock.new
|
2013-05-10 23:43:53 -04:00
|
|
|
processor.expect(:async, processor, [])
|
|
|
|
processor.expect(:process, nil, [uow])
|
|
|
|
|
|
|
|
mgr = Sidekiq::Manager.new(options)
|
|
|
|
mgr.ready << processor
|
|
|
|
mgr.assign(uow)
|
|
|
|
assert_equal 1, mgr.busy.size
|
|
|
|
|
|
|
|
processor.verify
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requeues work if stopping' do
|
2013-05-12 17:25:30 -04:00
|
|
|
uow = Minitest::Mock.new
|
2013-05-10 23:43:53 -04:00
|
|
|
uow.expect(:requeue, nil, [])
|
|
|
|
|
|
|
|
mgr = Sidekiq::Manager.new(options)
|
2013-11-21 06:09:30 -05:00
|
|
|
mgr.fetcher = Sidekiq::BasicFetch.new({:queues => []})
|
2013-05-10 23:43:53 -04:00
|
|
|
mgr.stop
|
|
|
|
mgr.assign(uow)
|
|
|
|
uow.verify
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shuts down the system' do
|
|
|
|
mgr = Sidekiq::Manager.new(options)
|
2013-11-21 06:09:30 -05:00
|
|
|
mgr.fetcher = Sidekiq::BasicFetch.new({:queues => []})
|
2013-05-10 23:43:53 -04:00
|
|
|
mgr.stop
|
|
|
|
|
|
|
|
assert mgr.busy.empty?
|
|
|
|
assert mgr.ready.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns finished processors to the ready pool' do
|
2013-09-22 17:05:29 -04:00
|
|
|
fetcher = MiniTest::Mock.new
|
|
|
|
fetcher.expect :async, fetcher, []
|
|
|
|
fetcher.expect :fetch, nil, []
|
2013-05-10 23:43:53 -04:00
|
|
|
mgr = Sidekiq::Manager.new(options)
|
2013-09-22 17:05:29 -04:00
|
|
|
mgr.fetcher = fetcher
|
2013-05-10 23:43:53 -04:00
|
|
|
init_size = mgr.ready.size
|
|
|
|
processor = mgr.ready.pop
|
|
|
|
mgr.busy << processor
|
|
|
|
mgr.processor_done(processor)
|
|
|
|
|
|
|
|
assert_equal 0, mgr.busy.size
|
|
|
|
assert_equal init_size, mgr.ready.size
|
2013-09-22 17:05:29 -04:00
|
|
|
fetcher.verify
|
2013-05-10 23:43:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'throws away dead processors' do
|
2013-09-22 17:05:29 -04:00
|
|
|
fetcher = MiniTest::Mock.new
|
|
|
|
fetcher.expect :async, fetcher, []
|
|
|
|
fetcher.expect :fetch, nil, []
|
2013-05-10 23:43:53 -04:00
|
|
|
mgr = Sidekiq::Manager.new(options)
|
2013-09-22 17:05:29 -04:00
|
|
|
mgr.fetcher = fetcher
|
2013-05-10 23:43:53 -04:00
|
|
|
init_size = mgr.ready.size
|
|
|
|
processor = mgr.ready.pop
|
|
|
|
mgr.busy << processor
|
|
|
|
mgr.processor_died(processor, 'ignored')
|
|
|
|
|
|
|
|
assert_equal 0, mgr.busy.size
|
|
|
|
assert_equal init_size, mgr.ready.size
|
|
|
|
refute mgr.ready.include?(processor)
|
2013-09-22 17:05:29 -04:00
|
|
|
fetcher.verify
|
2013-05-10 23:43:53 -04:00
|
|
|
end
|
|
|
|
|
2014-04-13 18:30:25 -04:00
|
|
|
describe 'heartbeat' do
|
|
|
|
describe 'proctitle' do
|
|
|
|
it 'sets useful info' do
|
|
|
|
mgr = Sidekiq::Manager.new(options)
|
|
|
|
mgr.heartbeat('identity', heartbeat_data)
|
|
|
|
|
|
|
|
proctitle = $0
|
|
|
|
assert_equal $0, "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy]"
|
|
|
|
$0 = proctitle
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'indicates when stopped' do
|
|
|
|
mgr = Sidekiq::Manager.new(options)
|
|
|
|
mgr.stop
|
|
|
|
mgr.heartbeat('identity', heartbeat_data)
|
|
|
|
|
|
|
|
proctitle = $0
|
|
|
|
assert_equal $0, "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy] stopping"
|
|
|
|
$0 = proctitle
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-10 23:43:53 -04:00
|
|
|
def options
|
|
|
|
{ :concurrency => 3, :queues => ['default'] }
|
|
|
|
end
|
2014-04-13 18:30:25 -04:00
|
|
|
|
|
|
|
def heartbeat_data
|
|
|
|
{ 'concurrency' => 3, 'tag' => 'myapp' }
|
|
|
|
end
|
2013-05-10 23:43:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|