Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitaly_check_spec.rb « health_checks « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 000b8eff6612b86af1d6a58b81e329bc683abb71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::HealthChecks::GitalyCheck do
  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(healthy_check)
    end

    context 'Gitaly server is up' 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: true }) }

      it { is_expected.to eq([result_class.new('gitaly_check', true, nil, shard: 'default')]) }
    end

    context 'Gitaly server is down' do
      let(:healthy_check) { double(check: { success: false, message: 'Connection refused' }) }

      it { is_expected.to eq([result_class.new('gitaly_check', false, 'Connection refused', shard: 'default')]) }
    end

    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
  end

  describe '#metrics' do
    subject { described_class.metrics }

    let(:server) { double(storage: 'default', read_writeable?: up) }

    before do
      allow(Gitaly::Server).to receive(:new).and_return(server)
    end

    context 'Gitaly server is up' do
      let(:up) { true }

      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
      let(:up) { false }

      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