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

wraps_gitaly_errors_spec.rb « git « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c321d4bbdb9a3cf142a7bec655380439d19ea2b6 (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
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Git::WrapsGitalyErrors, feature_category: :gitaly do
  subject(:wrapper) do
    klazz = Class.new { include Gitlab::Git::WrapsGitalyErrors }
    klazz.new
  end

  describe "#wrapped_gitaly_errors" do
    where(:original_error, :wrapped_error) do
      [
        [GRPC::NotFound, Gitlab::Git::Repository::NoRepository],
        [GRPC::InvalidArgument, ArgumentError],
        [GRPC::DeadlineExceeded, Gitlab::Git::CommandTimedOut],
        [GRPC::BadStatus, Gitlab::Git::CommandError]
      ]
    end

    with_them do
      it "wraps #{params[:original_error]} in a #{params[:wrapped_error]}" do
        expect { wrapper.wrapped_gitaly_errors { raise original_error, 'wrapped' } }
          .to raise_error(wrapped_error)
      end
    end

    context 'when wrap GRPC::ResourceExhausted' do
      context 'with Gitaly::LimitError detail' do
        let(:original_error) do
          new_detailed_error(
            GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED,
            'resource exhausted',
            Gitaly::LimitError.new(
              error_message: "maximum time in concurrency queue reached",
              retry_after: Google::Protobuf::Duration.new(seconds: 5, nanos: 1500)
            )
          )
        end

        it "wraps in a Gitlab::Git::ResourceExhaustedError with error message" do
          expect { wrapper.wrapped_gitaly_errors { raise original_error } }.to raise_error do |wrapped_error|
            expect(wrapped_error).to be_a(Gitlab::Git::ResourceExhaustedError)
            expect(wrapped_error.message).to eql(
              "Upstream Gitaly has been exhausted: maximum time in concurrency queue reached. Try again later"
            )
            expect(wrapped_error.headers).to eql({ 'Retry-After' => 5 })
          end
        end
      end

      context 'with Gitaly::LimitError detail without retry after' do
        let(:original_error) do
          new_detailed_error(
            GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED,
            'resource exhausted',
            Gitaly::LimitError.new(error_message: "maximum time in concurrency queue reached")
          )
        end

        it "wraps in a Gitlab::Git::ResourceExhaustedError with error message" do
          expect { wrapper.wrapped_gitaly_errors { raise original_error } }.to raise_error do |wrapped_error|
            expect(wrapped_error).to be_a(Gitlab::Git::ResourceExhaustedError)
            expect(wrapped_error.message).to eql(
              "Upstream Gitaly has been exhausted: maximum time in concurrency queue reached. Try again later"
            )
            expect(wrapped_error.headers).to eql({})
          end
        end
      end

      context 'without Gitaly::LimitError detail' do
        it("wraps in a Gitlab::Git::ResourceExhaustedError with default message") {
          expect { wrapper.wrapped_gitaly_errors { raise GRPC::ResourceExhausted } }.to raise_error do |wrapped_error|
            expect(wrapped_error).to be_a(Gitlab::Git::ResourceExhaustedError)
            expect(wrapped_error.message).to eql("Upstream Gitaly has been exhausted. Try again later")
            expect(wrapped_error.headers).to eql({})
          end
        }
      end
    end

    it 'does not swallow other errors' do
      expect { wrapper.wrapped_gitaly_errors { raise 'raised' } }
        .to raise_error(RuntimeError)
    end
  end
end