summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
commit8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch)
tree544930fb309b30317ae9797a9683768705d664c4 /spec/workers
parent4b1de649d0168371549608993deac953eb692019 (diff)
downloadgitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/approve_blocked_pending_approval_users_worker_spec.rb31
-rw-r--r--spec/workers/build_finished_worker_spec.rb3
-rw-r--r--spec/workers/ci/test_failure_history_worker_spec.rb47
-rw-r--r--spec/workers/clusters/applications/check_prometheus_health_worker_spec.rb2
-rw-r--r--spec/workers/concerns/gitlab/github_import/object_importer_spec.rb72
-rw-r--r--spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb72
-rw-r--r--spec/workers/concerns/reenqueuer_spec.rb8
-rw-r--r--spec/workers/environments/canary_ingress/update_worker_spec.rb33
-rw-r--r--spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb2
-rw-r--r--spec/workers/gitlab/github_import/import_issue_worker_spec.rb2
-rw-r--r--spec/workers/gitlab/github_import/import_note_worker_spec.rb2
-rw-r--r--spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb23
-rw-r--r--spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb23
-rw-r--r--spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb2
-rw-r--r--spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb12
-rw-r--r--spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb35
-rw-r--r--spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb52
-rw-r--r--spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb2
-rw-r--r--spec/workers/gitlab_performance_bar_stats_worker_spec.rb30
-rw-r--r--spec/workers/gitlab_usage_ping_worker_spec.rb7
-rw-r--r--spec/workers/import_issues_csv_worker_spec.rb10
-rw-r--r--spec/workers/jira_connect/sync_branch_worker_spec.rb9
-rw-r--r--spec/workers/jira_connect/sync_builds_worker_spec.rb60
-rw-r--r--spec/workers/jira_connect/sync_merge_request_worker_spec.rb9
-rw-r--r--spec/workers/jira_connect/sync_project_worker_spec.rb10
-rw-r--r--spec/workers/member_invitation_reminder_emails_worker_spec.rb26
-rw-r--r--spec/workers/namespaces/onboarding_user_added_worker_spec.rb16
-rw-r--r--spec/workers/post_receive_spec.rb83
-rw-r--r--spec/workers/project_cache_worker_spec.rb14
-rw-r--r--spec/workers/project_export_worker_spec.rb81
-rw-r--r--spec/workers/project_schedule_bulk_repository_shard_moves_worker_spec.rb33
-rw-r--r--spec/workers/purge_dependency_proxy_cache_worker_spec.rb8
-rw-r--r--spec/workers/releases/create_evidence_worker_spec.rb (renamed from spec/workers/create_evidence_worker_spec.rb)2
-rw-r--r--spec/workers/releases/manage_evidence_worker_spec.rb43
-rw-r--r--spec/workers/repository_import_worker_spec.rb2
-rw-r--r--spec/workers/repository_remove_remote_worker_spec.rb2
-rw-r--r--spec/workers/repository_update_remote_mirror_worker_spec.rb9
37 files changed, 684 insertions, 193 deletions
diff --git a/spec/workers/approve_blocked_pending_approval_users_worker_spec.rb b/spec/workers/approve_blocked_pending_approval_users_worker_spec.rb
new file mode 100644
index 00000000000..bd603bd870d
--- /dev/null
+++ b/spec/workers/approve_blocked_pending_approval_users_worker_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ApproveBlockedPendingApprovalUsersWorker, type: :worker do
+ let_it_be(:admin) { create(:admin) }
+ let_it_be(:active_user) { create(:user) }
+ let_it_be(:blocked_user) { create(:user, state: 'blocked_pending_approval') }
+
+ describe '#perform' do
+ subject do
+ described_class.new.perform(admin.id)
+ end
+
+ it 'calls ApproveService for users in blocked_pending_approval state' do
+ expect_next_instance_of(Users::ApproveService, admin) do |service|
+ expect(service).to receive(:execute).with(blocked_user)
+ end
+
+ subject
+ end
+
+ it 'does not call ApproveService for active users' do
+ expect_next_instance_of(Users::ApproveService, admin) do |service|
+ expect(service).not_to receive(:execute).with(active_user)
+ end
+
+ subject
+ end
+ end
+end
diff --git a/spec/workers/build_finished_worker_spec.rb b/spec/workers/build_finished_worker_spec.rb
index b0058c76e27..02e15b7bc22 100644
--- a/spec/workers/build_finished_worker_spec.rb
+++ b/spec/workers/build_finished_worker_spec.rb
@@ -26,9 +26,6 @@ RSpec.describe BuildFinishedWorker do
expect_next_instance_of(Ci::BuildReportResultWorker) do |instance|
expect(instance).to receive(:perform)
end
- expect_next_instance_of(Ci::TestCasesService) do |instance|
- expect(instance).to receive(:execute)
- end
expect(BuildHooksWorker).to receive(:perform_async)
expect(ExpirePipelineCacheWorker).to receive(:perform_async)
diff --git a/spec/workers/ci/test_failure_history_worker_spec.rb b/spec/workers/ci/test_failure_history_worker_spec.rb
new file mode 100644
index 00000000000..d2896c08209
--- /dev/null
+++ b/spec/workers/ci/test_failure_history_worker_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ::Ci::TestFailureHistoryWorker do
+ describe '#perform' do
+ subject(:perform) { described_class.new.perform(pipeline_id) }
+
+ context 'when pipeline exists' do
+ let(:pipeline) { create(:ci_pipeline) }
+ let(:pipeline_id) { pipeline.id }
+
+ it 'executes test failure history service' do
+ expect_next_instance_of(::Ci::TestFailureHistoryService) do |service|
+ expect(service).to receive(:execute)
+ end
+
+ perform
+ end
+ end
+
+ context 'when pipeline does not exist' do
+ let(:pipeline_id) { non_existing_record_id }
+
+ it 'does not execute test failure history service' do
+ expect(Ci::TestFailureHistoryService).not_to receive(:new)
+
+ perform
+ end
+ end
+ end
+
+ include_examples 'an idempotent worker' do
+ let(:pipeline) { create(:ci_pipeline) }
+ let(:job_args) { [pipeline.id] }
+
+ it 'tracks test failures' do
+ # The test report has 2 test case failures
+ create(:ci_build, :failed, :test_reports, pipeline: pipeline, project: pipeline.project)
+
+ subject
+
+ expect(Ci::TestCase.count).to eq(2)
+ expect(Ci::TestCaseFailure.count).to eq(2)
+ end
+ end
+end
diff --git a/spec/workers/clusters/applications/check_prometheus_health_worker_spec.rb b/spec/workers/clusters/applications/check_prometheus_health_worker_spec.rb
index 5a37031a55a..fb779bf3b01 100644
--- a/spec/workers/clusters/applications/check_prometheus_health_worker_spec.rb
+++ b/spec/workers/clusters/applications/check_prometheus_health_worker_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Clusters::Applications::CheckPrometheusHealthWorker, '#perform' d
it 'triggers health service' do
cluster = create(:cluster)
allow(Gitlab::Monitor::DemoProjects).to receive(:primary_keys)
- allow(Clusters::Cluster).to receive_message_chain(:with_application_prometheus, :with_project_alert_service_data).and_return([cluster])
+ allow(Clusters::Cluster).to receive_message_chain(:with_application_prometheus, :with_project_http_integrations).and_return([cluster])
service_instance = instance_double(Clusters::Applications::PrometheusHealthCheckService)
expect(Clusters::Applications::PrometheusHealthCheckService).to receive(:new).with(cluster).and_return(service_instance)
diff --git a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
index d0cbc6b35e2..75f2c7922de 100644
--- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
@@ -22,20 +22,21 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
end
describe '#import' do
- it 'imports the object' do
- representation_class = double(:representation_class)
- importer_class = double(:importer_class)
- importer_instance = double(:importer_instance)
- representation = double(:representation)
- project = double(:project, full_path: 'foo/bar')
- client = double(:client)
-
+ let(:representation_class) { double(:representation_class) }
+ let(:importer_class) { double(:importer_class, name: 'klass_name') }
+ let(:importer_instance) { double(:importer_instance) }
+ let(:representation) { double(:representation) }
+ let(:project) { double(:project, full_path: 'foo/bar', id: 1) }
+ let(:client) { double(:client) }
+
+ before do
expect(worker)
.to receive(:representation_class)
.and_return(representation_class)
expect(worker)
.to receive(:importer_class)
+ .at_least(:once)
.and_return(importer_class)
expect(representation_class)
@@ -47,7 +48,9 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
.to receive(:new)
.with(representation, project, client)
.and_return(importer_instance)
+ end
+ it 'imports the object' do
expect(importer_instance)
.to receive(:execute)
@@ -55,8 +58,61 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
.to receive(:increment)
.and_call_original
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'starting importer',
+ import_source: :github,
+ project_id: 1,
+ importer: 'klass_name'
+ )
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'importer finished',
+ import_source: :github,
+ project_id: 1,
+ importer: 'klass_name'
+ )
+ end
+
worker.import(project, client, { 'number' => 10 })
end
+
+ it 'logs error when the import fails' do
+ exception = StandardError.new('some error')
+ expect(importer_instance)
+ .to receive(:execute)
+ .and_raise(exception)
+
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'starting importer',
+ import_source: :github,
+ project_id: project.id,
+ importer: 'klass_name'
+ )
+ expect(logger)
+ .to receive(:error)
+ .with(
+ message: 'importer failed',
+ import_source: :github,
+ project_id: project.id,
+ importer: 'klass_name',
+ 'error.message': 'some error'
+ )
+ end
+
+ expect(Gitlab::ErrorTracking)
+ .to receive(:track_and_raise_exception)
+ .with(exception, import_source: :github, project_id: 1, importer: 'klass_name')
+ .and_call_original
+
+ expect { worker.import(project, client, { 'number' => 10 }) }.to raise_error(exception)
+ end
end
describe '#counter' do
diff --git a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
index 03e875bcb87..651ea77a71c 100644
--- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
@@ -5,7 +5,13 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::StageMethods do
let(:project) { create(:project) }
let(:worker) do
- Class.new { include(Gitlab::GithubImport::StageMethods) }.new
+ Class.new do
+ def self.name
+ 'DummyStage'
+ end
+
+ include(Gitlab::GithubImport::StageMethods)
+ end.new
end
describe '#perform' do
@@ -30,8 +36,72 @@ RSpec.describe Gitlab::GithubImport::StageMethods do
an_instance_of(Project)
)
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'starting stage',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'stage finished',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ end
+
worker.perform(project.id)
end
+
+ it 'logs error when import fails' do
+ exception = StandardError.new('some error')
+
+ allow(worker)
+ .to receive(:find_project)
+ .with(project.id)
+ .and_return(project)
+
+ expect(worker)
+ .to receive(:try_import)
+ .and_raise(exception)
+
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'starting stage',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ expect(logger)
+ .to receive(:error)
+ .with(
+ message: 'stage failed',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage',
+ 'error.message': 'some error'
+ )
+ end
+
+ expect(Gitlab::ErrorTracking)
+ .to receive(:track_and_raise_exception)
+ .with(
+ exception,
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ .and_call_original
+
+ expect { worker.perform(project.id) }.to raise_error(exception)
+ end
end
describe '#try_import' do
diff --git a/spec/workers/concerns/reenqueuer_spec.rb b/spec/workers/concerns/reenqueuer_spec.rb
index ab44042834f..56db2239bb1 100644
--- a/spec/workers/concerns/reenqueuer_spec.rb
+++ b/spec/workers/concerns/reenqueuer_spec.rb
@@ -79,6 +79,10 @@ RSpec.describe Reenqueuer do
job.perform
end
+
+ it 'returns the original value from #perform' do
+ expect(job.perform).to eq(true)
+ end
end
context 'when #perform returns falsey' do
@@ -87,6 +91,10 @@ RSpec.describe Reenqueuer do
job.perform
end
+
+ it 'returns the original value from #perform' do
+ expect(job.perform).to eq(false)
+ end
end
end
end
diff --git a/spec/workers/environments/canary_ingress/update_worker_spec.rb b/spec/workers/environments/canary_ingress/update_worker_spec.rb
new file mode 100644
index 00000000000..7bc5108719c
--- /dev/null
+++ b/spec/workers/environments/canary_ingress/update_worker_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Environments::CanaryIngress::UpdateWorker do
+ let_it_be(:environment) { create(:environment) }
+ let(:worker) { described_class.new }
+
+ describe '#perform' do
+ subject { worker.perform(environment_id, params) }
+
+ let(:environment_id) { environment.id }
+ let(:params) { { 'weight' => 50 } }
+
+ it 'executes the update service' do
+ expect_next_instance_of(Environments::CanaryIngress::UpdateService, environment.project, nil, params) do |service|
+ expect(service).to receive(:execute).with(environment)
+ end
+
+ subject
+ end
+
+ context 'when an environment does not exist' do
+ let(:environment_id) { non_existing_record_id }
+
+ it 'does not execute the update service' do
+ expect(Environments::CanaryIngress::UpdateService).not_to receive(:new)
+
+ subject
+ end
+ end
+ end
+end
diff --git a/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb b/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb
index 211eba993f7..4039cdac721 100644
--- a/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::GithubImport::ImportDiffNoteWorker do
describe '#import' do
it 'imports a diff note' do
- project = double(:project, full_path: 'foo/bar')
+ project = double(:project, full_path: 'foo/bar', id: 1)
client = double(:client)
importer = double(:importer)
hash = {
diff --git a/spec/workers/gitlab/github_import/import_issue_worker_spec.rb b/spec/workers/gitlab/github_import/import_issue_worker_spec.rb
index 1d285790ee2..c25e89f6928 100644
--- a/spec/workers/gitlab/github_import/import_issue_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/import_issue_worker_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::GithubImport::ImportIssueWorker do
describe '#import' do
it 'imports an issue' do
- project = double(:project, full_path: 'foo/bar')
+ project = double(:project, full_path: 'foo/bar', id: 1)
client = double(:client)
importer = double(:importer)
hash = {
diff --git a/spec/workers/gitlab/github_import/import_note_worker_spec.rb b/spec/workers/gitlab/github_import/import_note_worker_spec.rb
index 618aca4ff0a..bfb40d7c3d3 100644
--- a/spec/workers/gitlab/github_import/import_note_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/import_note_worker_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::GithubImport::ImportNoteWorker do
describe '#import' do
it 'imports a note' do
- project = double(:project, full_path: 'foo/bar')
+ project = double(:project, full_path: 'foo/bar', id: 1)
client = double(:client)
importer = double(:importer)
hash = {
diff --git a/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb
new file mode 100644
index 00000000000..c799c676300
--- /dev/null
+++ b/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::ImportPullRequestMergedByWorker do
+ it { is_expected.to include_module(Gitlab::GithubImport::ObjectImporter) }
+
+ describe '#representation_class' do
+ it { expect(subject.representation_class).to eq(Gitlab::GithubImport::Representation::PullRequest) }
+ end
+
+ describe '#importer_class' do
+ it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequestMergedByImporter) }
+ end
+
+ describe '#counter_name' do
+ it { expect(subject.counter_name).to eq(:github_importer_imported_pull_requests_merged_by) }
+ end
+
+ describe '#counter_description' do
+ it { expect(subject.counter_description).to eq('The number of imported GitHub pull requests merged by') }
+ end
+end
diff --git a/spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb
new file mode 100644
index 00000000000..cd14d6631d5
--- /dev/null
+++ b/spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::ImportPullRequestReviewWorker do
+ it { is_expected.to include_module(Gitlab::GithubImport::ObjectImporter) }
+
+ describe '#representation_class' do
+ it { expect(subject.representation_class).to eq(Gitlab::GithubImport::Representation::PullRequestReview) }
+ end
+
+ describe '#importer_class' do
+ it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequestReviewImporter) }
+ end
+
+ describe '#counter_name' do
+ it { expect(subject.counter_name).to eq(:github_importer_imported_pull_request_reviews) }
+ end
+
+ describe '#counter_description' do
+ it { expect(subject.counter_description).to eq('The number of imported GitHub pull request reviews') }
+ end
+end
diff --git a/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb
index 0f5df302d56..12b21abf910 100644
--- a/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Gitlab::GithubImport::ImportPullRequestWorker do
describe '#import' do
it 'imports a pull request' do
- project = double(:project, full_path: 'foo/bar')
+ project = double(:project, full_path: 'foo/bar', id: 1)
client = double(:client)
importer = double(:importer)
hash = {
diff --git a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb
index c821e0aaa09..2615da2be15 100644
--- a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb
@@ -26,7 +26,17 @@ RSpec.describe Gitlab::GithubImport::Stage::FinishImportWorker do
.to receive(:increment)
.and_call_original
- expect(worker.logger).to receive(:info).with(an_instance_of(String))
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'GitHub project import finished',
+ import_stage: 'Gitlab::GithubImport::Stage::FinishImportWorker',
+ import_source: :github,
+ project_id: project.id,
+ duration_s: a_kind_of(Numeric)
+ )
+ end
worker.report_import_time(project)
end
diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb
new file mode 100644
index 00000000000..6fcb5db2a54
--- /dev/null
+++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker do
+ let(:project) { create(:project) }
+ let(:import_state) { create(:import_state, project: project) }
+ let(:worker) { described_class.new }
+
+ describe '#import' do
+ it 'imports all the pull requests' do
+ importer = double(:importer)
+ client = double(:client)
+ waiter = Gitlab::JobWaiter.new(2, '123')
+
+ expect(Gitlab::GithubImport::Importer::PullRequestsMergedByImporter)
+ .to receive(:new)
+ .with(project, client)
+ .and_return(importer)
+
+ expect(importer)
+ .to receive(:execute)
+ .and_return(waiter)
+
+ expect(import_state)
+ .to receive(:refresh_jid_expiration)
+
+ expect(Gitlab::GithubImport::AdvanceStageWorker)
+ .to receive(:perform_async)
+ .with(project.id, { '123' => 2 }, :pull_request_reviews)
+
+ worker.import(client, project)
+ end
+ end
+end
diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb
new file mode 100644
index 00000000000..7acf1a338d3
--- /dev/null
+++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker do
+ let(:project) { create(:project) }
+ let(:import_state) { create(:import_state, project: project) }
+ let(:worker) { described_class.new }
+ let(:client) { double(:client) }
+
+ describe '#import' do
+ it 'does not import with the feature disabled' do
+ stub_feature_flags(github_import_pull_request_reviews: false)
+
+ expect(Gitlab::JobWaiter)
+ .to receive(:new)
+ .and_return(double(key: '123', jobs_remaining: 0))
+
+ expect(Gitlab::GithubImport::AdvanceStageWorker)
+ .to receive(:perform_async)
+ .with(project.id, { '123' => 0 }, :issues_and_diff_notes)
+
+ worker.import(client, project)
+ end
+
+ it 'imports all the pull request reviews' do
+ stub_feature_flags(github_import_pull_request_reviews: true)
+
+ importer = double(:importer)
+
+ waiter = Gitlab::JobWaiter.new(2, '123')
+
+ expect(Gitlab::GithubImport::Importer::PullRequestsReviewsImporter)
+ .to receive(:new)
+ .with(project, client)
+ .and_return(importer)
+
+ expect(importer)
+ .to receive(:execute)
+ .and_return(waiter)
+
+ expect(import_state)
+ .to receive(:refresh_jid_expiration)
+
+ expect(Gitlab::GithubImport::AdvanceStageWorker)
+ .to receive(:perform_async)
+ .with(project.id, { '123' => 2 }, :issues_and_diff_notes)
+
+ worker.import(client, project)
+ end
+ end
+end
diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb
index 0acbca7032c..29578f9bf37 100644
--- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb
@@ -27,7 +27,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do
expect(Gitlab::GithubImport::AdvanceStageWorker)
.to receive(:perform_async)
- .with(project.id, { '123' => 2 }, :issues_and_diff_notes)
+ .with(project.id, { '123' => 2 }, :pull_requests_merged_by)
worker.import(client, project)
end
diff --git a/spec/workers/gitlab_performance_bar_stats_worker_spec.rb b/spec/workers/gitlab_performance_bar_stats_worker_spec.rb
new file mode 100644
index 00000000000..367003dd1ad
--- /dev/null
+++ b/spec/workers/gitlab_performance_bar_stats_worker_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabPerformanceBarStatsWorker do
+ include ExclusiveLeaseHelpers
+
+ subject(:worker) { described_class.new }
+
+ describe '#perform' do
+ let(:redis) { double(Gitlab::Redis::SharedState) }
+ let(:uuid) { 1 }
+
+ before do
+ expect(Gitlab::Redis::SharedState).to receive(:with).and_yield(redis)
+ expect_to_cancel_exclusive_lease(GitlabPerformanceBarStatsWorker::LEASE_KEY, uuid)
+ end
+
+ it 'fetches list of request ids and processes them' do
+ expect(redis).to receive(:smembers).with(GitlabPerformanceBarStatsWorker::STATS_KEY).and_return([1, 2])
+ expect(redis).to receive(:del).with(GitlabPerformanceBarStatsWorker::STATS_KEY)
+ expect_next_instance_of(Gitlab::PerformanceBar::Stats) do |stats|
+ expect(stats).to receive(:process).with(1)
+ expect(stats).to receive(:process).with(2)
+ end
+
+ worker.perform(uuid)
+ end
+ end
+end
diff --git a/spec/workers/gitlab_usage_ping_worker_spec.rb b/spec/workers/gitlab_usage_ping_worker_spec.rb
index a180d29fd5f..f282b20363c 100644
--- a/spec/workers/gitlab_usage_ping_worker_spec.rb
+++ b/spec/workers/gitlab_usage_ping_worker_spec.rb
@@ -8,6 +8,13 @@ RSpec.describe GitlabUsagePingWorker, :clean_gitlab_redis_shared_state do
allow(subject).to receive(:sleep)
end
+ it 'does not run for GitLab.com' do
+ allow(Gitlab).to receive(:com?).and_return(true)
+ expect(SubmitUsagePingService).not_to receive(:new)
+
+ subject.perform
+ end
+
it 'delegates to SubmitUsagePingService' do
expect_next_instance_of(SubmitUsagePingService) { |service| expect(service).to receive(:execute) }
diff --git a/spec/workers/import_issues_csv_worker_spec.rb b/spec/workers/import_issues_csv_worker_spec.rb
index c5420b00e8a..6a698af49c0 100644
--- a/spec/workers/import_issues_csv_worker_spec.rb
+++ b/spec/workers/import_issues_csv_worker_spec.rb
@@ -3,9 +3,9 @@
require 'spec_helper'
RSpec.describe ImportIssuesCsvWorker do
- let(:project) { create(:project) }
- let(:user) { create(:user) }
- let(:upload) { create(:upload) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+ let(:upload) { create(:upload, :with_file) }
let(:worker) { described_class.new }
@@ -19,5 +19,9 @@ RSpec.describe ImportIssuesCsvWorker do
expect { upload.reload }.to raise_error ActiveRecord::RecordNotFound
end
+
+ it_behaves_like 'an idempotent worker' do
+ let(:job_args) { [user.id, project.id, upload.id] }
+ end
end
end
diff --git a/spec/workers/jira_connect/sync_branch_worker_spec.rb b/spec/workers/jira_connect/sync_branch_worker_spec.rb
index 4aa2f89de7b..c8453064b0d 100644
--- a/spec/workers/jira_connect/sync_branch_worker_spec.rb
+++ b/spec/workers/jira_connect/sync_branch_worker_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe JiraConnect::SyncBranchWorker do
+ include AfterNextHelpers
+
describe '#perform' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
@@ -67,7 +69,7 @@ RSpec.describe JiraConnect::SyncBranchWorker do
context 'with update_sequence_id' do
let(:update_sequence_id) { 1 }
- let(:request_url) { 'https://sample.atlassian.net/rest/devinfo/0.10/bulk' }
+ let(:request_path) { '/rest/devinfo/0.10/bulk' }
let(:request_body) do
{
repositories: [
@@ -78,14 +80,13 @@ RSpec.describe JiraConnect::SyncBranchWorker do
update_sequence_id: update_sequence_id
)
]
- }.to_json
+ }
end
subject { described_class.new.perform(project_id, branch_name, commit_shas, update_sequence_id) }
it 'sends the reqeust with custom update_sequence_id' do
- expect(Atlassian::JiraConnect::Client).to receive(:post)
- .with(URI(request_url), headers: anything, body: request_body)
+ expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body)
subject
end
diff --git a/spec/workers/jira_connect/sync_builds_worker_spec.rb b/spec/workers/jira_connect/sync_builds_worker_spec.rb
new file mode 100644
index 00000000000..7c58803d778
--- /dev/null
+++ b/spec/workers/jira_connect/sync_builds_worker_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ::JiraConnect::SyncBuildsWorker do
+ include AfterNextHelpers
+ include ServicesHelper
+
+ describe '#perform' do
+ let_it_be(:pipeline) { create(:ci_pipeline) }
+
+ let(:sequence_id) { Random.random_number(1..10_000) }
+ let(:pipeline_id) { pipeline.id }
+
+ subject { described_class.new.perform(pipeline_id, sequence_id) }
+
+ context 'when pipeline exists' do
+ it 'calls the Jira sync service' do
+ expect_next(::JiraConnect::SyncService, pipeline.project)
+ .to receive(:execute).with(pipelines: contain_exactly(pipeline), update_sequence_id: sequence_id)
+
+ subject
+ end
+ end
+
+ context 'when pipeline does not exist' do
+ let(:pipeline_id) { non_existing_record_id }
+
+ it 'does not call the sync service' do
+ expect_next(::JiraConnect::SyncService).not_to receive(:execute)
+
+ subject
+ end
+ end
+
+ context 'when the feature flag is disabled' do
+ before do
+ stub_feature_flags(jira_sync_builds: false)
+ end
+
+ it 'does not call the sync service' do
+ expect_next(::JiraConnect::SyncService).not_to receive(:execute)
+
+ subject
+ end
+ end
+
+ context 'when the feature flag is enabled for this project' do
+ before do
+ stub_feature_flags(jira_sync_builds: pipeline.project)
+ end
+
+ it 'calls the sync service' do
+ expect_next(::JiraConnect::SyncService).to receive(:execute)
+
+ subject
+ end
+ end
+ end
+end
diff --git a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb
index b3c0db4f260..1a40aa2b3ad 100644
--- a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb
+++ b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe JiraConnect::SyncMergeRequestWorker do
+ include AfterNextHelpers
+
describe '#perform' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
@@ -33,7 +35,7 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do
context 'with update_sequence_id' do
let(:update_sequence_id) { 1 }
- let(:request_url) { 'https://sample.atlassian.net/rest/devinfo/0.10/bulk' }
+ let(:request_path) { '/rest/devinfo/0.10/bulk' }
let(:request_body) do
{
repositories: [
@@ -43,14 +45,13 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do
update_sequence_id: update_sequence_id
)
]
- }.to_json
+ }
end
subject { described_class.new.perform(merge_request_id, update_sequence_id) }
it 'sends the request with custom update_sequence_id' do
- expect(Atlassian::JiraConnect::Client).to receive(:post)
- .with(URI(request_url), headers: anything, body: request_body)
+ expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body)
subject
end
diff --git a/spec/workers/jira_connect/sync_project_worker_spec.rb b/spec/workers/jira_connect/sync_project_worker_spec.rb
index 25210de828c..f7fa565d534 100644
--- a/spec/workers/jira_connect/sync_project_worker_spec.rb
+++ b/spec/workers/jira_connect/sync_project_worker_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep do
end
it_behaves_like 'an idempotent worker' do
- let(:request_url) { 'https://sample.atlassian.net/rest/devinfo/0.10/bulk' }
+ let(:request_path) { '/rest/devinfo/0.10/bulk' }
let(:request_body) do
{
repositories: [
@@ -46,13 +46,13 @@ RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep do
update_sequence_id: update_sequence_id
)
]
- }.to_json
+ }
end
it 'sends the request with custom update_sequence_id' do
- expect(Atlassian::JiraConnect::Client).to receive(:post)
- .exactly(IdempotentWorkerHelper::WORKER_EXEC_TIMES).times
- .with(URI(request_url), headers: anything, body: request_body)
+ allow_next_instances_of(Atlassian::JiraConnect::Client, IdempotentWorkerHelper::WORKER_EXEC_TIMES) do |client|
+ expect(client).to receive(:post).with(request_path, request_body)
+ end
subject
end
diff --git a/spec/workers/member_invitation_reminder_emails_worker_spec.rb b/spec/workers/member_invitation_reminder_emails_worker_spec.rb
index bfd08792c7c..bb4ff466584 100644
--- a/spec/workers/member_invitation_reminder_emails_worker_spec.rb
+++ b/spec/workers/member_invitation_reminder_emails_worker_spec.rb
@@ -10,30 +10,12 @@ RSpec.describe MemberInvitationReminderEmailsWorker do
create(:group_member, :invited, created_at: 2.days.ago)
end
- context 'feature flag disabled' do
- before do
- stub_experiment(invitation_reminders: false)
+ it 'executes the invitation reminder email service' do
+ expect_next_instance_of(Members::InvitationReminderEmailService) do |service|
+ expect(service).to receive(:execute)
end
- it 'does not attempt to execute the invitation reminder service' do
- expect(Members::InvitationReminderEmailService).not_to receive(:new)
-
- subject
- end
- end
-
- context 'feature flag enabled' do
- before do
- stub_experiment(invitation_reminders: true)
- end
-
- it 'executes the invitation reminder email service' do
- expect_next_instance_of(Members::InvitationReminderEmailService) do |service|
- expect(service).to receive(:execute)
- end
-
- subject
- end
+ subject
end
end
end
diff --git a/spec/workers/namespaces/onboarding_user_added_worker_spec.rb b/spec/workers/namespaces/onboarding_user_added_worker_spec.rb
new file mode 100644
index 00000000000..03c668259f8
--- /dev/null
+++ b/spec/workers/namespaces/onboarding_user_added_worker_spec.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Namespaces::OnboardingUserAddedWorker, '#perform' do
+ include AfterNextHelpers
+
+ let_it_be(:group) { create(:group) }
+
+ it 'records the event' do
+ expect_next(OnboardingProgressService, group)
+ .to receive(:execute).with(action: :user_added).and_call_original
+
+ expect { subject.perform(group.id) }.to change(NamespaceOnboardingAction, :count).by(1)
+ end
+end
diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb
index 77c1d16428f..5b8d8878a99 100644
--- a/spec/workers/post_receive_spec.rb
+++ b/spec/workers/post_receive_spec.rb
@@ -3,6 +3,9 @@
require 'spec_helper'
RSpec.describe PostReceive do
+ include AfterNextHelpers
+ include ServicesHelper
+
let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" }
let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") }
let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) }
@@ -18,8 +21,8 @@ RSpec.describe PostReceive do
described_class.new.perform(gl_repository, key_id, changes)
end
- context "as a sidekiq worker" do
- it "responds to #perform" do
+ context 'as a sidekiq worker' do
+ it 'responds to #perform' do
expect(described_class.new).to respond_to(:perform)
end
end
@@ -30,7 +33,7 @@ RSpec.describe PostReceive do
"Triggered hook for non-existing gl_repository \"#{gl_repository}\""
end
- it "returns false and logs an error" do
+ it 'returns false and logs an error' do
expect(Gitlab::GitLogger).to receive(:error).with("POST-RECEIVE: #{error_message}")
expect(perform).to be(false)
end
@@ -42,9 +45,7 @@ RSpec.describe PostReceive do
it 'does not log an error' do
expect(Gitlab::GitLogger).not_to receive(:error)
expect(Gitlab::GitPostReceive).to receive(:new).and_call_original
- expect_any_instance_of(described_class) do |instance|
- expect(instance).to receive(:process_snippet_changes)
- end
+ expect_next(described_class).to receive(:process_snippet_changes)
perform
end
@@ -61,13 +62,13 @@ RSpec.describe PostReceive do
end
end
- describe "#process_project_changes" do
+ describe '#process_project_changes' do
context 'with an empty project' do
let(:empty_project) { create(:project, :empty_repo) }
let(:changes) { "123456 789012 refs/heads/tést1\n" }
before do
- allow_any_instance_of(Gitlab::GitPostReceive).to receive(:identify).and_return(empty_project.owner)
+ allow_next(Gitlab::GitPostReceive).to receive(:identify).and_return(empty_project.owner)
# Need to mock here so we can expect calls on project
allow(Gitlab::GlRepository).to receive(:parse).and_return([empty_project, empty_project, Gitlab::GlRepository::PROJECT])
end
@@ -97,9 +98,9 @@ RSpec.describe PostReceive do
end
context 'empty changes' do
- it "does not call any PushService but runs after project hooks" do
+ it 'does not call any PushService but runs after project hooks' do
expect(Git::ProcessRefChangesService).not_to receive(:new)
- expect_next_instance_of(SystemHooksService) { |service| expect(service).to receive(:execute_hooks) }
+ expect_next(SystemHooksService).to receive(:execute_hooks)
perform(changes: "")
end
@@ -121,7 +122,7 @@ RSpec.describe PostReceive do
let(:push_service) { double(execute: true) }
before do
- allow_any_instance_of(Gitlab::GitPostReceive).to receive(:identify).and_return(project.owner)
+ allow_next(Gitlab::GitPostReceive).to receive(:identify).and_return(project.owner)
allow(Gitlab::GlRepository).to receive(:parse).and_return([project, project, Gitlab::GlRepository::PROJECT])
end
@@ -135,7 +136,7 @@ RSpec.describe PostReceive do
end
end
- context "branches" do
+ context 'branches' do
let(:changes) do
<<~EOF
123456 789012 refs/heads/tést1
@@ -157,9 +158,7 @@ RSpec.describe PostReceive do
end
it 'calls Git::ProcessRefChangesService' do
- expect_next_instance_of(Git::ProcessRefChangesService) do |service|
- expect(service).to receive(:execute).and_return(true)
- end
+ expect_next(Git::ProcessRefChangesService).to receive(:execute).and_return(true)
perform
end
@@ -191,7 +190,7 @@ RSpec.describe PostReceive do
end
end
- context "tags" do
+ context 'tags' do
let(:changes) do
<<~EOF
654321 210987 refs/tags/tag1
@@ -219,9 +218,7 @@ RSpec.describe PostReceive do
end
it 'calls Git::ProcessRefChangesService' do
- expect_next_instance_of(Git::ProcessRefChangesService) do |service|
- expect(service).to receive(:execute).and_return(true)
- end
+ expect_execution_of(Git::ProcessRefChangesService)
perform
end
@@ -236,7 +233,7 @@ RSpec.describe PostReceive do
it_behaves_like 'updating remote mirrors'
end
- context "merge-requests" do
+ context 'merge-requests' do
let(:changes) { "123456 789012 refs/merge-requests/123" }
it "does not call any of the services" do
@@ -250,19 +247,19 @@ RSpec.describe PostReceive do
context 'after project changes hooks' do
let(:changes) { '123456 789012 refs/heads/tést' }
- let(:fake_hook_data) { Hash.new(event_name: 'repository_update') }
+ let(:fake_hook_data) { { event_name: 'repository_update' } }
before do
- allow_any_instance_of(Gitlab::DataBuilder::Repository).to receive(:update).and_return(fake_hook_data)
+ allow(Gitlab::DataBuilder::Repository).to receive(:update).and_return(fake_hook_data)
# silence hooks so we can isolate
- allow_any_instance_of(Key).to receive(:post_create_hook).and_return(true)
- expect_next_instance_of(Git::ProcessRefChangesService) do |service|
- expect(service).to receive(:execute).and_return(true)
- end
+ allow_next(Key).to receive(:post_create_hook).and_return(true)
+ expect_execution_of(Git::ProcessRefChangesService)
end
it 'calls SystemHooksService' do
- expect_any_instance_of(SystemHooksService).to receive(:execute_hooks).with(fake_hook_data, :repository_update_hooks).and_return(true)
+ expect_next(SystemHooksService)
+ .to receive(:execute_hooks).with(fake_hook_data, :repository_update_hooks)
+ .and_return(true)
perform
end
@@ -299,7 +296,7 @@ RSpec.describe PostReceive do
end
end
- context "master" do
+ context 'master' do
let(:default_branch) { 'master' }
let(:oldrev) { '012345' }
let(:newrev) { '6789ab' }
@@ -313,18 +310,13 @@ RSpec.describe PostReceive do
let(:raw_repo) { double('RawRepo') }
it 'processes the changes on the master branch' do
- expect_next_instance_of(Git::WikiPushService) do |service|
- expect(service).to receive(:execute).and_call_original
- end
- expect(project.wiki).to receive(:default_branch).twice.and_return(default_branch)
- expect(project.wiki.repository).to receive(:raw).and_return(raw_repo)
- expect(raw_repo).to receive(:raw_changes_between).once.with(oldrev, newrev).and_return([])
+ expect_next(Git::WikiPushService).to receive(:execute)
perform
end
end
- context "branches" do
+ context 'branches' do
let(:changes) do
<<~EOF
123456 789012 refs/heads/tést1
@@ -333,9 +325,7 @@ RSpec.describe PostReceive do
end
before do
- allow_next_instance_of(Git::WikiPushService) do |service|
- allow(service).to receive(:execute)
- end
+ allow_next(Git::WikiPushService).to receive(:execute)
end
it 'expires the branches cache' do
@@ -353,24 +343,21 @@ RSpec.describe PostReceive do
end
end
- context "webhook" do
- it "fetches the correct project" do
+ context 'webhook' do
+ it 'fetches the correct project' do
expect(Project).to receive(:find_by).with(id: project.id)
perform
end
it "does not run if the author is not in the project" do
- allow_any_instance_of(Gitlab::GitPostReceive)
- .to receive(:identify_using_ssh_key)
- .and_return(nil)
-
+ allow_next(Gitlab::GitPostReceive).to receive(:identify_using_ssh_key).and_return(nil)
expect(project).not_to receive(:execute_hooks)
expect(perform).to be_falsey
end
- it "asks the project to trigger all hooks" do
+ it 'asks the project to trigger all hooks' do
create(:project_hook, push_events: true, tag_push_events: true, project: project)
create(:custom_issue_tracker_service, push_events: true, merge_requests_events: false, project: project)
allow(Project).to receive(:find_by).and_return(project)
@@ -381,11 +368,9 @@ RSpec.describe PostReceive do
perform
end
- it "enqueues a UpdateMergeRequestsWorker job" 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_next(MergeRequests::PushedBranchesService).to receive(:execute).and_return(%w(tést))
expect(UpdateMergeRequestsWorker).to receive(:perform_async).with(project.id, project.owner.id, any_args)
diff --git a/spec/workers/project_cache_worker_spec.rb b/spec/workers/project_cache_worker_spec.rb
index 0f91f7af255..7f42c700ce4 100644
--- a/spec/workers/project_cache_worker_spec.rb
+++ b/spec/workers/project_cache_worker_spec.rb
@@ -5,8 +5,9 @@ require 'spec_helper'
RSpec.describe ProjectCacheWorker do
include ExclusiveLeaseHelpers
+ let_it_be(:project) { create(:project, :repository) }
+
let(:worker) { described_class.new }
- let(:project) { create(:project, :repository) }
let(:lease_key) { ["project_cache_worker", project.id, *statistics.sort].join(":") }
let(:lease_timeout) { ProjectCacheWorker::LEASE_TIMEOUT }
let(:statistics) { [] }
@@ -126,4 +127,15 @@ RSpec.describe ProjectCacheWorker do
end
end
end
+
+ it_behaves_like 'an idempotent worker' do
+ let(:job_args) { [project.id, %w(readme), %w(repository_size)] }
+
+ it 'calls Projects::UpdateStatisticsService service twice', :clean_gitlab_redis_shared_state do
+ expect(Projects::UpdateStatisticsService).to receive(:new).once.and_return(double(execute: true))
+ expect(UpdateProjectStatisticsWorker).to receive(:perform_in).once
+
+ subject
+ end
+ end
end
diff --git a/spec/workers/project_export_worker_spec.rb b/spec/workers/project_export_worker_spec.rb
index defecefc3cc..9923d8bde7f 100644
--- a/spec/workers/project_export_worker_spec.rb
+++ b/spec/workers/project_export_worker_spec.rb
@@ -3,84 +3,5 @@
require 'spec_helper'
RSpec.describe ProjectExportWorker do
- let!(:user) { create(:user) }
- let!(:project) { create(:project) }
-
- subject { described_class.new }
-
- describe '#perform' do
- before do
- allow_next_instance_of(described_class) do |job|
- allow(job).to receive(:jid).and_return(SecureRandom.hex(8))
- end
- end
-
- context 'when it succeeds' do
- it 'calls the ExportService' do
- expect_next_instance_of(::Projects::ImportExport::ExportService) do |service|
- expect(service).to receive(:execute)
- end
-
- subject.perform(user.id, project.id, { 'klass' => 'Gitlab::ImportExport::AfterExportStrategies::DownloadNotificationStrategy' })
- end
-
- context 'export job' do
- before do
- allow_next_instance_of(::Projects::ImportExport::ExportService) do |service|
- allow(service).to receive(:execute)
- end
- end
-
- it 'creates an export job record for the project' do
- expect { subject.perform(user.id, project.id, {}) }.to change { project.export_jobs.count }.from(0).to(1)
- end
-
- it 'sets the export job status to started' do
- expect_next_instance_of(ProjectExportJob) do |job|
- expect(job).to receive(:start)
- end
-
- subject.perform(user.id, project.id, {})
- end
-
- it 'sets the export job status to finished' do
- expect_next_instance_of(ProjectExportJob) do |job|
- expect(job).to receive(:finish)
- end
-
- subject.perform(user.id, project.id, {})
- end
- end
- end
-
- context 'when it fails' do
- it 'does not raise an exception when strategy is invalid' do
- expect(::Projects::ImportExport::ExportService).not_to receive(:new)
-
- expect { subject.perform(user.id, project.id, { 'klass' => 'Whatever' }) }.not_to raise_error
- end
-
- it 'does not raise error when project cannot be found' do
- expect { subject.perform(user.id, non_existing_record_id, {}) }.not_to raise_error
- end
-
- it 'does not raise error when user cannot be found' do
- expect { subject.perform(non_existing_record_id, project.id, {}) }.not_to raise_error
- end
- end
- end
-
- describe 'sidekiq options' do
- it 'disables retry' do
- expect(described_class.sidekiq_options['retry']).to eq(false)
- end
-
- it 'disables dead' do
- expect(described_class.sidekiq_options['dead']).to eq(false)
- end
-
- it 'sets default status expiration' do
- expect(described_class.sidekiq_options['status_expiration']).to eq(StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION)
- end
- end
+ it_behaves_like 'export worker'
end
diff --git a/spec/workers/project_schedule_bulk_repository_shard_moves_worker_spec.rb b/spec/workers/project_schedule_bulk_repository_shard_moves_worker_spec.rb
new file mode 100644
index 00000000000..aadfae51906
--- /dev/null
+++ b/spec/workers/project_schedule_bulk_repository_shard_moves_worker_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ProjectScheduleBulkRepositoryShardMovesWorker do
+ describe "#perform" do
+ before do
+ stub_storage_settings('test_second_storage' => { 'path' => 'tmp/tests/extra_storage' })
+
+ allow(ProjectUpdateRepositoryStorageWorker).to receive(:perform_async)
+ end
+
+ let!(:project) { create(:project, :repository).tap { |project| project.track_project_repository } }
+ let(:source_storage_name) { 'default' }
+ let(:destination_storage_name) { 'test_second_storage' }
+
+ include_examples 'an idempotent worker' do
+ let(:job_args) { [source_storage_name, destination_storage_name] }
+
+ it 'schedules project repository storage moves' do
+ expect { subject }.to change(ProjectRepositoryStorageMove, :count).by(1)
+
+ storage_move = project.repository_storage_moves.last!
+
+ expect(storage_move).to have_attributes(
+ source_storage_name: source_storage_name,
+ destination_storage_name: destination_storage_name,
+ state_name: :scheduled
+ )
+ end
+ end
+ end
+end
diff --git a/spec/workers/purge_dependency_proxy_cache_worker_spec.rb b/spec/workers/purge_dependency_proxy_cache_worker_spec.rb
index 9cd3b6636f5..8379b11af8f 100644
--- a/spec/workers/purge_dependency_proxy_cache_worker_spec.rb
+++ b/spec/workers/purge_dependency_proxy_cache_worker_spec.rb
@@ -6,6 +6,7 @@ RSpec.describe PurgeDependencyProxyCacheWorker do
let_it_be(:user) { create(:admin) }
let_it_be(:blob) { create(:dependency_proxy_blob )}
let_it_be(:group, reload: true) { blob.group }
+ let_it_be(:manifest) { create(:dependency_proxy_manifest, group: group )}
let_it_be(:group_id) { group.id }
subject { described_class.new.perform(user.id, group_id) }
@@ -17,8 +18,9 @@ RSpec.describe PurgeDependencyProxyCacheWorker do
describe '#perform' do
shared_examples 'returns nil' do
- it 'returns nil' do
+ it 'returns nil', :aggregate_failures do
expect { subject }.not_to change { group.dependency_proxy_blobs.size }
+ expect { subject }.not_to change { group.dependency_proxy_manifests.size }
expect(subject).to be_nil
end
end
@@ -27,12 +29,14 @@ RSpec.describe PurgeDependencyProxyCacheWorker do
include_examples 'an idempotent worker' do
let(:job_args) { [user.id, group_id] }
- it 'deletes the blobs and returns ok' do
+ it 'deletes the blobs and returns ok', :aggregate_failures do
expect(group.dependency_proxy_blobs.size).to eq(1)
+ expect(group.dependency_proxy_manifests.size).to eq(1)
subject
expect(group.dependency_proxy_blobs.size).to eq(0)
+ expect(group.dependency_proxy_manifests.size).to eq(0)
end
end
end
diff --git a/spec/workers/create_evidence_worker_spec.rb b/spec/workers/releases/create_evidence_worker_spec.rb
index c700c086163..743f2abc8a7 100644
--- a/spec/workers/create_evidence_worker_spec.rb
+++ b/spec/workers/releases/create_evidence_worker_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe CreateEvidenceWorker do
+RSpec.describe Releases::CreateEvidenceWorker do
let(:project) { create(:project, :repository) }
let(:release) { create(:release, project: project) }
let(:pipeline) { create(:ci_empty_pipeline, sha: release.sha, project: project) }
diff --git a/spec/workers/releases/manage_evidence_worker_spec.rb b/spec/workers/releases/manage_evidence_worker_spec.rb
new file mode 100644
index 00000000000..2fbfb6c9dc1
--- /dev/null
+++ b/spec/workers/releases/manage_evidence_worker_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Releases::ManageEvidenceWorker do
+ let(:project) { create(:project, :repository) }
+
+ shared_examples_for 'does not create a new Evidence record' do
+ specify :sidekiq_inline do
+ aggregate_failures do
+ expect(::Releases::CreateEvidenceService).not_to receive(:execute)
+ expect { described_class.new.perform }.to change(Releases::Evidence, :count).by(0)
+ end
+ end
+ end
+
+ context 'when `released_at` in inside the window' do
+ context 'when Evidence has not been created' do
+ let(:release) { create(:release, project: project, released_at: 1.hour.since) }
+
+ it 'creates a new Evidence record', :sidekiq_inline do
+ expect_next_instance_of(::Releases::CreateEvidenceService, release, { pipeline: nil }) do |service|
+ expect(service).to receive(:execute).and_call_original
+ end
+
+ expect { described_class.new.perform }.to change(Releases::Evidence, :count).by(1)
+ end
+ end
+
+ context 'when evidence has already been created' do
+ let(:release) { create(:release, project: project, released_at: 1.hour.since) }
+ let!(:evidence) { create(:evidence, release: release )}
+
+ it_behaves_like 'does not create a new Evidence record'
+ end
+ end
+
+ context 'when `released_at` is outside the window' do
+ let(:release) { create(:release, project: project, released_at: 300.minutes.since) }
+
+ it_behaves_like 'does not create a new Evidence record'
+ end
+end
diff --git a/spec/workers/repository_import_worker_spec.rb b/spec/workers/repository_import_worker_spec.rb
index 4a80f4f9da6..82d975cb85a 100644
--- a/spec/workers/repository_import_worker_spec.rb
+++ b/spec/workers/repository_import_worker_spec.rb
@@ -58,6 +58,7 @@ RSpec.describe RepositoryImportWorker do
subject.perform(project.id)
end.to raise_error(RuntimeError, error)
expect(import_state.reload.jid).not_to be_nil
+ expect(import_state.status).to eq('failed')
end
it 'updates the error on Import/Export' do
@@ -74,6 +75,7 @@ RSpec.describe RepositoryImportWorker do
end.to raise_error(RuntimeError, error)
expect(import_state.reload.last_error).not_to be_nil
+ expect(import_state.status).to eq('failed')
end
end
diff --git a/spec/workers/repository_remove_remote_worker_spec.rb b/spec/workers/repository_remove_remote_worker_spec.rb
index 7d66131f34e..758f7f75e03 100644
--- a/spec/workers/repository_remove_remote_worker_spec.rb
+++ b/spec/workers/repository_remove_remote_worker_spec.rb
@@ -32,7 +32,7 @@ RSpec.describe RepositoryRemoveRemoteWorker do
expect(subject)
.to receive(:log_error)
- .with("Cannot obtain an exclusive lease for #{subject.class.name}. There must be another instance already in execution.")
+ .with("Cannot obtain an exclusive lease for #{lease_key}. There must be another instance already in execution.")
subject.perform(project.id, remote_name)
end
diff --git a/spec/workers/repository_update_remote_mirror_worker_spec.rb b/spec/workers/repository_update_remote_mirror_worker_spec.rb
index 858f5226c48..ef6a8d76d2c 100644
--- a/spec/workers/repository_update_remote_mirror_worker_spec.rb
+++ b/spec/workers/repository_update_remote_mirror_worker_spec.rb
@@ -3,9 +3,8 @@
require 'spec_helper'
RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_state do
- subject { described_class.new }
+ let_it_be(:remote_mirror) { create(:remote_mirror) }
- let(:remote_mirror) { create(:remote_mirror) }
let(:scheduled_time) { Time.current - 5.minutes }
around do |example|
@@ -19,6 +18,8 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st
end
describe '#perform' do
+ subject { described_class.new }
+
it 'calls out to the service to perform the update' do
expect_mirror_service_to_return(remote_mirror, status: :success)
@@ -68,4 +69,8 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st
subject.perform(remote_mirror.id, scheduled_time)
end
end
+
+ include_examples 'an idempotent worker' do
+ let(:job_args) { [remote_mirror.id, scheduled_time] }
+ end
end