mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Merge pull request #2745 from ckersh/test_coverage_handle_signal
Improve test coverage for handling signals
This commit is contained in:
commit
c131c1f55d
1 changed files with 80 additions and 10 deletions
|
@ -309,18 +309,88 @@ class TestCli < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe 'misc' do
|
||||
it 'handles interrupts' do
|
||||
cli = Sidekiq::CLI.new
|
||||
assert_raises Interrupt do
|
||||
cli.handle_signal('INT')
|
||||
end
|
||||
assert_raises Interrupt do
|
||||
cli.handle_signal('TERM')
|
||||
end
|
||||
cli.handle_signal('USR2')
|
||||
cli.handle_signal('TTIN')
|
||||
before do
|
||||
@cli = Sidekiq::CLI.new
|
||||
end
|
||||
|
||||
it 'handles interrupts' do
|
||||
assert_raises Interrupt do
|
||||
@cli.handle_signal('INT')
|
||||
end
|
||||
assert_raises Interrupt do
|
||||
@cli.handle_signal('TERM')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'handles USR1 and USR2' do
|
||||
before do
|
||||
@tmp_log_path = '/tmp/sidekiq.log'
|
||||
@cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
|
||||
end
|
||||
|
||||
after do
|
||||
File.unlink @tmp_log_path if File.exists? @tmp_log_path
|
||||
end
|
||||
|
||||
it 'shuts down the worker' do
|
||||
count = 0
|
||||
Sidekiq.options[:lifecycle_events][:quiet] = [proc {
|
||||
count += 1
|
||||
}]
|
||||
@cli.launcher = Sidekiq::Launcher.new(Sidekiq.options)
|
||||
@cli.handle_signal('USR1')
|
||||
|
||||
assert_equal 1, count
|
||||
end
|
||||
|
||||
it 'reopens logs' do
|
||||
mock = MiniTest::Mock.new
|
||||
# reopen_logs returns number of files reopened so mock that
|
||||
mock.expect(:call, 1)
|
||||
|
||||
Sidekiq::Logging.stub(:reopen_logs, mock) do
|
||||
@cli.handle_signal('USR2')
|
||||
end
|
||||
mock.verify
|
||||
end
|
||||
end
|
||||
|
||||
describe 'handles TTIN' do
|
||||
before do
|
||||
@tmp_log_path = '/tmp/sidekiq.log'
|
||||
@cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
|
||||
@mock_thread = MiniTest::Mock.new
|
||||
@mock_thread.expect(:[], 'interrupt_test', ['label'])
|
||||
end
|
||||
|
||||
after do
|
||||
File.unlink @tmp_log_path if File.exists? @tmp_log_path
|
||||
end
|
||||
|
||||
describe 'with backtrace' do
|
||||
it 'logs backtrace' do
|
||||
2.times { @mock_thread.expect(:backtrace, ['something went wrong']) }
|
||||
|
||||
Thread.stub(:list, [@mock_thread]) do
|
||||
@cli.handle_signal('TTIN')
|
||||
assert_match(/something went wrong/, File.read(@tmp_log_path), "didn't include the log message")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'without backtrace' do
|
||||
it 'logs no backtrace available' do
|
||||
@mock_thread.expect(:backtrace, nil)
|
||||
|
||||
Thread.stub(:list, [@mock_thread]) do
|
||||
@cli.handle_signal('TTIN')
|
||||
assert_match(/no backtrace available/, File.read(@tmp_log_path), "didn't include the log message")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
it 'can fire events' do
|
||||
count = 0
|
||||
Sidekiq.options[:lifecycle_events][:startup] = [proc {
|
||||
|
|
Loading…
Reference in a new issue