2019-11-24 07:06:34 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-11-07 10:06:33 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require_relative './simple_check_shared'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::HealthChecks::MasterCheck do
|
2019-11-07 10:06:33 -05:00
|
|
|
let(:result_class) { Gitlab::HealthChecks::Result }
|
|
|
|
|
|
|
|
before do
|
2020-05-19 17:08:05 -04:00
|
|
|
stub_const('SUCCESS_CODE', 100)
|
|
|
|
stub_const('FAILURE_CODE', 101)
|
2019-11-07 10:06:33 -05:00
|
|
|
described_class.register_master
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
described_class.finish_master
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#readiness' do
|
|
|
|
context 'when master is running' do
|
|
|
|
it 'worker does return success' do
|
|
|
|
_, child_status = run_worker
|
|
|
|
|
|
|
|
expect(child_status.exitstatus).to eq(SUCCESS_CODE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when master finishes early' do
|
|
|
|
before do
|
|
|
|
described_class.send(:close_write)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'worker does return failure' do
|
|
|
|
_, child_status = run_worker
|
|
|
|
|
|
|
|
expect(child_status.exitstatus).to eq(FAILURE_CODE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_worker
|
|
|
|
pid = fork do
|
|
|
|
described_class.register_worker
|
|
|
|
|
|
|
|
exit(described_class.readiness.success ? SUCCESS_CODE : FAILURE_CODE)
|
|
|
|
end
|
|
|
|
|
|
|
|
Process.wait2(pid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|