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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/git/wraps_gitaly_errors_spec.rb')
-rw-r--r--spec/lib/gitlab/git/wraps_gitaly_errors_spec.rb81
1 files changed, 69 insertions, 12 deletions
diff --git a/spec/lib/gitlab/git/wraps_gitaly_errors_spec.rb b/spec/lib/gitlab/git/wraps_gitaly_errors_spec.rb
index e551dfaa1c5..c321d4bbdb9 100644
--- a/spec/lib/gitlab/git/wraps_gitaly_errors_spec.rb
+++ b/spec/lib/gitlab/git/wraps_gitaly_errors_spec.rb
@@ -2,24 +2,81 @@
require 'spec_helper'
-RSpec.describe Gitlab::Git::WrapsGitalyErrors do
+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
- mapping = {
- GRPC::NotFound => Gitlab::Git::Repository::NoRepository,
- GRPC::InvalidArgument => ArgumentError,
- GRPC::DeadlineExceeded => Gitlab::Git::CommandTimedOut,
- GRPC::BadStatus => Gitlab::Git::CommandError
- }
-
- mapping.each do |grpc_error, error|
- it "wraps #{grpc_error} in a #{error}" do
- expect { wrapper.wrapped_gitaly_errors { raise grpc_error, 'wrapped' } }
- .to raise_error(error)
+ 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