mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Do not stop heartbeat even when manager is already stopped
* Heartbeat should never stop (discussion: ba8c8a57b9 (commitcomment-5996837)
)
* Test that heartbeat stores data in Redis with ttl
This commit is contained in:
parent
473de4da8f
commit
bd59becebd
2 changed files with 52 additions and 13 deletions
|
@ -139,8 +139,6 @@ module Sidekiq
|
|||
proctitle << 'stopping' if stopped?
|
||||
$0 = proctitle.join(' ')
|
||||
|
||||
return if stopped?
|
||||
|
||||
❤(key)
|
||||
after(5) do
|
||||
heartbeat(key, data)
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
require 'helper'
|
||||
require 'sidekiq/manager'
|
||||
require 'sidekiq/util'
|
||||
|
||||
class TestManager < Sidekiq::Test
|
||||
|
||||
describe 'manager' do
|
||||
before do
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
it 'creates N processor instances' do
|
||||
mgr = Sidekiq::Manager.new(options)
|
||||
assert_equal options[:concurrency], mgr.ready.size
|
||||
|
@ -79,25 +82,63 @@ class TestManager < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe 'heartbeat' do
|
||||
describe 'proctitle' do
|
||||
it 'sets useful info' do
|
||||
mgr = Sidekiq::Manager.new(options)
|
||||
mgr.heartbeat('identity', heartbeat_data)
|
||||
before do
|
||||
uow = Object.new
|
||||
|
||||
@processor = Minitest::Mock.new
|
||||
@processor.expect(:async, @processor, [])
|
||||
@processor.expect(:process, nil, [uow])
|
||||
|
||||
@mgr = Sidekiq::Manager.new(options)
|
||||
@mgr.ready << @processor
|
||||
@mgr.assign(uow)
|
||||
|
||||
@processor.verify
|
||||
end
|
||||
|
||||
describe 'when manager is active' do
|
||||
before do
|
||||
@mgr.heartbeat('identity', heartbeat_data)
|
||||
end
|
||||
|
||||
it 'sets useful info to proctitle' do
|
||||
proctitle = $0
|
||||
assert_equal $0, "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy]"
|
||||
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy]", $0
|
||||
$0 = proctitle
|
||||
end
|
||||
|
||||
it 'indicates when stopped' do
|
||||
mgr = Sidekiq::Manager.new(options)
|
||||
mgr.stop
|
||||
mgr.heartbeat('identity', heartbeat_data)
|
||||
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, 1
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when manager is stopped' do
|
||||
before do
|
||||
@processor.expect(:alive?, [])
|
||||
@processor.expect(:terminate, [])
|
||||
|
||||
@mgr.stop
|
||||
@mgr.processor_done(@processor)
|
||||
@mgr.heartbeat('identity', heartbeat_data)
|
||||
|
||||
@processor.verify
|
||||
end
|
||||
|
||||
it 'indicates status in proctitle' do
|
||||
proctitle = $0
|
||||
assert_equal $0, "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy] stopping"
|
||||
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [0 of 3 busy] stopping", $0
|
||||
$0 = proctitle
|
||||
end
|
||||
|
||||
it 'stores process info in redis' do
|
||||
info = Sidekiq.redis { |c| c.hmget('identity', 'busy') }
|
||||
assert_equal ["0"], info
|
||||
expires = Sidekiq.redis { |c| c.pttl('identity') }
|
||||
assert_in_delta 60000, expires, 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue