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

82 lines
2.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-10-06 15:43:01 -04:00
require_relative 'helper'
require 'sidekiq/launcher'
class TestLauncher < Sidekiq::Test
describe 'launcher' do
before do
Sidekiq.redis {|c| c.flushdb }
end
def new_manager(opts)
2015-10-08 12:37:37 -04:00
Sidekiq::Manager.new(opts)
2015-10-06 15:43:01 -04:00
end
describe 'heartbeat' do
before do
uow = Object.new
@mgr = new_manager(options)
@launcher = Sidekiq::Launcher.new(options)
@launcher.manager = @mgr
2015-10-07 18:01:44 -04:00
Sidekiq::Processor::WORKER_STATE['a'] = {'b' => 1}
2015-10-06 15:43:01 -04:00
@proctitle = $0
end
after do
2015-10-07 18:01:44 -04:00
Sidekiq::Processor::WORKER_STATE.clear
2015-10-06 15:43:01 -04:00
$0 = @proctitle
end
describe 'when manager is active' do
before do
Sidekiq::CLI::PROCTITLES << proc { "xyz" }
2015-10-06 15:43:01 -04:00
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
Sidekiq::CLI::PROCTITLES.pop
2015-10-06 15:43:01 -04:00
end
it 'sets useful info to proctitle' do
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] xyz", $0
end
it 'stores process info in redis' do
info = Sidekiq.redis { |c| c.hmget('identity', 'busy') }
assert_equal ["1"], info
expires = Sidekiq.redis { |c| c.pttl('identity') }
assert_in_delta 60000, expires, 500
end
end
describe 'when manager is stopped' do
before do
@launcher.quiet
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
end
it 'indicates stopping status in proctitle' do
2015-10-07 18:01:44 -04:00
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] stopping", $0
2015-10-06 15:43:01 -04:00
end
it 'stores process info in redis' do
info = Sidekiq.redis { |c| c.hmget('identity', 'busy') }
2015-10-07 18:01:44 -04:00
assert_equal ["1"], info
2015-10-06 15:43:01 -04:00
expires = Sidekiq.redis { |c| c.pttl('identity') }
assert_in_delta 60000, expires, 50
end
end
end
def options
{ :concurrency => 3, :queues => ['default'] }
end
def heartbeat_data
{ 'concurrency' => 3, 'tag' => 'myapp' }
end
end
end