Sha256: dab59c5c451da330d60b06d9dc8256975d06949b7f5c2b204608eb6eac53ed50
Contents?: true
Size: 1.96 KB
Versions: 6
Compression:
Stored size: 1.96 KB
Contents
RSpec.describe WorkerKiller do let(:logger){ Logger.new(nil) } let(:config) do WorkerKiller::Configuration.new.tap do |c| c.quit_attempts = 2 c.kill_attempts = 2 end end before do WorkerKiller.instance_variable_set('@kill_attempts', nil) end describe '#randomize' do [1, 5, 25, 125, 5000, 10_000].each do |max| it "randomize(#{max})" do 1000.times do rnd = WorkerKiller.randomize(max) expect(rnd).to be >= 0 expect(rnd).to be < max end end end end describe '#kill_self' do context 'with use_quit TRUE' do around do |example| prev = WorkerKiller.configuration config.use_quit = true WorkerKiller.configuration = config example.run ensure WorkerKiller.configuration = prev end it 'expect right signal order' do expect(Process).to receive(:kill).with(:QUIT, anything).exactly(2).times expect(Process).to receive(:kill).with(:TERM, anything).exactly(2).times expect(Process).to receive(:kill).with(:KILL, anything).exactly(5).times 2.times { WorkerKiller.kill_self(logger, Time.now) } # 2 QUIT 2.times { WorkerKiller.kill_self(logger, Time.now) } # 2 TERM 5.times { WorkerKiller.kill_self(logger, Time.now) } # other - KILL end end context 'with use_quit FALSE' do around do |example| prev = WorkerKiller.configuration config.use_quit = false WorkerKiller.configuration = config example.run ensure WorkerKiller.configuration = prev end it 'expect right signal order' do expect(Process).to receive(:kill).with(:TERM, anything).exactly(2).times expect(Process).to receive(:kill).with(:KILL, anything).exactly(5).times 2.times { WorkerKiller.kill_self(logger, Time.now) } # 2 TERM 5.times { WorkerKiller.kill_self(logger, Time.now) } # other - KILL end end end end
Version data entries
6 entries across 6 versions & 1 rubygems