2019-11-24 12:06:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-21 23:34:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::HealthChecks::GitalyCheck do
|
2018-01-21 23:34:09 +00:00
|
|
|
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
|
|
|
|
expect(Gitlab::GitalyClient::HealthCheckService).to receive(:new).and_return(gitaly_check)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'Gitaly server is up' do
|
|
|
|
let(:gitaly_check) { double(check: { success: true }) }
|
|
|
|
|
2019-10-03 21:07:29 +00:00
|
|
|
it { is_expected.to eq([result_class.new('gitaly_check', true, nil, shard: 'default')]) }
|
2018-01-21 23:34:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Gitaly server is down' do
|
|
|
|
let(:gitaly_check) { double(check: { success: false, message: 'Connection refused' }) }
|
|
|
|
|
2019-10-03 21:07:29 +00:00
|
|
|
it { is_expected.to eq([result_class.new('gitaly_check', false, 'Connection refused', shard: 'default')]) }
|
2018-01-21 23:34:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#metrics' do
|
|
|
|
subject { described_class.metrics }
|
2019-10-18 11:11:44 +00:00
|
|
|
|
2018-06-20 08:21:59 +00:00
|
|
|
let(:server) { double(storage: 'default', read_writeable?: up) }
|
2018-01-21 23:34:09 +00:00
|
|
|
|
|
|
|
before do
|
2018-06-20 08:21:59 +00:00
|
|
|
allow(Gitaly::Server).to receive(:new).and_return(server)
|
2018-01-21 23:34:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Gitaly server is up' do
|
2018-06-20 08:21:59 +00:00
|
|
|
let(:up) { true }
|
2018-01-21 23:34:09 +00:00
|
|
|
|
|
|
|
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-06-20 08:21:59 +00:00
|
|
|
let(:up) { false }
|
2018-01-21 23:34:09 +00:00
|
|
|
|
|
|
|
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
|