2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
require 'fast_spec_helper'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::HealthChecks::GitalyCheck do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:result_class) { Gitlab::HealthChecks::Result }
|
|
|
|
let(:repository_storages) { ['default'] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:repository_storages) { repository_storages }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#readiness' do
|
|
|
|
subject { described_class.readiness }
|
|
|
|
|
|
|
|
before do
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(Gitlab::GitalyClient::HealthCheckService).to receive(:new).and_return(healthy_check)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'Gitaly server is up' do
|
2022-10-11 01:57:18 +05:30
|
|
|
before do
|
|
|
|
expect(Gitlab::GitalyClient::ServerService).to receive(:new).and_return(ready_check)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:healthy_check) { double(check: { success: true }) }
|
|
|
|
let(:ready_check) { double(readiness_check: { success: true }) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it { is_expected.to eq([result_class.new('gitaly_check', true, nil, shard: 'default')]) }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'Gitaly server is down' do
|
2022-10-11 01:57:18 +05:30
|
|
|
let(:healthy_check) { double(check: { success: false, message: 'Connection refused' }) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it { is_expected.to eq([result_class.new('gitaly_check', false, 'Connection refused', shard: 'default')]) }
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
context 'Gitaly server is not ready' do
|
|
|
|
before do
|
|
|
|
expect(Gitlab::GitalyClient::ServerService).to receive(:new).and_return(ready_check)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:healthy_check) { double(check: { success: true }) }
|
|
|
|
let(:ready_check) { double(readiness_check: { success: false, message: 'Clock is out of sync' }) }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([result_class.new('gitaly_check', false, 'Clock is out of sync', shard: 'default')]) }
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#metrics' do
|
|
|
|
subject { described_class.metrics }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:server) { double(storage: 'default', read_writeable?: up) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
before do
|
2018-11-08 19:23:39 +05:30
|
|
|
allow(Gitaly::Server).to receive(:new).and_return(server)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'Gitaly server is up' do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:up) { true }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'provides metrics' do
|
|
|
|
expect(subject).to all(have_attributes(labels: { shard: 'default' }))
|
|
|
|
expect(subject).to include(an_object_having_attributes(name: 'gitaly_health_check_success', value: 1))
|
|
|
|
expect(subject).to include(an_object_having_attributes(name: 'gitaly_health_check_latency_seconds', value: be >= 0))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Gitaly server is down' do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:up) { false }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'provides metrics' do
|
|
|
|
expect(subject).to include(an_object_having_attributes(name: 'gitaly_health_check_success', value: 0))
|
|
|
|
expect(subject).to include(an_object_having_attributes(name: 'gitaly_health_check_latency_seconds', value: be >= 0))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|