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
path: root/spec
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-07-30 19:55:28 +0300
committerNick Thomas <nick@gitlab.com>2018-07-30 19:55:28 +0300
commitcb2e07309b4e61501a44c3568155bdb73252338f (patch)
tree90d9c1deae0ee2c57b05fbe76ed96d13cf54a1af /spec
parent5b6553a0810f65d79c648aca9dba254644a293fb (diff)
parent9a81550feddd907f8796362d604f63ed66ad80a2 (diff)
Merge branch 'fj-37736-improve-performance-post-receive-create-gpg-siganture-worker' into 'master'
Create GPG commit signature in bulk See merge request gitlab-org/gitlab-ce!20870
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_spec.rb10
-rw-r--r--spec/services/git_push_service_spec.rb12
-rw-r--r--spec/workers/create_gpg_signature_worker_spec.rb38
3 files changed, 47 insertions, 13 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index b75ca91b007..ef4167a3912 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -3877,6 +3877,16 @@ describe Project do
end
end
+ context '#commits_by' do
+ let(:project) { create(:project, :repository) }
+ let(:commits) { project.repository.commits('HEAD', limit: 3).commits }
+ let(:commit_shas) { commits.map(&:id) }
+
+ it 'retrieves several commits from the repository by oid' do
+ expect(project.commits_by(oids: commit_shas)).to eq commits
+ end
+ end
+
def rugged_config
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
project.repository.rugged.config
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index 3f62e7e61e1..657afb2b2b5 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -761,7 +761,7 @@ describe GitPushService, services: true do
end
it 'does not queue a CreateGpgSignatureWorker' do
- expect(CreateGpgSignatureWorker).not_to receive(:perform_async).with(sample_commit.id, project.id)
+ expect(CreateGpgSignatureWorker).not_to receive(:perform_async)
execute_service(project, user, oldrev, newrev, ref)
end
@@ -769,7 +769,15 @@ describe GitPushService, services: true do
context 'when the signature is not yet cached' do
it 'queues a CreateGpgSignatureWorker' do
- expect(CreateGpgSignatureWorker).to receive(:perform_async).with(sample_commit.id, project.id)
+ expect(CreateGpgSignatureWorker).to receive(:perform_async).with([sample_commit.id], project.id)
+
+ execute_service(project, user, oldrev, newrev, ref)
+ end
+
+ it 'can queue several commits to create the gpg signature' do
+ allow(Gitlab::Git::Commit).to receive(:shas_with_signatures).and_return([sample_commit.id, another_sample_commit.id])
+
+ expect(CreateGpgSignatureWorker).to receive(:perform_async).with([sample_commit.id, another_sample_commit.id], project.id)
execute_service(project, user, oldrev, newrev, ref)
end
diff --git a/spec/workers/create_gpg_signature_worker_spec.rb b/spec/workers/create_gpg_signature_worker_spec.rb
index aa6c347d738..647a4bcc18e 100644
--- a/spec/workers/create_gpg_signature_worker_spec.rb
+++ b/spec/workers/create_gpg_signature_worker_spec.rb
@@ -2,21 +2,37 @@ require 'spec_helper'
describe CreateGpgSignatureWorker do
let(:project) { create(:project, :repository) }
+ let(:commits) { project.repository.commits('HEAD', limit: 3).commits }
+ let(:commit_shas) { commits.map(&:id) }
context 'when GpgKey is found' do
- let(:commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' }
+ let(:gpg_commit) { instance_double(Gitlab::Gpg::Commit) }
+
+ before do
+ allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
+ allow(project).to receive(:commits_by).with(oids: commit_shas).and_return(commits)
+ end
+
+ subject { described_class.new.perform(commit_shas, project.id) }
it 'calls Gitlab::Gpg::Commit#signature' do
- commit = instance_double(Commit)
- gpg_commit = instance_double(Gitlab::Gpg::Commit)
+ commits.each do |commit|
+ expect(Gitlab::Gpg::Commit).to receive(:new).with(commit).and_return(gpg_commit).once
+ end
- allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
- allow(project).to receive(:commit).with(commit_sha).and_return(commit)
+ expect(gpg_commit).to receive(:signature).exactly(commits.size).times
+
+ subject
+ end
+
+ it 'can recover form exception and continue the siganture frocess' do
+ allow(gpg_commit).to receive(:signature)
+ allow(Gitlab::Gpg::Commit).to receive(:new).and_return(gpg_commit)
+ allow(Gitlab::Gpg::Commit).to receive(:new).with(commits.first).and_raise(StandardError)
- expect(Gitlab::Gpg::Commit).to receive(:new).with(commit).and_return(gpg_commit)
- expect(gpg_commit).to receive(:signature)
+ expect(gpg_commit).to receive(:signature).exactly(2).times
- described_class.new.perform(commit_sha, project.id)
+ subject
end
end
@@ -24,7 +40,7 @@ describe CreateGpgSignatureWorker do
let(:nonexisting_commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a34' }
it 'does not raise errors' do
- expect { described_class.new.perform(nonexisting_commit_sha, project.id) }.not_to raise_error
+ expect { described_class.new.perform([nonexisting_commit_sha], project.id) }.not_to raise_error
end
end
@@ -32,13 +48,13 @@ describe CreateGpgSignatureWorker do
let(:nonexisting_project_id) { -1 }
it 'does not raise errors' do
- expect { described_class.new.perform(anything, nonexisting_project_id) }.not_to raise_error
+ expect { described_class.new.perform(commit_shas, nonexisting_project_id) }.not_to raise_error
end
it 'does not call Gitlab::Gpg::Commit#signature' do
expect_any_instance_of(Gitlab::Gpg::Commit).not_to receive(:signature)
- described_class.new.perform(anything, nonexisting_project_id)
+ described_class.new.perform(commit_shas, nonexisting_project_id)
end
end
end