Commit 240bfbdd authored by Craig Miskell's avatar Craig Miskell Committed by Sean McGivern

Fix bug with monotonic_time, updates for style in tests

Per feedback on MR
parent afe208aa
...@@ -68,17 +68,21 @@ module Gitlab ...@@ -68,17 +68,21 @@ module Gitlab
SidekiqCluster.write_pid(@pid) if @pid SidekiqCluster.write_pid(@pid) if @pid
end end
def monotonic_time
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
end
def continue_waiting?(deadline) def continue_waiting?(deadline)
SidekiqCluster.any_alive?(@processes) && Gitlab::Metrics::System.monotonic_time < deadline SidekiqCluster.any_alive?(@processes) && monotonic_time < deadline
end end
def hard_stop_stuck_pids def hard_stop_stuck_pids
SidekiqCluster.signal_processes(SidekiqCluster.pids_alive(@processes), :KILL) SidekiqCluster.signal_processes(SidekiqCluster.pids_alive(@processes), :KILL)
end end
def wait_for_termination(check_interval = CHECK_TERMINATE_INTERVAL_SECONDS, terminate_timeout = TERMINATE_TIMEOUT_SECONDS) def wait_for_termination
deadline = Gitlab::Metrics::System.monotonic_time + terminate_timeout deadline = monotonic_time + TERMINATE_TIMEOUT_SECONDS
sleep(check_interval) while continue_waiting?(deadline) sleep(CHECK_TERMINATE_INTERVAL_SECONDS) while continue_waiting?(deadline)
hard_stop_stuck_pids hard_stop_stuck_pids
end end
......
...@@ -95,8 +95,9 @@ describe Gitlab::SidekiqCluster::CLI do ...@@ -95,8 +95,9 @@ describe Gitlab::SidekiqCluster::CLI do
expect(Gitlab::SidekiqCluster).to receive(:signal_processes) expect(Gitlab::SidekiqCluster).to receive(:signal_processes)
.with([], :KILL) .with([], :KILL)
# Check every 0.1s, for no more than 1 second total stub_const("Gitlab::SidekiqCluster::CLI::CHECK_TERMINATE_INTERVAL_SECONDS", 0.1)
cli.wait_for_termination(0.1, 1) stub_const("Gitlab::SidekiqCluster::CLI::TERMINATE_TIMEOUT_SECONDS", 1)
cli.wait_for_termination
end end
context 'with hanging workers' do context 'with hanging workers' do
...@@ -123,8 +124,9 @@ describe Gitlab::SidekiqCluster::CLI do ...@@ -123,8 +124,9 @@ describe Gitlab::SidekiqCluster::CLI do
cli.run(%w(foo)) cli.run(%w(foo))
# Check every 0.1s, for no more than 1 second total stub_const("Gitlab::SidekiqCluster::CLI::CHECK_TERMINATE_INTERVAL_SECONDS", 0.1)
cli.wait_for_termination(0.1, 1) stub_const("Gitlab::SidekiqCluster::CLI::TERMINATE_TIMEOUT_SECONDS", 1)
cli.wait_for_termination
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment