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

health_check_service_spec.rb « gitaly_client « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0855544d11e5be077fe43536f0028a7a85f97dfc (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GitalyClient::HealthCheckService do
  let(:project) { create(:project) }
  let(:storage_name) { project.repository_storage }

  subject { described_class.new(storage_name) }

  describe '#check' do
    it 'successfully sends a health check request' do
      expect(Gitlab::GitalyClient).to receive(:call).with(
        storage_name,
        :health_check,
        :check,
        instance_of(Grpc::Health::V1::HealthCheckRequest),
        timeout: Gitlab::GitalyClient.fast_timeout).and_call_original

      expect(subject.check).to eq({ success: true })
    end

    it 'receives an unsuccessful health check request' do
      expect_any_instance_of(Grpc::Health::V1::Health::Stub)
        .to receive(:check)
        .and_return(double(status: false))

      expect(subject.check).to eq({ success: false })
    end

    it 'gracefully handles gRPC error' do
      expect(Gitlab::GitalyClient).to receive(:call).with(
        storage_name,
        :health_check,
        :check,
        instance_of(Grpc::Health::V1::HealthCheckRequest),
        timeout: Gitlab::GitalyClient.fast_timeout)
          .and_raise(GRPC::Unavailable.new('Connection refused'))

      expect(subject.check).to eq({ success: false, message: '14:Connection refused' })
    end
  end
end