diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/lib/gitlab/health_checks/master_check_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/lib/gitlab/health_checks/master_check_spec.rb')
-rw-r--r-- | spec/lib/gitlab/health_checks/master_check_spec.rb | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/spec/lib/gitlab/health_checks/master_check_spec.rb b/spec/lib/gitlab/health_checks/master_check_spec.rb index 8a87b01c560..5cd26f6302a 100644 --- a/spec/lib/gitlab/health_checks/master_check_spec.rb +++ b/spec/lib/gitlab/health_checks/master_check_spec.rb @@ -4,16 +4,14 @@ require 'fast_spec_helper' require_relative './simple_check_shared' RSpec.describe Gitlab::HealthChecks::MasterCheck do - before do - stub_const('SUCCESS_CODE', 100) - stub_const('FAILURE_CODE', 101) - end - context 'when Puma runs in Clustered mode' do before do allow(Gitlab::Runtime).to receive(:puma_in_clustered_mode?).and_return(true) - described_class.register_master + # We need to capture the read pipe here to stub out the non-blocking read. + # The original implementation actually forked the test suite for a more + # end-to-end test but that caused knock-on effects on other tests. + @pipe_read, _ = described_class.register_master end after do @@ -25,34 +23,40 @@ RSpec.describe Gitlab::HealthChecks::MasterCheck do 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) + context 'when no worker registered' do + it 'succeeds' do + expect(described_class.readiness.success).to be(true) end end - context 'when master finishes early' do - before do - described_class.send(:close_write) + context 'when worker registers itself' do + context 'when reading from pipe succeeds' do + it 'succeeds' do + expect(@pipe_read).to receive(:read_nonblock) # rubocop: disable RSpec/InstanceVariable + + described_class.register_worker + + expect(described_class.readiness.success).to be(true) + end end - it 'worker does return failure' do - _, child_status = run_worker + context 'when read pipe is open but not ready for reading' do + it 'succeeds' do + expect(@pipe_read).to receive(:read_nonblock).and_raise(IO::EAGAINWaitReadable) # rubocop: disable RSpec/InstanceVariable + + described_class.register_worker - expect(child_status.exitstatus).to eq(FAILURE_CODE) + expect(described_class.readiness.success).to be(true) + end end end - def run_worker - pid = fork do - described_class.register_worker + context 'when master finishes early' do + it 'fails' do + described_class.finish_master - exit(described_class.readiness.success ? SUCCESS_CODE : FAILURE_CODE) + expect(described_class.readiness.success).to be(false) end - - Process.wait2(pid) end end end |