diff options
Diffstat (limited to 'spec/lib/gitlab/health_checks')
-rw-r--r-- | spec/lib/gitlab/health_checks/master_check_spec.rb | 68 | ||||
-rw-r--r-- | spec/lib/gitlab/health_checks/probes/collection_spec.rb | 29 |
2 files changed, 73 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 diff --git a/spec/lib/gitlab/health_checks/probes/collection_spec.rb b/spec/lib/gitlab/health_checks/probes/collection_spec.rb index 03138e936aa..69828c143db 100644 --- a/spec/lib/gitlab/health_checks/probes/collection_spec.rb +++ b/spec/lib/gitlab/health_checks/probes/collection_spec.rb @@ -61,6 +61,35 @@ RSpec.describe Gitlab::HealthChecks::Probes::Collection do expect(subject.json[:message]).to eq('Redis::CannotConnectError : Redis down') end end + + context 'when some checks are not available' do + before do + allow(Gitlab::Runtime).to receive(:puma_in_clustered_mode?).and_return(false) + end + + let(:checks) do + [ + Gitlab::HealthChecks::MasterCheck + ] + end + + it 'asks for check availability' do + expect(Gitlab::HealthChecks::MasterCheck).to receive(:available?) + + subject + end + + it 'does not call `readiness` on checks that are not available' do + expect(Gitlab::HealthChecks::MasterCheck).not_to receive(:readiness) + + subject + end + + it 'does not fail collection check' do + expect(subject.http_status).to eq(200) + expect(subject.json[:status]).to eq('ok') + end + end end context 'without checks' do |