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
SidekiqCluster.write_pid(@pid) if @pid
end
def monotonic_time
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
end
def continue_waiting?(deadline)
SidekiqCluster.any_alive?(@processes) && Gitlab::Metrics::System.monotonic_time < deadline
SidekiqCluster.any_alive?(@processes) && monotonic_time < deadline
end
def hard_stop_stuck_pids
SidekiqCluster.signal_processes(SidekiqCluster.pids_alive(@processes), :KILL)
end
def wait_for_termination(check_interval = CHECK_TERMINATE_INTERVAL_SECONDS, terminate_timeout = TERMINATE_TIMEOUT_SECONDS)
deadline = Gitlab::Metrics::System.monotonic_time + terminate_timeout
sleep(check_interval) while continue_waiting?(deadline)
def wait_for_termination
deadline = monotonic_time + TERMINATE_TIMEOUT_SECONDS
sleep(CHECK_TERMINATE_INTERVAL_SECONDS) while continue_waiting?(deadline)
hard_stop_stuck_pids
end
......
......@@ -95,8 +95,9 @@ describe Gitlab::SidekiqCluster::CLI do
expect(Gitlab::SidekiqCluster).to receive(:signal_processes)
.with([], :KILL)
# Check every 0.1s, for no more than 1 second total
cli.wait_for_termination(0.1, 1)
stub_const("Gitlab::SidekiqCluster::CLI::CHECK_TERMINATE_INTERVAL_SECONDS", 0.1)
stub_const("Gitlab::SidekiqCluster::CLI::TERMINATE_TIMEOUT_SECONDS", 1)
cli.wait_for_termination
end
context 'with hanging workers' do
......@@ -123,8 +124,9 @@ describe Gitlab::SidekiqCluster::CLI do
cli.run(%w(foo))
# Check every 0.1s, for no more than 1 second total
cli.wait_for_termination(0.1, 1)
stub_const("Gitlab::SidekiqCluster::CLI::CHECK_TERMINATE_INTERVAL_SECONDS", 0.1)
stub_const("Gitlab::SidekiqCluster::CLI::TERMINATE_TIMEOUT_SECONDS", 1)
cli.wait_for_termination
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