diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/gitaly_client | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/gitaly_client')
19 files changed, 224 insertions, 23 deletions
diff --git a/spec/lib/gitlab/gitaly_client/blob_service_spec.rb b/spec/lib/gitlab/gitaly_client/blob_service_spec.rb index e609acc8fb0..037734f1b13 100644 --- a/spec/lib/gitlab/gitaly_client/blob_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/blob_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::BlobService do +RSpec.describe Gitlab::GitalyClient::BlobService do let(:project) { create(:project, :repository) } let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } diff --git a/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb b/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb index e88b86c71f2..e0c3e8d4b40 100644 --- a/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb +++ b/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::BlobsStitcher do +RSpec.describe Gitlab::GitalyClient::BlobsStitcher do describe 'enumeration' do it 'combines segregated blob messages together' do messages = [ diff --git a/spec/lib/gitlab/gitaly_client/call_spec.rb b/spec/lib/gitlab/gitaly_client/call_spec.rb new file mode 100644 index 00000000000..5c33ac40460 --- /dev/null +++ b/spec/lib/gitlab/gitaly_client/call_spec.rb @@ -0,0 +1,122 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GitalyClient::Call do + describe '#call', :request_store do + let(:client) { Gitlab::GitalyClient } + let(:storage) { 'default' } + let(:remote_storage) { nil } + let(:request) { Gitaly::FindLocalBranchesRequest.new } + let(:rpc) { :find_local_branches } + let(:service) { :ref_service } + let(:timeout) { client.long_timeout } + + subject do + described_class.new(storage, service, rpc, request, remote_storage, timeout).call + end + + before do + allow(client).to receive(:execute) { response } + allow(Gitlab::PerformanceBar).to receive(:enabled_for_request?) { true } + end + + def expect_call_details_to_match(duration_higher_than: 0) + expect(client.list_call_details.size).to eq(1) + expect(client.list_call_details.first) + .to match a_hash_including(feature: "#{service}##{rpc}", + duration: a_value > duration_higher_than, + request: an_instance_of(Hash), + rpc: rpc, + backtrace: an_instance_of(Array)) + end + + context 'when the response is not an enumerator' do + let(:response) do + Gitaly::FindLocalBranchesResponse.new + end + + it 'returns the response' do + expect(subject).to eq(response) + end + + it 'stores timings and call details' do + subject + + expect(client.query_time).to be > 0 + expect_call_details_to_match + end + + context 'when err' do + before do + allow(client).to receive(:execute).and_raise(StandardError) + end + + it 'stores timings and call details' do + expect { subject }.to raise_error(StandardError) + + expect(client.query_time).to be > 0 + expect_call_details_to_match + end + end + end + + context 'when the response is an enumerator' do + let(:response) do + Enumerator.new do |yielder| + yielder << 1 + yielder << 2 + end + end + + it 'returns a consumable enumerator' do + instrumented_response = subject + + expect(instrumented_response).to be_a(Enumerator) + expect(instrumented_response.to_a).to eq([1, 2]) + end + + context 'time measurements' do + let(:response) do + Enumerator.new do |yielder| + sleep 0.1 + yielder << 1 + sleep 0.2 + yielder << 2 + end + end + + it 'records full rpc stream consumption' do + subject.to_a + + expect(client.query_time).to be > 0.3 + expect_call_details_to_match(duration_higher_than: 0.3) + end + + it 'records partial rpc stream consumption' do + subject.first + + expect(client.query_time).to be > 0.1 + expect_call_details_to_match(duration_higher_than: 0.1) + end + + context 'when err' do + let(:response) do + Enumerator.new do |yielder| + sleep 0.2 + yielder << 1 + raise StandardError + end + end + + it 'records partial rpc stream consumption' do + expect { subject.to_a }.to raise_error(StandardError) + + expect(client.query_time).to be > 0.2 + expect_call_details_to_match(duration_higher_than: 0.2) + end + end + end + end + end +end diff --git a/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb b/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb index 07f53797b2a..3381c69ea0d 100644 --- a/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::CleanupService do +RSpec.describe Gitlab::GitalyClient::CleanupService do let(:project) { create(:project) } let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb index 29a5ef0d2fc..45a25ccfc88 100644 --- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::CommitService do +RSpec.describe Gitlab::GitalyClient::CommitService do let(:project) { create(:project, :repository) } let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } @@ -290,7 +290,8 @@ describe Gitlab::GitalyClient::CommitService do request = Gitaly::FindCommitsRequest.new( repository: repository_message, disable_walk: true, - order: 'NONE' + order: 'NONE', + global_options: Gitaly::GlobalOptions.new(literal_pathspecs: false) ) expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:find_commits) @@ -303,7 +304,8 @@ describe Gitlab::GitalyClient::CommitService do request = Gitaly::FindCommitsRequest.new( repository: repository_message, disable_walk: true, - order: 'TOPO' + order: 'TOPO', + global_options: Gitaly::GlobalOptions.new(literal_pathspecs: false) ) expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:find_commits) @@ -317,7 +319,8 @@ describe Gitlab::GitalyClient::CommitService do repository: repository_message, disable_walk: true, order: 'NONE', - author: "Billy Baggins <bilbo@shire.com>" + author: "Billy Baggins <bilbo@shire.com>", + global_options: Gitaly::GlobalOptions.new(literal_pathspecs: false) ) expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:find_commits) @@ -338,7 +341,8 @@ describe Gitlab::GitalyClient::CommitService do revision: (options[:revision] || '').dup.force_encoding(Encoding::ASCII_8BIT), path: (options[:path] || '').dup.force_encoding(Encoding::ASCII_8BIT), limit: (options[:limit] || 1000).to_i, - offset: (options[:offset] || 0).to_i + offset: (options[:offset] || 0).to_i, + global_options: Gitaly::GlobalOptions.new(literal_pathspecs: true) ) allow_any_instance_of(Gitaly::CommitService::Stub) @@ -381,4 +385,19 @@ describe Gitlab::GitalyClient::CommitService do commits.map { |commit| Gitlab::Git::Commit.new(repository, commit) } end end + + describe '#list_commits_by_ref_name' do + let(:project) { create(:project, :repository, create_branch: 'ü/unicode/multi-byte') } + + it 'lists latest commits grouped by a ref name' do + response = client.list_commits_by_ref_name(%w[master feature v1.0.0 nonexistent ü/unicode/multi-byte]) + + expect(response.keys.count).to eq 4 + expect(response.fetch('master').id).to eq 'b83d6e391c22777fca1ed3012fce84f633d7fed0' + expect(response.fetch('feature').id).to eq '0b4bc9a49b562e85de7cc9e834518ea6828729b9' + expect(response.fetch('v1.0.0').id).to eq '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9' + expect(response.fetch('ü/unicode/multi-byte')).to be_present + expect(response).not_to have_key 'nonexistent' + end + end end diff --git a/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb b/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb index db734b1c129..0bb8628af6c 100644 --- a/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb +++ b/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::ConflictFilesStitcher do +RSpec.describe Gitlab::GitalyClient::ConflictFilesStitcher do describe 'enumeration' do it 'combines segregated ConflictFile messages together' do target_project = create(:project, :repository) diff --git a/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb b/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb index f19bcae2470..b016e8bdf5a 100644 --- a/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::ConflictsService do +RSpec.describe Gitlab::GitalyClient::ConflictsService do let(:project) { create(:project, :repository) } let(:target_project) { create(:project, :repository) } let(:source_repository) { project.repository.raw } diff --git a/spec/lib/gitlab/gitaly_client/diff_spec.rb b/spec/lib/gitlab/gitaly_client/diff_spec.rb index d86497da7f5..230322faecd 100644 --- a/spec/lib/gitlab/gitaly_client/diff_spec.rb +++ b/spec/lib/gitlab/gitaly_client/diff_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::Diff do +RSpec.describe Gitlab::GitalyClient::Diff do let(:diff_fields) do { to_path: ".gitmodules", diff --git a/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb b/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb index c9d42ad32cf..113c47b4f2c 100644 --- a/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb +++ b/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::DiffStitcher do +RSpec.describe Gitlab::GitalyClient::DiffStitcher do describe 'enumeration' do it 'combines segregated diff messages together' do diff_1 = OpenStruct.new( diff --git a/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb b/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb index 615bc80fff2..0855544d11e 100644 --- a/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::HealthCheckService do +RSpec.describe Gitlab::GitalyClient::HealthCheckService do let(:project) { create(:project) } let(:storage_name) { project.repository_storage } diff --git a/spec/lib/gitlab/gitaly_client/object_pool_service_spec.rb b/spec/lib/gitlab/gitaly_client/object_pool_service_spec.rb index 0e0c3d329b5..15eebf62a39 100644 --- a/spec/lib/gitlab/gitaly_client/object_pool_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/object_pool_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::ObjectPoolService do +RSpec.describe Gitlab::GitalyClient::ObjectPoolService do let(:pool_repository) { create(:pool_repository) } let(:project) { create(:project, :repository) } let(:raw_repository) { project.repository.raw } diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index 45701b501bb..4e16f760235 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::OperationService do +RSpec.describe Gitlab::GitalyClient::OperationService do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :repository) } let(:repository) { project.repository.raw } @@ -191,6 +191,20 @@ describe Gitlab::GitalyClient::OperationService do it { expect(subject).to be_nil } end + + context "when the pre-receive hook fails" do + let(:response) do + Gitaly::UserFFBranchResponse.new( + branch_update: nil, + pre_receive_error: "pre-receive hook error message\n" + ) + end + + it "raises the error" do + # the PreReceiveError class strips the GL-HOOK-ERR prefix from this error + expect { subject }.to raise_error(Gitlab::Git::PreReceiveError, "pre-receive hook failed.") + end + end end shared_examples 'cherry pick and revert errors' do diff --git a/spec/lib/gitlab/gitaly_client/praefect_info_service_spec.rb b/spec/lib/gitlab/gitaly_client/praefect_info_service_spec.rb index 9b5c751e0ec..5f90745f4e0 100644 --- a/spec/lib/gitlab/gitaly_client/praefect_info_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/praefect_info_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::PraefectInfoService do +RSpec.describe Gitlab::GitalyClient::PraefectInfoService do let(:project) { create(:project, :repository) } let(:repository) { project.repository } let(:gitaly_repository) { repository.gitaly_repository } diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb index d4a7f6e6df9..a4c6e30bba8 100644 --- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::RefService do +RSpec.describe Gitlab::GitalyClient::RefService do let(:project) { create(:project, :repository) } let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } @@ -34,7 +34,7 @@ describe Gitlab::GitalyClient::RefService do subject end - it 'concantes and returns the response branches as Gitlab::Git::Branch objects' do + it 'concatenates and returns the response branches as Gitlab::Git::Branch objects' do target_commits = create_list(:gitaly_commit, 4) response_branches = target_commits.each_with_index.map do |gitaly_commit, i| Gitaly::Branch.new(name: "#{remote_name}/#{i}", target_commit: gitaly_commit) @@ -59,6 +59,17 @@ describe Gitlab::GitalyClient::RefService do end end + describe '#merged_branches' do + it 'sends a find_all_branches message' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:find_all_branches) + .with(gitaly_request_with_params(merged_only: true, merged_branches: ['test']), kind_of(Hash)) + .and_return([]) + + client.merged_branches(%w(test)) + end + end + describe '#branch_names' do it 'sends a find_all_branch_names message' do expect_any_instance_of(Gitaly::RefService::Stub) @@ -135,6 +146,38 @@ describe Gitlab::GitalyClient::RefService do end end + describe '#tags' do + it 'sends a find_all_tags message' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:find_all_tags) + .and_return([]) + + client.tags + end + end + + describe '#branch_names_contains_sha' do + it 'sends a list_branch_names_containing_commit message' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:list_branch_names_containing_commit) + .with(gitaly_request_with_params(commit_id: '123', limit: 0), kind_of(Hash)) + .and_return([]) + + client.branch_names_contains_sha('123') + end + end + + describe '#get_tag_messages' do + it 'sends a get_tag_messages message' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:get_tag_messages) + .with(gitaly_request_with_params(tag_ids: ['some_tag_id']), kind_of(Hash)) + .and_return([]) + + client.get_tag_messages(['some_tag_id']) + end + end + describe '#find_ref_name', :seed_helper do subject { client.find_ref_name(SeedRepo::Commit::ID, 'refs/heads/master') } diff --git a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb index 2bddec739fc..b9ef76e1f41 100644 --- a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::RemoteService do +RSpec.describe Gitlab::GitalyClient::RemoteService do let(:project) { create(:project) } let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } @@ -73,8 +73,11 @@ describe Gitlab::GitalyClient::RemoteService do describe '.exists?' do context "when the remote doesn't exist" do let(:url) { 'https://gitlab.com/gitlab-org/ik-besta-niet-of-ik-word-geplaagd.git' } + let(:storage_name) { 'default' } it 'returns false' do + expect(Gitaly::FindRemoteRepositoryRequest).to receive(:new).with(remote: url, storage_name: storage_name).and_call_original + expect(described_class.exists?(url)).to be(false) end end diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index 5f4147f6ff6..c7ea0a95596 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::RepositoryService do +RSpec.describe Gitlab::GitalyClient::RepositoryService do using RSpec::Parameterized::TableSyntax let(:project) { create(:project) } diff --git a/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb b/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb index a6b29489df3..0c4c8de52ae 100644 --- a/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb +++ b/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::StorageSettings do +RSpec.describe Gitlab::GitalyClient::StorageSettings do describe "#initialize" do context 'when the storage contains no path' do it 'raises an error' do diff --git a/spec/lib/gitlab/gitaly_client/util_spec.rb b/spec/lib/gitlab/gitaly_client/util_spec.rb index f31b7c349ff..b6589a08f7d 100644 --- a/spec/lib/gitlab/gitaly_client/util_spec.rb +++ b/spec/lib/gitlab/gitaly_client/util_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::Util do +RSpec.describe Gitlab::GitalyClient::Util do describe '.repository' do let(:repository_storage) { 'default' } let(:relative_path) { 'my/repo.git' } diff --git a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb index cb04f9a1637..a06f8459963 100644 --- a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GitalyClient::WikiService do +RSpec.describe Gitlab::GitalyClient::WikiService do let(:project) { create(:project) } let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } |