Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Oct 7, 2015
1 parent 752bfc6 commit 89a1914
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
23 changes: 5 additions & 18 deletions test/test_launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -58,23 +51,17 @@ def new_manager(opts)

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
Expand Down
10 changes: 4 additions & 6 deletions test/test_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ def successful_job
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

Expand All @@ -191,10 +190,9 @@ def failed_job
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
Expand Down

0 comments on commit 89a1914

Please sign in to comment.