diff options
Diffstat (limited to 'spec/lib/gitlab/health_checks/master_check_spec.rb')
-rw-r--r-- | spec/lib/gitlab/health_checks/master_check_spec.rb | 68 |
1 files changed, 44 insertions, 24 deletions
diff --git a/spec/lib/gitlab/health_checks/master_check_spec.rb b/spec/lib/gitlab/health_checks/master_check_spec.rb index 1c1efe178e2..287ebcec207 100644 --- a/spec/lib/gitlab/health_checks/master_check_spec.rb +++ b/spec/lib/gitlab/health_checks/master_check_spec.rb @@ -4,47 +4,67 @@ require 'spec_helper' require_relative './simple_check_shared' RSpec.describe Gitlab::HealthChecks::MasterCheck do - let(:result_class) { Gitlab::HealthChecks::Result } - before do stub_const('SUCCESS_CODE', 100) stub_const('FAILURE_CODE', 101) - described_class.register_master end - after do - described_class.finish_master - end + context 'when Puma runs in Clustered mode' do + before do + allow(Gitlab::Runtime).to receive(:puma_in_clustered_mode?).and_return(true) - describe '#readiness' do - context 'when master is running' do - it 'worker does return success' do - _, child_status = run_worker + described_class.register_master + end - expect(child_status.exitstatus).to eq(SUCCESS_CODE) - end + after do + described_class.finish_master end - context 'when master finishes early' do - before do - described_class.send(:close_write) + describe '.available?' do + specify { expect(described_class.available?).to be true } + 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 - it 'worker does return failure' do - _, child_status = run_worker + context 'when master finishes early' do + before do + described_class.send(:close_write) + end - expect(child_status.exitstatus).to eq(FAILURE_CODE) + it 'worker does return failure' do + _, child_status = run_worker + + expect(child_status.exitstatus).to eq(FAILURE_CODE) + end end - end - def run_worker - pid = fork do - described_class.register_worker + def run_worker + pid = fork do + described_class.register_worker - exit(described_class.readiness.success ? SUCCESS_CODE : FAILURE_CODE) + exit(described_class.readiness.success ? SUCCESS_CODE : FAILURE_CODE) + end + + Process.wait2(pid) end + end + end + + # '.readiness' check is not invoked if '.available?' returns false + context 'when Puma runs in Single mode' do + before do + allow(Gitlab::Runtime).to receive(:puma_in_clustered_mode?).and_return(false) + end - Process.wait2(pid) + describe '.available?' do + specify { expect(described_class.available?).to be false } end end end |