debian-mirror-gitlab/spec/lib/gitlab/health_checks/master_check_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.2 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require 'fast_spec_helper'
2019-12-26 22:10:19 +05:30
require_relative './simple_check_shared'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::HealthChecks::MasterCheck do
2021-03-11 19:13:27 +05:30
context 'when Puma runs in Clustered mode' do
before do
allow(Gitlab::Runtime).to receive(:puma_in_clustered_mode?).and_return(true)
2019-12-26 22:10:19 +05:30
2022-11-25 23:54:43 +05:30
# 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
2021-03-11 19:13:27 +05:30
end
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
after do
described_class.finish_master
2019-12-26 22:10:19 +05:30
end
2021-03-11 19:13:27 +05:30
describe '.available?' do
specify { expect(described_class.available?).to be true }
end
describe '.readiness' do
2022-11-25 23:54:43 +05:30
context 'when no worker registered' do
it 'succeeds' do
expect(described_class.readiness.success).to be(true)
2021-03-11 19:13:27 +05:30
end
2019-12-26 22:10:19 +05:30
end
2022-11-25 23:54:43 +05:30
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
2021-03-11 19:13:27 +05:30
end
2019-12-26 22:10:19 +05:30
2022-11-25 23:54:43 +05:30
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
2021-03-11 19:13:27 +05:30
2022-11-25 23:54:43 +05:30
expect(described_class.readiness.success).to be(true)
end
2021-03-11 19:13:27 +05:30
end
2019-12-26 22:10:19 +05:30
end
2022-11-25 23:54:43 +05:30
context 'when master finishes early' do
it 'fails' do
described_class.finish_master
2019-12-26 22:10:19 +05:30
2022-11-25 23:54:43 +05:30
expect(described_class.readiness.success).to be(false)
2021-03-11 19:13:27 +05:30
end
2019-12-26 22:10:19 +05:30
end
2021-03-11 19:13:27 +05:30
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
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
describe '.available?' do
specify { expect(described_class.available?).to be false }
2019-12-26 22:10:19 +05:30
end
end
end