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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 21:38:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 21:38:24 +0300
commit983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch)
treeb153cd387c14ba23bd5a07514c7c01fddf6a78a0 /spec/workers
parenta2bddee2cdb38673df0e004d5b32d9f77797de64 (diff)
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/concerns/cronjob_queue_spec.rb22
-rw-r--r--spec/workers/create_commit_signature_worker_spec.rb59
-rw-r--r--spec/workers/expire_pipeline_cache_worker_spec.rb8
-rw-r--r--spec/workers/export_csv_worker_spec.rb34
-rw-r--r--spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb18
-rw-r--r--spec/workers/post_receive_spec.rb3
6 files changed, 126 insertions, 18 deletions
diff --git a/spec/workers/concerns/cronjob_queue_spec.rb b/spec/workers/concerns/cronjob_queue_spec.rb
index ea3b7bad2e1..0cea67bf116 100644
--- a/spec/workers/concerns/cronjob_queue_spec.rb
+++ b/spec/workers/concerns/cronjob_queue_spec.rb
@@ -14,6 +14,10 @@ describe CronjobQueue do
end
end
+ before do
+ stub_const("DummyWorker", worker)
+ end
+
it 'sets the queue name of a worker' do
expect(worker.sidekiq_options['queue'].to_s).to eq('cronjob:dummy')
end
@@ -29,4 +33,22 @@ describe CronjobQueue do
expect(worker_context[:root_namespace]).to be_nil
expect(worker_context[:project]).to be_nil
end
+
+ it 'gets scheduled with caller_id set to Cronjob' do
+ worker.perform_async
+
+ job = worker.jobs.last
+
+ expect(job).to include('meta.caller_id' => 'Cronjob')
+ end
+
+ it 'does not set the caller_id if there was already one in the context' do
+ Gitlab::ApplicationContext.with_context(caller_id: 'already set') do
+ worker.perform_async
+ end
+
+ job = worker.jobs.last
+
+ expect(job).to include('meta.caller_id' => 'already set')
+ end
end
diff --git a/spec/workers/create_commit_signature_worker_spec.rb b/spec/workers/create_commit_signature_worker_spec.rb
index d7235fcd907..f40482f2361 100644
--- a/spec/workers/create_commit_signature_worker_spec.rb
+++ b/spec/workers/create_commit_signature_worker_spec.rb
@@ -9,14 +9,14 @@ describe CreateCommitSignatureWorker do
let(:gpg_commit) { instance_double(Gitlab::Gpg::Commit) }
let(:x509_commit) { instance_double(Gitlab::X509::Commit) }
- context 'when a signature is found' do
- 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
+ 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) }
+ subject { described_class.new.perform(commit_shas, project.id) }
+ context 'when a signature is found' do
it 'calls Gitlab::Gpg::Commit#signature' do
commits.each do |commit|
allow(commit).to receive(:signature_type).and_return(:PGP)
@@ -67,9 +67,10 @@ describe CreateCommitSignatureWorker do
end
context 'handles when a string is passed in for the commit SHA' do
+ let(:commit_shas) { super().first }
+
before do
- allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
- allow(project).to receive(:commits_by).with(oids: Array(commit_shas.first)).and_return(commits)
+ allow(project).to receive(:commits_by).with(oids: [commit_shas]).and_return(commits)
allow(commits.first).to receive(:signature_type).and_return(:PGP)
end
@@ -78,35 +79,65 @@ describe CreateCommitSignatureWorker do
expect(gpg_commit).to receive(:signature).once
- described_class.new.perform(commit_shas.first, project.id)
+ subject
end
end
context 'when Commit is not found' do
let(:nonexisting_commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a34' }
+ let(:commit_shas) { [nonexisting_commit_sha] }
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(commit_shas, project.id) }.not_to raise_error
end
end
context 'when Project is not found' do
- let(:nonexisting_project_id) { -1 }
+ let(:commits) { [] }
+ let(:project) { double(id: non_existing_record_id) }
it 'does not raise errors' do
- expect { described_class.new.perform(commit_shas, nonexisting_project_id) }.not_to raise_error
+ expect { subject }.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(commit_shas, nonexisting_project_id)
+ subject
end
it 'does not call Gitlab::X509::Commit#signature' do
expect_any_instance_of(Gitlab::X509::Commit).not_to receive(:signature)
- described_class.new.perform(commit_shas, nonexisting_project_id)
+ subject
+ end
+ end
+
+ context 'fetching signatures' do
+ before do
+ commits.each do |commit|
+ allow(commit).to receive(:signature_type).and_return(type)
+ end
+ end
+
+ context 'X509' do
+ let(:type) { :X509 }
+
+ it 'performs a single query for commit signatures' do
+ expect(X509CommitSignature).to receive(:by_commit_sha).with(commit_shas).once.and_return([])
+
+ subject
+ end
+ end
+
+ context 'PGP' do
+ let(:type) { :PGP }
+
+ it 'performs a single query for commit signatures' do
+ expect(GpgSignature).to receive(:by_commit_sha).with(commit_shas).once.and_return([])
+
+ subject
+ end
end
end
end
diff --git a/spec/workers/expire_pipeline_cache_worker_spec.rb b/spec/workers/expire_pipeline_cache_worker_spec.rb
index 8d898ffc13e..61ea22fbd32 100644
--- a/spec/workers/expire_pipeline_cache_worker_spec.rb
+++ b/spec/workers/expire_pipeline_cache_worker_spec.rb
@@ -11,7 +11,9 @@ describe ExpirePipelineCacheWorker do
describe '#perform' do
it 'executes the service' do
- expect_any_instance_of(Ci::ExpirePipelineCacheService).to receive(:execute).with(pipeline).and_call_original
+ expect_next_instance_of(Ci::ExpirePipelineCacheService) do |instance|
+ expect(instance).to receive(:execute).with(pipeline).and_call_original
+ end
subject.perform(pipeline.id)
end
@@ -31,5 +33,9 @@ describe ExpirePipelineCacheWorker do
subject.perform(pipeline.id)
end
+
+ it_behaves_like 'an idempotent worker' do
+ let(:job_args) { [pipeline.id] }
+ end
end
end
diff --git a/spec/workers/export_csv_worker_spec.rb b/spec/workers/export_csv_worker_spec.rb
new file mode 100644
index 00000000000..87285b6264a
--- /dev/null
+++ b/spec/workers/export_csv_worker_spec.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ExportCsvWorker do
+ let(:user) { create(:user) }
+ let(:project) { create(:project, creator: user) }
+
+ def perform(params = {})
+ described_class.new.perform(user.id, project.id, params)
+ end
+
+ it 'emails a CSV' do
+ expect {perform}.to change(ActionMailer::Base.deliveries, :size).by(1)
+ end
+
+ it 'ensures that project_id is passed to issues_finder' do
+ expect(IssuesFinder).to receive(:new).with(anything, hash_including(project_id: project.id)).and_call_original
+
+ perform
+ end
+
+ it 'removes sort parameter' do
+ expect(IssuesFinder).to receive(:new).with(anything, hash_not_including(:sort)).and_call_original
+
+ perform
+ end
+
+ it 'converts controller string keys to symbol keys for IssuesFinder' do
+ expect(IssuesFinder).to receive(:new).with(anything, hash_including(test_key: true)).and_call_original
+
+ perform('test_key' => true)
+ end
+end
diff --git a/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb
index 93e2a44223b..5c3c7dcccc1 100644
--- a/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb
+++ b/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb
@@ -20,7 +20,7 @@ describe Gitlab::JiraImport::Stage::FinishImportWorker do
end
context 'when feature flag enabled' do
- let_it_be(:jira_import) { create(:jira_import_state, :scheduled, project: project) }
+ let_it_be(:jira_import, reload: true) { create(:jira_import_state, :scheduled, project: project) }
before do
stub_feature_flags(jira_issue_import: true)
@@ -31,15 +31,27 @@ describe Gitlab::JiraImport::Stage::FinishImportWorker do
end
context 'when import started' do
+ let_it_be(:import_label) { create(:label, project: project, title: 'jira-import') }
+ let_it_be(:imported_issues) { create_list(:labeled_issue, 3, project: project, labels: [import_label]) }
+
before do
+ expect(Gitlab::JiraImport).to receive(:get_import_label_id).and_return(import_label.id)
+ expect(Gitlab::JiraImport).to receive(:issue_failures).and_return(2)
+
jira_import.start!
+ worker.perform(project.id)
end
it 'changes import state to finished' do
- worker.perform(project.id)
-
expect(project.jira_import_status).to eq('finished')
end
+
+ it 'saves imported issues counts' do
+ latest_jira_import = project.latest_jira_import
+ expect(latest_jira_import.total_issue_count).to eq(5)
+ expect(latest_jira_import.failed_to_import_count).to eq(2)
+ expect(latest_jira_import.imported_issues_count).to eq(3)
+ end
end
end
end
diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb
index a51e0b79075..3d24b5f753a 100644
--- a/spec/workers/post_receive_spec.rb
+++ b/spec/workers/post_receive_spec.rb
@@ -352,6 +352,9 @@ describe PostReceive do
it "enqueues a UpdateMergeRequestsWorker job" do
allow(Project).to receive(:find_by).and_return(project)
+ expect_next_instance_of(MergeRequests::PushedBranchesService) do |service|
+ expect(service).to receive(:execute).and_return(%w(tést))
+ end
expect(UpdateMergeRequestsWorker).to receive(:perform_async).with(project.id, project.owner.id, any_args)