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

Fix tests

This commit is contained in:
Mike Perham 2015-10-07 15:01:44 -07:00
parent 752bfc6d8b
commit 89a1914d45
2 changed files with 9 additions and 24 deletions

View file

@ -9,31 +9,24 @@ class TestLauncher < Sidekiq::Test
end
def new_manager(opts)
condvar = Minitest::Mock.new
condvar.expect(:signal, nil, [])
Sidekiq::Manager.new(condvar, opts)
Sidekiq::Manager.new(nil, opts)
end
describe 'heartbeat' do
before do
uow = Object.new
@processor = Minitest::Mock.new
@processor.expect(:request_process, nil, [uow])
@processor.expect(:hash, 1234, [])
@mgr = new_manager(options)
@launcher = Sidekiq::Launcher.new(options)
@launcher.manager = @mgr
@mgr.ready << @processor
@mgr.assign(uow)
Sidekiq::Processor::WORKER_STATE['a'] = {'b' => 1}
@processor.verify
@proctitle = $0
end
after do
Sidekiq::Processor::WORKER_STATE.clear
$0 = @proctitle
end
@ -58,23 +51,17 @@ class TestLauncher < Sidekiq::Test
describe 'when manager is stopped' do
before do
@processor.expect(:hash, 1234, [])
@processor.expect(:terminate, [])
@launcher.quiet
@launcher.manager.processor_done(@processor)
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
@processor.verify
end
it 'indicates stopping status in proctitle' do
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy] stopping", $0
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] stopping", $0
end
it 'stores process info in redis' do
info = Sidekiq.redis { |c| c.hmget('identity', 'busy') }
assert_equal ["0"], info
assert_equal ["1"], info
expires = Sidekiq.redis { |c| c.pttl('identity') }
assert_in_delta 60000, expires, 50
end

View file

@ -172,10 +172,9 @@ class TestProcessor < Sidekiq::Test
end
it 'increments processed stat' do
assert_equal 0, Sidekiq::Stats.new.processed
Sidekiq::Processor::PROCESSED.value = 0
successful_job
assert_equal 1, Sidekiq::Stats.new.processed
assert_equal Sidekiq::Processor::STATS_TIMEOUT, Sidekiq.redis { |conn| conn.ttl(processed_today_key) }
assert_equal 1, Sidekiq::Processor::PROCESSED.value
end
end
@ -191,10 +190,9 @@ class TestProcessor < Sidekiq::Test
end
it 'increments failed stat' do
assert_equal 0, Sidekiq::Stats.new.failed
Sidekiq::Processor::FAILURE.value = 0
failed_job
assert_equal 1, Sidekiq::Stats.new.failed
assert_equal Sidekiq::Processor::STATS_TIMEOUT, Sidekiq.redis { |conn| conn.ttl(failed_today_key) }
assert_equal 1, Sidekiq::Processor::FAILURE.value
end
end
end