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>2022-07-20 18:40:28 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-20 18:40:28 +0300
commitb595cb0c1dec83de5bdee18284abe86614bed33b (patch)
tree8c3d4540f193c5ff98019352f554e921b3a41a72 /spec/workers
parent2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff)
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/build_finished_worker_spec.rb13
-rw-r--r--spec/workers/build_hooks_worker_spec.rb19
-rw-r--r--spec/workers/bulk_imports/pipeline_worker_spec.rb66
-rw-r--r--spec/workers/ci/archive_trace_worker_spec.rb17
-rw-r--r--spec/workers/ci/build_finished_worker_spec.rb13
-rw-r--r--spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb43
-rw-r--r--spec/workers/clusters/applications/activate_integration_worker_spec.rb9
-rw-r--r--spec/workers/clusters/applications/deactivate_integration_worker_spec.rb9
-rw-r--r--spec/workers/concerns/gitlab/github_import/object_importer_spec.rb22
-rw-r--r--spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb32
-rw-r--r--spec/workers/concerns/waitable_worker_spec.rb53
-rw-r--r--spec/workers/container_registry/migration/enqueuer_worker_spec.rb2
-rw-r--r--spec/workers/disallow_two_factor_for_group_worker_spec.rb2
-rw-r--r--spec/workers/every_sidekiq_worker_spec.rb8
-rw-r--r--spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb3
-rw-r--r--spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb51
-rw-r--r--spec/workers/gitlab/github_import/import_issue_worker_spec.rb3
-rw-r--r--spec/workers/gitlab/github_import/import_note_worker_spec.rb3
-rw-r--r--spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb3
-rw-r--r--spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb48
-rw-r--r--spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb2
-rw-r--r--spec/workers/gitlab_service_ping_worker_spec.rb25
-rw-r--r--spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb50
-rw-r--r--spec/workers/incident_management/close_incident_worker_spec.rb65
-rw-r--r--spec/workers/integrations/execute_worker_spec.rb22
-rw-r--r--spec/workers/integrations/irker_worker_spec.rb6
-rw-r--r--spec/workers/loose_foreign_keys/cleanup_worker_spec.rb2
-rw-r--r--spec/workers/namespaces/onboarding_issue_created_worker_spec.rb2
-rw-r--r--spec/workers/packages/cleanup/execute_policy_worker_spec.rb160
-rw-r--r--spec/workers/packages/cleanup_package_file_worker_spec.rb5
-rw-r--r--spec/workers/packages/cleanup_package_registry_worker_spec.rb25
-rw-r--r--spec/workers/packages/debian/generate_distribution_worker_spec.rb6
-rw-r--r--spec/workers/packages/debian/process_changes_worker_spec.rb6
-rw-r--r--spec/workers/pages/invalidate_domain_cache_worker_spec.rb45
-rw-r--r--spec/workers/post_receive_spec.rb26
-rw-r--r--spec/workers/projects/after_import_worker_spec.rb13
-rw-r--r--spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb27
-rw-r--r--spec/workers/remove_expired_group_links_worker_spec.rb41
-rw-r--r--spec/workers/remove_expired_members_worker_spec.rb4
-rw-r--r--spec/workers/stage_update_worker_spec.rb2
-rw-r--r--spec/workers/web_hooks/destroy_worker_spec.rb64
41 files changed, 708 insertions, 309 deletions
diff --git a/spec/workers/build_finished_worker_spec.rb b/spec/workers/build_finished_worker_spec.rb
index b4b986662d2..2ff173c1558 100644
--- a/spec/workers/build_finished_worker_spec.rb
+++ b/spec/workers/build_finished_worker_spec.rb
@@ -12,7 +12,6 @@ RSpec.describe BuildFinishedWorker do
let_it_be(:build) { create(:ci_build, :success, pipeline: create(:ci_pipeline)) }
before do
- stub_feature_flags(ci_build_finished_worker_namespace_changed: build.project)
expect(Ci::Build).to receive(:find_by).with({ id: build.id }).and_return(build)
end
@@ -30,18 +29,6 @@ RSpec.describe BuildFinishedWorker do
subject
end
- context 'with ci_build_finished_worker_namespace_changed feature flag disabled' do
- before do
- stub_feature_flags(ci_build_finished_worker_namespace_changed: false)
- end
-
- it 'calls deprecated worker' do
- expect(ArchiveTraceWorker).to receive(:perform_in)
-
- subject
- end
- end
-
context 'when build is failed' do
before do
build.update!(status: :failed)
diff --git a/spec/workers/build_hooks_worker_spec.rb b/spec/workers/build_hooks_worker_spec.rb
index a69e188b441..426eb03638c 100644
--- a/spec/workers/build_hooks_worker_spec.rb
+++ b/spec/workers/build_hooks_worker_spec.rb
@@ -23,6 +23,25 @@ RSpec.describe BuildHooksWorker do
end
end
+ describe '.perform_async' do
+ it 'sends a message to the application logger, before performing', :sidekiq_inline do
+ build = create(:ci_build)
+
+ expect(Gitlab::AppLogger).to receive(:info).with(
+ message: include('Enqueuing hooks for Build'),
+ class: described_class.name,
+ build_id: build.id,
+ pipeline_id: build.pipeline_id,
+ project_id: build.project_id,
+ build_status: build.status
+ )
+
+ expect_any_instance_of(Ci::Build).to receive(:execute_hooks)
+
+ described_class.perform_async(build)
+ end
+ end
+
it_behaves_like 'worker with data consistency',
described_class,
data_consistency: :delayed
diff --git a/spec/workers/bulk_imports/pipeline_worker_spec.rb b/spec/workers/bulk_imports/pipeline_worker_spec.rb
index b5f20e9ff76..fe2039bd79e 100644
--- a/spec/workers/bulk_imports/pipeline_worker_spec.rb
+++ b/spec/workers/bulk_imports/pipeline_worker_spec.rb
@@ -189,7 +189,7 @@ RSpec.describe BulkImports::PipelineWorker do
end
end
- context 'when network error is raised' do
+ context 'when retry pipeline error is raised' do
let(:pipeline_tracker) do
create(
:bulk_import_tracker,
@@ -200,7 +200,7 @@ RSpec.describe BulkImports::PipelineWorker do
end
let(:exception) do
- BulkImports::NetworkError.new(response: instance_double(HTTParty::Response, code: 429, headers: {}))
+ BulkImports::RetryPipelineError.new('Error!', 60)
end
before do
@@ -213,54 +213,36 @@ RSpec.describe BulkImports::PipelineWorker do
end
end
- context 'when error is retriable' do
- it 'reenqueues the worker' do
- expect_any_instance_of(BulkImports::Tracker) do |tracker|
- expect(tracker).to receive(:retry).and_call_original
- end
-
- expect_next_instance_of(Gitlab::Import::Logger) do |logger|
- expect(logger)
- .to receive(:info)
- .with(
- hash_including(
- 'pipeline_name' => 'FakePipeline',
- 'entity_id' => entity.id
- )
- )
- end
+ it 'reenqueues the worker' do
+ expect_any_instance_of(BulkImports::Tracker) do |tracker|
+ expect(tracker).to receive(:retry).and_call_original
+ end
- expect(described_class)
- .to receive(:perform_in)
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
.with(
- 60.seconds,
- pipeline_tracker.id,
- pipeline_tracker.stage,
- pipeline_tracker.entity.id
+ hash_including(
+ 'pipeline_name' => 'FakePipeline',
+ 'entity_id' => entity.id
+ )
)
-
- subject.perform(pipeline_tracker.id, pipeline_tracker.stage, entity.id)
-
- pipeline_tracker.reload
-
- expect(pipeline_tracker.enqueued?).to be_truthy
end
- context 'when error is not retriable' do
- let(:exception) do
- BulkImports::NetworkError.new(response: instance_double(HTTParty::Response, code: 503, headers: {}))
- end
-
- it 'marks tracker as failed and logs the error' do
- expect(described_class).not_to receive(:perform_in)
+ expect(described_class)
+ .to receive(:perform_in)
+ .with(
+ 60.seconds,
+ pipeline_tracker.id,
+ pipeline_tracker.stage,
+ pipeline_tracker.entity.id
+ )
- subject.perform(pipeline_tracker.id, pipeline_tracker.stage, entity.id)
+ subject.perform(pipeline_tracker.id, pipeline_tracker.stage, entity.id)
- pipeline_tracker.reload
+ pipeline_tracker.reload
- expect(pipeline_tracker.failed?).to eq(true)
- end
- end
+ expect(pipeline_tracker.enqueued?).to be_truthy
end
end
end
diff --git a/spec/workers/ci/archive_trace_worker_spec.rb b/spec/workers/ci/archive_trace_worker_spec.rb
index 52723ff5823..3ac769aab9e 100644
--- a/spec/workers/ci/archive_trace_worker_spec.rb
+++ b/spec/workers/ci/archive_trace_worker_spec.rb
@@ -27,23 +27,6 @@ RSpec.describe Ci::ArchiveTraceWorker do
subject
end
-
- context 'when sticky_ci_archive_trace_worker is disabled' do
- before do
- stub_feature_flags(sticky_ci_archive_trace_worker: false)
- end
-
- it 'does not preload associations' do
- allow_next_instance_of(Ci::ArchiveTraceService) do |instance|
- allow(instance).to receive(:execute) do |job|
- expect(job.association(:project)).not_to be_loaded
- expect(job.association(:pending_state)).not_to be_loaded
- end
- end
-
- subject
- end
- end
end
context 'when job is not found' do
diff --git a/spec/workers/ci/build_finished_worker_spec.rb b/spec/workers/ci/build_finished_worker_spec.rb
index e9e7a057f98..201182636e7 100644
--- a/spec/workers/ci/build_finished_worker_spec.rb
+++ b/spec/workers/ci/build_finished_worker_spec.rb
@@ -10,7 +10,6 @@ RSpec.describe Ci::BuildFinishedWorker do
let_it_be(:build) { create(:ci_build, :success, pipeline: create(:ci_pipeline)) }
before do
- stub_feature_flags(ci_build_finished_worker_namespace_changed: build.project)
expect(Ci::Build).to receive(:find_by).with({ id: build.id }).and_return(build)
end
@@ -28,18 +27,6 @@ RSpec.describe Ci::BuildFinishedWorker do
subject
end
- context 'with ci_build_finished_worker_namespace_changed feature flag disabled' do
- before do
- stub_feature_flags(ci_build_finished_worker_namespace_changed: false)
- end
-
- it 'calls deprecated worker' do
- expect(ArchiveTraceWorker).to receive(:perform_in)
-
- subject
- end
- end
-
context 'when build is failed' do
before do
build.update!(status: :failed)
diff --git a/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb
index 000eda055af..7b28384a5bf 100644
--- a/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb
+++ b/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb
@@ -2,28 +2,57 @@
require 'spec_helper'
-RSpec.describe ::Ci::PipelineArtifacts::CoverageReportWorker do
+RSpec.describe Ci::PipelineArtifacts::CoverageReportWorker do
describe '#perform' do
+ let(:pipeline_id) { pipeline.id }
+
subject { described_class.new.perform(pipeline_id) }
context 'when pipeline exists' do
- let(:pipeline) { create(:ci_pipeline) }
- let(:pipeline_id) { pipeline.id }
+ let(:pipeline) { create(:ci_pipeline, :success) }
- it 'calls pipeline report result service' do
- expect_next_instance_of(::Ci::PipelineArtifacts::CoverageReportService) do |create_artifact_service|
- expect(create_artifact_service).to receive(:execute)
+ it 'calls the pipeline coverage report service' do
+ expect_next_instance_of(::Ci::PipelineArtifacts::CoverageReportService, pipeline) do |service|
+ expect(service).to receive(:execute)
end
subject
end
end
+ context 'when the pipeline is part of a hierarchy' do
+ let_it_be(:root_ancestor_pipeline) { create(:ci_pipeline, :success) }
+ let_it_be(:pipeline) { create(:ci_pipeline, :success, child_of: root_ancestor_pipeline) }
+ let_it_be(:another_child_pipeline) { create(:ci_pipeline, :success, child_of: root_ancestor_pipeline) }
+
+ context 'when all pipelines is complete' do
+ it 'calls the pipeline coverage report service on the root ancestor pipeline' do
+ expect_next_instance_of(::Ci::PipelineArtifacts::CoverageReportService, root_ancestor_pipeline) do |service|
+ expect(service).to receive(:execute)
+ end
+
+ subject
+ end
+ end
+
+ context 'when the pipeline hierarchy has incomplete pipeline' do
+ before do
+ another_child_pipeline.update!(status: :running)
+ end
+
+ it 'does not call pipeline coverage report service' do
+ expect(Ci::PipelineArtifacts::CoverageReportService).not_to receive(:new)
+
+ subject
+ end
+ end
+ end
+
context 'when pipeline does not exist' do
let(:pipeline_id) { non_existing_record_id }
it 'does not call pipeline create artifact service' do
- expect(Ci::PipelineArtifacts::CoverageReportService).not_to receive(:execute)
+ expect(Ci::PipelineArtifacts::CoverageReportService).not_to receive(:new)
subject
end
diff --git a/spec/workers/clusters/applications/activate_integration_worker_spec.rb b/spec/workers/clusters/applications/activate_integration_worker_spec.rb
index ecb49be5a4b..5163e4681fa 100644
--- a/spec/workers/clusters/applications/activate_integration_worker_spec.rb
+++ b/spec/workers/clusters/applications/activate_integration_worker_spec.rb
@@ -40,15 +40,6 @@ RSpec.describe Clusters::Applications::ActivateIntegrationWorker, '#perform' do
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
end
-
- context 'when using the old worker class' do
- let(:described_class) { Clusters::Applications::ActivateServiceWorker }
-
- it 'ensures Prometheus integration is activated' do
- expect { described_class.new.perform(cluster.id, integration_name) }
- .to change { project.reload.prometheus_integration&.active }.from(nil).to(true)
- end
- end
end
end
end
diff --git a/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb b/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb
index 3f0188eee23..62792a3b7d9 100644
--- a/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb
+++ b/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb
@@ -46,15 +46,6 @@ RSpec.describe Clusters::Applications::DeactivateIntegrationWorker, '#perform' d
expect { described_class.new.perform(cluster.id, integration_name) }
.to change { prometheus_integration.reload.active }.from(true).to(false)
end
-
- context 'when using the old worker class' do
- let(:described_class) { Clusters::Applications::ActivateServiceWorker }
-
- it 'ensures Prometheus integration is deactivated' do
- expect { described_class.new.perform(cluster.id, integration_name) }
- .to change { prometheus_integration.reload.active }.from(true).to(false)
- end
- end
end
end
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 3cd82b8bf4d..5a32c1b40bb 100644
--- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
@@ -22,6 +22,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do
end
let_it_be(:project) { create(:project, :import_started) }
+ let_it_be(:project2) { create(:project, :import_canceled) }
let(:importer_class) { double(:importer_class, name: 'klass_name') }
let(:importer_instance) { double(:importer_instance) }
@@ -110,6 +111,27 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do
})
end
+ it 'logs info if the import state is canceled' do
+ expect(project2.import_state.status).to eq('canceled')
+
+ expect(importer_class).not_to receive(:new)
+
+ expect(importer_instance).not_to receive(:execute)
+
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
+ .with(
+ {
+ github_identifiers: nil,
+ message: 'project import canceled',
+ project_id: project2.id,
+ importer: 'klass_name'
+ }
+ )
+
+ worker.import(project2, client, { 'number' => 11, 'github_id' => 2 } )
+ end
+
it 'logs error when the import fails' do
expect(importer_class)
.to receive(:new)
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 1e088929f66..0ac1733781a 100644
--- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::StageMethods do
let_it_be(:project) { create(:project, :import_started, import_url: 'https://t0ken@github.com/repo/repo.git') }
+ let_it_be(:project2) { create(:project, :import_canceled) }
let(:worker) do
Class.new do
@@ -22,6 +23,37 @@ RSpec.describe Gitlab::GithubImport::StageMethods do
worker.perform(-1)
end
+ it 'returns if the import state is canceled' do
+ allow(worker)
+ .to receive(:find_project)
+ .with(project2.id)
+ .and_return(project2)
+
+ expect(worker).not_to receive(:try_import)
+
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
+ .with(
+ {
+ message: 'starting stage',
+ project_id: project2.id,
+ import_stage: 'DummyStage'
+ }
+ )
+
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
+ .with(
+ {
+ message: 'project import canceled',
+ project_id: project2.id,
+ import_stage: 'DummyStage'
+ }
+ )
+
+ worker.perform(project2.id)
+ end
+
it 'imports the data when the project exists' do
allow(worker)
.to receive(:find_project)
diff --git a/spec/workers/concerns/waitable_worker_spec.rb b/spec/workers/concerns/waitable_worker_spec.rb
index 824ae8fcf83..f6d4cc4679d 100644
--- a/spec/workers/concerns/waitable_worker_spec.rb
+++ b/spec/workers/concerns/waitable_worker_spec.rb
@@ -29,40 +29,41 @@ RSpec.describe WaitableWorker do
subject(:job) { worker.new }
describe '.bulk_perform_and_wait' do
- it 'schedules the jobs and waits for them to complete' do
- worker.bulk_perform_and_wait([[1], [2]])
-
- expect(worker.counter).to eq(3)
+ context '1 job' do
+ it 'inlines the job' do
+ args_list = [[1]]
+ expect(worker).to receive(:bulk_perform_inline).with(args_list).and_call_original
+ expect(Gitlab::AppJsonLogger).to(
+ receive(:info).with(a_hash_including('message' => 'running inline',
+ 'class' => 'Gitlab::Foo::Bar::DummyWorker',
+ 'job_status' => 'running',
+ 'queue' => 'foo_bar_dummy'))
+ .once)
+
+ worker.bulk_perform_and_wait(args_list)
+
+ expect(worker.counter).to eq(1)
+ end
end
- it 'inlines workloads <= 3 jobs' do
- args_list = [[1], [2], [3]]
- expect(worker).to receive(:bulk_perform_inline).with(args_list).and_call_original
- expect(Gitlab::AppJsonLogger).to(
- receive(:info).with(a_hash_including('message' => 'running inline',
- 'class' => 'Gitlab::Foo::Bar::DummyWorker',
- 'job_status' => 'running',
- 'queue' => 'foo_bar_dummy'))
- .exactly(3).times)
-
- worker.bulk_perform_and_wait(args_list)
+ context 'between 2 and 3 jobs' do
+ it 'runs the jobs asynchronously' do
+ arguments = [[1], [2], [3]]
- expect(worker.counter).to eq(6)
- end
-
- it 'runs > 3 jobs using sidekiq and a waiter key' do
- expect(worker).to receive(:bulk_perform_async)
- .with([[1, anything], [2, anything], [3, anything], [4, anything]])
+ expect(worker).to receive(:bulk_perform_async).with(arguments)
- worker.bulk_perform_and_wait([[1], [2], [3], [4]])
+ worker.bulk_perform_and_wait(arguments)
+ end
end
- it 'runs > 10 * timeout jobs using sidekiq and no waiter key' do
- arguments = 1.upto(21).map { |i| [i] }
+ context '>= 4 jobs' do
+ it 'runs jobs using sidekiq' do
+ arguments = 1.upto(5).map { |i| [i] }
- expect(worker).to receive(:bulk_perform_async).with(arguments)
+ expect(worker).to receive(:bulk_perform_async).with(arguments)
- worker.bulk_perform_and_wait(arguments, timeout: 2)
+ worker.bulk_perform_and_wait(arguments)
+ end
end
end
diff --git a/spec/workers/container_registry/migration/enqueuer_worker_spec.rb b/spec/workers/container_registry/migration/enqueuer_worker_spec.rb
index ab3bd8f75d4..c2381c0ced7 100644
--- a/spec/workers/container_registry/migration/enqueuer_worker_spec.rb
+++ b/spec/workers/container_registry/migration/enqueuer_worker_spec.rb
@@ -158,7 +158,7 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures
expect(worker).to receive(:handle_next_migration).exactly(3).times.and_call_original
- expect { subject }.to make_queries_matching(/LIMIT 2/)
+ expect { subject }.to make_queries_matching(/LIMIT 25/)
expect(container_repository.reload).to be_pre_importing
expect(container_repository2.reload).to be_pre_importing
diff --git a/spec/workers/disallow_two_factor_for_group_worker_spec.rb b/spec/workers/disallow_two_factor_for_group_worker_spec.rb
index a69dd893f81..f30b12dd7f4 100644
--- a/spec/workers/disallow_two_factor_for_group_worker_spec.rb
+++ b/spec/workers/disallow_two_factor_for_group_worker_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe DisallowTwoFactorForGroupWorker do
end
it "updates group members" do
- group.add_user(user, GroupMember::DEVELOPER)
+ group.add_member(user, GroupMember::DEVELOPER)
described_class.new.perform(group.id)
diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb
index a9e886de52a..e8ec7c28537 100644
--- a/spec/workers/every_sidekiq_worker_spec.rb
+++ b/spec/workers/every_sidekiq_worker_spec.rb
@@ -181,9 +181,7 @@ RSpec.describe 'Every Sidekiq worker' do
'ClusterWaitForAppUpdateWorker' => 3,
'ClusterWaitForIngressIpAddressWorker' => 3,
'Clusters::Applications::ActivateIntegrationWorker' => 3,
- 'Clusters::Applications::ActivateServiceWorker' => 3,
'Clusters::Applications::DeactivateIntegrationWorker' => 3,
- 'Clusters::Applications::DeactivateServiceWorker' => 3,
'Clusters::Applications::UninstallWorker' => 3,
'Clusters::Applications::WaitForUninstallAppWorker' => 3,
'Clusters::Cleanup::AppWorker' => 3,
@@ -261,6 +259,7 @@ RSpec.describe 'Every Sidekiq worker' do
'Gitlab::GithubImport::AdvanceStageWorker' => 3,
'Gitlab::GithubImport::ImportDiffNoteWorker' => 5,
'Gitlab::GithubImport::ImportIssueWorker' => 5,
+ 'Gitlab::GithubImport::ImportIssueEventWorker' => 5,
'Gitlab::GithubImport::ImportLfsObjectWorker' => 5,
'Gitlab::GithubImport::ImportNoteWorker' => 5,
'Gitlab::GithubImport::ImportPullRequestMergedByWorker' => 5,
@@ -270,6 +269,7 @@ RSpec.describe 'Every Sidekiq worker' do
'Gitlab::GithubImport::Stage::FinishImportWorker' => 5,
'Gitlab::GithubImport::Stage::ImportBaseDataWorker' => 5,
'Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker' => 5,
+ 'Gitlab::GithubImport::Stage::ImportIssueEventsWorker' => 5,
'Gitlab::GithubImport::Stage::ImportLfsObjectsWorker' => 5,
'Gitlab::GithubImport::Stage::ImportNotesWorker' => 5,
'Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker' => 5,
@@ -310,7 +310,6 @@ RSpec.describe 'Every Sidekiq worker' do
'Integrations::ExecuteWorker' => 3,
'Integrations::IrkerWorker' => 3,
'InvalidGpgSignatureUpdateWorker' => 3,
- 'IrkerWorker' => 3,
'IssuableExportCsvWorker' => 3,
'Issues::PlacementWorker' => 3,
'Issues::RebalancingWorker' => 3,
@@ -358,6 +357,7 @@ RSpec.describe 'Every Sidekiq worker' do
'ObjectStorage::BackgroundMoveWorker' => 5,
'ObjectStorage::MigrateUploadsWorker' => 3,
'Packages::CleanupPackageFileWorker' => 0,
+ 'Packages::Cleanup::ExecutePolicyWorker' => 0,
'Packages::Composer::CacheUpdateWorker' => false,
'Packages::Go::SyncPackagesWorker' => 3,
'Packages::MarkPackageFilesForDestructionWorker' => 3,
@@ -366,7 +366,6 @@ RSpec.describe 'Every Sidekiq worker' do
'Packages::Rubygems::ExtractionWorker' => 3,
'PagesDomainSslRenewalWorker' => 3,
'PagesDomainVerificationWorker' => 3,
- 'PagesTransferWorker' => 3,
'PagesWorker' => 3,
'PersonalAccessTokens::Groups::PolicyWorker' => 3,
'PersonalAccessTokens::Instance::PolicyWorker' => 3,
@@ -381,7 +380,6 @@ RSpec.describe 'Every Sidekiq worker' do
'ProjectExportWorker' => false,
'ProjectImportScheduleWorker' => 1,
'ProjectScheduleBulkRepositoryShardMovesWorker' => 3,
- 'ProjectServiceWorker' => 3,
'ProjectTemplateExportWorker' => false,
'ProjectUpdateRepositoryStorageWorker' => 3,
'Projects::GitGarbageCollectWorker' => false,
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 af15f465107..15bc55c1526 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,8 @@ RSpec.describe Gitlab::GithubImport::ImportDiffNoteWorker do
describe '#import' do
it 'imports a diff note' do
- project = double(:project, full_path: 'foo/bar', id: 1, import_state: nil)
+ import_state = create(:import_state, :started)
+ project = double(:project, full_path: 'foo/bar', id: 1, import_state: import_state)
client = double(:client)
importer = double(:importer)
hash = {
diff --git a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb
new file mode 100644
index 00000000000..03a6503fb84
--- /dev/null
+++ b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker do
+ subject(:worker) { described_class.new }
+
+ describe '#import' do
+ let(:import_state) { create(:import_state, :started) }
+
+ let(:project) do
+ instance_double('Project', full_path: 'foo/bar', id: 1, import_state: import_state)
+ end
+
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+ let(:importer) { instance_double('Gitlab::GithubImport::Importer::IssueEventImporter') }
+
+ let(:event_hash) do
+ {
+ 'id' => 6501124486,
+ 'node_id' => 'CE_lADOHK9fA85If7x0zwAAAAGDf0mG',
+ 'url' => 'https://api.github.com/repos/elhowm/test-import/issues/events/6501124486',
+ 'actor' => { 'id' => 4, 'login' => 'alice' },
+ 'event' => 'closed',
+ 'commit_id' => nil,
+ 'commit_url' => nil,
+ 'created_at' => '2022-04-26 18:30:53 UTC',
+ 'performed_via_github_app' => nil
+ }
+ end
+
+ it 'imports an issue event' do
+ expect(Gitlab::GithubImport::Importer::IssueEventImporter)
+ .to receive(:new)
+ .with(
+ an_instance_of(Gitlab::GithubImport::Representation::IssueEvent),
+ project,
+ client
+ )
+ .and_return(importer)
+
+ expect(importer).to receive(:execute)
+
+ expect(Gitlab::GithubImport::ObjectCounter)
+ .to receive(:increment)
+ .and_call_original
+
+ worker.import(project, client, event_hash)
+ end
+ end
+end
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 29f21c1d184..c2a7639fde4 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,8 @@ RSpec.describe Gitlab::GithubImport::ImportIssueWorker do
describe '#import' do
it 'imports an issue' do
- project = double(:project, full_path: 'foo/bar', id: 1, import_state: nil)
+ import_state = create(:import_state, :started)
+ project = double(:project, full_path: 'foo/bar', id: 1, import_state: import_state)
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 f4598340938..16ca5658f77 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,8 @@ RSpec.describe Gitlab::GithubImport::ImportNoteWorker do
describe '#import' do
it 'imports a note' do
- project = double(:project, full_path: 'foo/bar', id: 1, import_state: nil)
+ import_state = create(:import_state, :started)
+ project = double(:project, full_path: 'foo/bar', id: 1, import_state: import_state)
client = double(:client)
importer = double(:importer)
hash = {
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 faed2f8f340..59f45b437c4 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,8 @@ RSpec.describe Gitlab::GithubImport::ImportPullRequestWorker do
describe '#import' do
it 'imports a pull request' do
- project = double(:project, full_path: 'foo/bar', id: 1, import_state: nil)
+ import_state = create(:import_state, :started)
+ project = double(:project, full_path: 'foo/bar', id: 1, import_state: import_state)
client = double(:client)
importer = double(:importer)
hash = {
diff --git a/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb
new file mode 100644
index 00000000000..b3c6a48767c
--- /dev/null
+++ b/spec/workers/gitlab/github_import/stage/import_issue_events_worker_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker do
+ subject(:worker) { described_class.new }
+
+ let(:project) { create(:project) }
+ let!(:group) { create(:group, projects: [project]) }
+ let(:feature_flag_state) { [group] }
+
+ describe '#import' do
+ let(:importer) { instance_double('Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter') }
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+
+ before do
+ stub_feature_flags(github_importer_issue_events_import: feature_flag_state)
+ end
+
+ it 'imports all the issue events' do
+ waiter = Gitlab::JobWaiter.new(2, '123')
+
+ expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter)
+ .to receive(:new)
+ .with(project, client)
+ .and_return(importer)
+
+ expect(importer).to receive(:execute).and_return(waiter)
+
+ expect(Gitlab::GithubImport::AdvanceStageWorker)
+ .to receive(:perform_async)
+ .with(project.id, { '123' => 2 }, :notes)
+
+ worker.import(client, project)
+ end
+
+ context 'when feature flag is disabled' do
+ let(:feature_flag_state) { false }
+
+ it 'skips issue events import and calls next stage' do
+ expect(Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter).not_to receive(:new)
+ expect(Gitlab::GithubImport::AdvanceStageWorker).to receive(:perform_async).with(project.id, {}, :notes)
+
+ worker.import(client, project)
+ end
+ end
+ end
+end
diff --git a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb
index c0dd4f488cc..a88256b3cae 100644
--- a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb
@@ -26,7 +26,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker do
expect(Gitlab::GithubImport::AdvanceStageWorker)
.to receive(:perform_async)
- .with(project.id, { '123' => 2 }, :notes)
+ .with(project.id, { '123' => 2 }, :issue_events)
worker.import(client, project)
end
diff --git a/spec/workers/gitlab_service_ping_worker_spec.rb b/spec/workers/gitlab_service_ping_worker_spec.rb
index 057639dcf1d..c88708dc50a 100644
--- a/spec/workers/gitlab_service_ping_worker_spec.rb
+++ b/spec/workers/gitlab_service_ping_worker_spec.rb
@@ -21,29 +21,12 @@ RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do
subject.perform
end
- context 'with prerecord_service_ping_data feature enabled' do
- it 'delegates to ServicePing::SubmitService' do
- stub_feature_flags(prerecord_service_ping_data: true)
-
- expect_next_instance_of(ServicePing::SubmitService, payload: payload) do |service|
- expect(service).to receive(:execute)
- end
-
- subject.perform
+ it 'delegates to ServicePing::SubmitService' do
+ expect_next_instance_of(ServicePing::SubmitService, payload: payload) do |service|
+ expect(service).to receive(:execute)
end
- end
- context 'with prerecord_service_ping_data feature disabled' do
- it 'does not prerecord ServicePing, and calls SubmitService', :aggregate_failures do
- stub_feature_flags(prerecord_service_ping_data: false)
-
- expect(ServicePing::BuildPayload).not_to receive(:new)
- expect(ServicePing::BuildPayload).not_to receive(:new)
- expect_next_instance_of(ServicePing::SubmitService, payload: nil) do |service|
- expect(service).to receive(:execute)
- end
- expect { subject.perform }.not_to change { RawUsageData.count }
- end
+ subject.perform
end
context 'payload computation' do
diff --git a/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb b/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb
new file mode 100644
index 00000000000..5d595a3679b
--- /dev/null
+++ b/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require 'google/apis/sqladmin_v1beta4'
+
+RSpec.describe GoogleCloud::CreateCloudsqlInstanceWorker do
+ let(:random_user) { create(:user) }
+ let(:project) { create(:project) }
+ let(:worker_options) do
+ {
+ gcp_project_id: :gcp_project_id,
+ instance_name: :instance_name,
+ database_version: :database_version,
+ environment_name: :environment_name,
+ is_protected: true
+ }
+ end
+
+ context 'when triggered' do
+ subject do
+ user_id = project.creator.id
+ project_id = project.id
+ described_class.new.perform(user_id, project_id, worker_options)
+ end
+
+ it 'calls GoogleCloud::SetupCloudsqlInstanceService' do
+ allow_next_instance_of(GoogleCloud::SetupCloudsqlInstanceService) do |service|
+ expect(service).to receive(:execute).and_return({ status: :success })
+ end
+
+ subject
+ end
+
+ context 'when GoogleCloud::SetupCloudsqlInstanceService fails' do
+ subject do
+ user_id = random_user.id
+ project_id = project.id
+ described_class.new.perform(user_id, project_id, worker_options)
+ end
+
+ it 'raises error' do
+ allow_next_instance_of(GoogleCloud::SetupCloudsqlInstanceService) do |service|
+ expect(service).to receive(:execute).and_return({ status: :error })
+ end
+
+ expect { subject }.to raise_error(Exception)
+ end
+ end
+ end
+end
diff --git a/spec/workers/incident_management/close_incident_worker_spec.rb b/spec/workers/incident_management/close_incident_worker_spec.rb
new file mode 100644
index 00000000000..b0d284ba5db
--- /dev/null
+++ b/spec/workers/incident_management/close_incident_worker_spec.rb
@@ -0,0 +1,65 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IncidentManagement::CloseIncidentWorker do
+ subject(:worker) { described_class.new }
+
+ describe '#perform' do
+ let_it_be(:user) { User.alert_bot }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:issue, reload: true) { create(:incident, project: project) }
+
+ let(:issue_id) { issue.id }
+
+ it 'calls the close issue service' do
+ expect_next_instance_of(Issues::CloseService, project: project, current_user: user) do |service|
+ expect(service).to receive(:execute).with(issue, system_note: false).and_call_original
+ end
+
+ expect { worker.perform(issue_id) }.to change(ResourceStateEvent, :count).by(1)
+ end
+
+ shared_examples 'does not call the close issue service' do
+ specify do
+ expect(Issues::CloseService).not_to receive(:new)
+
+ expect { worker.perform(issue_id) }.not_to change(ResourceStateEvent, :count)
+ end
+ end
+
+ context 'when the incident does not exist' do
+ let(:issue_id) { non_existing_record_id }
+
+ it_behaves_like 'does not call the close issue service'
+ end
+
+ context 'when issue type is not incident' do
+ before do
+ issue.update!(issue_type: :issue)
+ end
+
+ it_behaves_like 'does not call the close issue service'
+ end
+
+ context 'when incident is not open' do
+ before do
+ issue.close
+ end
+
+ it_behaves_like 'does not call the close issue service'
+ end
+
+ context 'when incident fails to close' do
+ before do
+ allow_next_instance_of(Issues::CloseService) do |service|
+ expect(service).to receive(:close_issue).and_return(issue)
+ end
+ end
+
+ specify do
+ expect { worker.perform(issue_id) }.not_to change(ResourceStateEvent, :count)
+ end
+ end
+ end
+end
diff --git a/spec/workers/integrations/execute_worker_spec.rb b/spec/workers/integrations/execute_worker_spec.rb
index 19600f35c8f..0e585e3006c 100644
--- a/spec/workers/integrations/execute_worker_spec.rb
+++ b/spec/workers/integrations/execute_worker_spec.rb
@@ -36,26 +36,4 @@ RSpec.describe Integrations::ExecuteWorker, '#perform' do
end.not_to raise_error
end
end
-
- context 'when using the old worker class' do
- let(:described_class) { ProjectServiceWorker }
-
- it 'uses the correct worker attributes', :aggregate_failures do
- expect(described_class.sidekiq_options).to include('retry' => 3, 'dead' => false)
- expect(described_class.get_data_consistency).to eq(:always)
- expect(described_class.get_feature_category).to eq(:integrations)
- expect(described_class.get_urgency).to eq(:low)
- expect(described_class.worker_has_external_dependencies?).to be(true)
- end
-
- it 'executes integration with given data' do
- data = { test: 'test' }
-
- expect_next_found_instance_of(integration.class) do |integration|
- expect(integration).to receive(:execute).with(data)
- end
-
- worker.perform(integration.id, data)
- end
- end
end
diff --git a/spec/workers/integrations/irker_worker_spec.rb b/spec/workers/integrations/irker_worker_spec.rb
index 27dc08212ea..3b7b9af72fd 100644
--- a/spec/workers/integrations/irker_worker_spec.rb
+++ b/spec/workers/integrations/irker_worker_spec.rb
@@ -101,12 +101,6 @@ RSpec.describe Integrations::IrkerWorker, '#perform' do
subject.perform(*arguments)
end
end
-
- context 'when using the old worker class' do
- let(:described_class) { ::IrkerWorker }
-
- it { expect(subject.perform(*arguments)).to be_truthy }
- end
end
def wrap_message(text)
diff --git a/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb b/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb
index 632e4fb3071..77190dc49d9 100644
--- a/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb
+++ b/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb
@@ -169,7 +169,7 @@ RSpec.describe LooseForeignKeys::CleanupWorker do
let(:expected_connection) { expected_connection_model.constantize.connection }
before do
- allow(Gitlab::Database).to receive(:database_base_models).and_return(database_base_models)
+ allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(database_base_models)
if database_base_models.has_key?(:ci)
Gitlab::Database::SharedModel.using_connection(database_base_models[:ci].connection) do
diff --git a/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb b/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb
index 32e7bdd563d..53116815ce7 100644
--- a/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb
+++ b/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Namespaces::OnboardingIssueCreatedWorker, '#perform' do
let_it_be(:issue) { create(:issue) }
- let(:namespace) { issue.namespace }
+ let(:namespace) { issue.project.namespace }
it_behaves_like 'records an onboarding progress action', :issue_created do
subject { described_class.new.perform(namespace.id) }
diff --git a/spec/workers/packages/cleanup/execute_policy_worker_spec.rb b/spec/workers/packages/cleanup/execute_policy_worker_spec.rb
new file mode 100644
index 00000000000..81fcec1a360
--- /dev/null
+++ b/spec/workers/packages/cleanup/execute_policy_worker_spec.rb
@@ -0,0 +1,160 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Packages::Cleanup::ExecutePolicyWorker do
+ let(:worker) { described_class.new }
+
+ describe '#perform_work' do
+ subject(:perform_work) { worker.perform_work }
+
+ shared_examples 'not executing any policy' do
+ it 'is a no op' do
+ expect(::Packages::Cleanup::ExecutePolicyService).not_to receive(:new)
+
+ expect { perform_work }.not_to change { Packages::PackageFile.installable.count }
+ end
+ end
+
+ context 'with no policies' do
+ it_behaves_like 'not executing any policy'
+ end
+
+ context 'with no runnable policies' do
+ let_it_be(:policy) { create(:packages_cleanup_policy) }
+
+ it_behaves_like 'not executing any policy'
+ end
+
+ context 'with runnable policies linked to no packages' do
+ let_it_be(:policy) { create(:packages_cleanup_policy, :runnable) }
+
+ it_behaves_like 'not executing any policy'
+ end
+
+ context 'with runnable policies linked to packages' do
+ let_it_be(:policy) { create(:packages_cleanup_policy, :runnable, keep_n_duplicated_package_files: '1') }
+ let_it_be(:package) { create(:package, project: policy.project) }
+
+ let_it_be(:package_file1) { create(:package_file, file_name: 'test1', package: package) }
+ let_it_be(:package_file2) { create(:package_file, file_name: 'test1', package: package) }
+
+ include_examples 'an idempotent worker' do
+ it 'executes the policy' do
+ expect(::Packages::Cleanup::ExecutePolicyService)
+ .to receive(:new).with(policy).and_call_original
+ expect_log_extra_metadata(:project_id, policy.project_id)
+ expect_log_extra_metadata(:execution_timeout, false)
+ expect_log_extra_metadata(:marked_package_files_total_count, 1)
+ expect_log_extra_metadata(:unique_package_id_and_file_name_total_count, 1)
+
+ expect { perform_work }
+ .to change { package.package_files.installable.count }.by(-1)
+ .and change { policy.reload.next_run_at.future? }.from(false).to(true)
+ end
+
+ context 'with a timeout' do
+ let(:mark_service_response) do
+ ServiceResponse.error(
+ message: 'Timeout',
+ payload: { marked_package_files_count: 1 }
+ )
+ end
+
+ it 'executes the policy partially' do
+ expect_next_instance_of(::Packages::MarkPackageFilesForDestructionService) do |service|
+ expect(service).to receive(:execute).and_return(mark_service_response)
+ end
+
+ expect_log_extra_metadata(:project_id, policy.project_id)
+ expect_log_extra_metadata(:execution_timeout, true)
+ expect_log_extra_metadata(:marked_package_files_total_count, 1)
+ expect_log_extra_metadata(:unique_package_id_and_file_name_total_count, 1)
+
+ expect { perform_work }
+ .to change { policy.reload.next_run_at.future? }.from(false).to(true)
+ end
+ end
+ end
+
+ context 'with several eligible policies' do
+ let_it_be(:policy2) { create(:packages_cleanup_policy, :runnable) }
+ let_it_be(:package2) { create(:package, project: policy2.project) }
+
+ before do
+ policy2.update_column(:next_run_at, 100.years.ago)
+ end
+
+ it 'executes the most urgent policy' do
+ expect(::Packages::Cleanup::ExecutePolicyService)
+ .to receive(:new).with(policy2).and_call_original
+ expect_log_extra_metadata(:project_id, policy2.project_id)
+ expect_log_extra_metadata(:execution_timeout, false)
+ expect_log_extra_metadata(:marked_package_files_total_count, 0)
+ expect_log_extra_metadata(:unique_package_id_and_file_name_total_count, 0)
+
+ expect { perform_work }
+ .to change { policy2.reload.next_run_at.future? }.from(false).to(true)
+ .and not_change { policy.reload.next_run_at }
+ end
+ end
+ end
+
+ context 'with runnable policy linked to packages in a disabled state' do
+ let_it_be(:policy) { create(:packages_cleanup_policy, :runnable, keep_n_duplicated_package_files: 'all') }
+ let_it_be(:package) { create(:package, project: policy.project) }
+
+ it_behaves_like 'not executing any policy'
+ end
+
+ def expect_log_extra_metadata(key, value)
+ expect(worker).to receive(:log_extra_metadata_on_done).with(key, value)
+ end
+ end
+
+ describe '#remaining_work_count' do
+ subject { worker.remaining_work_count}
+
+ context 'with no policies' do
+ it { is_expected.to eq(0) }
+ end
+
+ context 'with no runnable policies' do
+ let_it_be(:policy) { create(:packages_cleanup_policy) }
+
+ it { is_expected.to eq(0) }
+ end
+
+ context 'with runnable policies linked to no packages' do
+ let_it_be(:policy) { create(:packages_cleanup_policy, :runnable) }
+
+ it { is_expected.to eq(0) }
+ end
+
+ context 'with runnable policies linked to packages' do
+ let_it_be(:policy) { create(:packages_cleanup_policy, :runnable) }
+ let_it_be(:package) { create(:package, project: policy.project) }
+
+ it { is_expected.to eq(1) }
+ end
+
+ context 'with runnable policy linked to packages in a disabled state' do
+ let_it_be(:policy) { create(:packages_cleanup_policy, :runnable, keep_n_duplicated_package_files: 'all') }
+ let_it_be(:package) { create(:package, project: policy.project) }
+
+ it { is_expected.to eq(0) }
+ end
+ end
+
+ describe '#max_running_jobs' do
+ let(:capacity) { 50 }
+
+ subject { worker.max_running_jobs }
+
+ before do
+ stub_application_setting(package_registry_cleanup_policies_worker_capacity: capacity)
+ end
+
+ it { is_expected.to eq(capacity) }
+ end
+end
diff --git a/spec/workers/packages/cleanup_package_file_worker_spec.rb b/spec/workers/packages/cleanup_package_file_worker_spec.rb
index 380e8916d13..95cf65c18c5 100644
--- a/spec/workers/packages/cleanup_package_file_worker_spec.rb
+++ b/spec/workers/packages/cleanup_package_file_worker_spec.rb
@@ -52,6 +52,7 @@ RSpec.describe Packages::CleanupPackageFileWorker do
end
it 'handles the error' do
+ expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(RuntimeError), class: described_class.name)
expect { subject }.to change { Packages::PackageFile.error.count }.from(0).to(1)
expect(package_file.reload).to be_error
end
@@ -71,7 +72,9 @@ RSpec.describe Packages::CleanupPackageFileWorker do
end
it 'handles the error' do
- expect { subject }.to change { Packages::PackageFile.count }.by(-1)
+ expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(RuntimeError), class: described_class.name)
+ expect { subject }.not_to change { Packages::PackageFile.count }
+ expect(package_file.reload).to be_error
end
end
end
diff --git a/spec/workers/packages/cleanup_package_registry_worker_spec.rb b/spec/workers/packages/cleanup_package_registry_worker_spec.rb
index e43864975f6..e12f2198f66 100644
--- a/spec/workers/packages/cleanup_package_registry_worker_spec.rb
+++ b/spec/workers/packages/cleanup_package_registry_worker_spec.rb
@@ -5,6 +5,8 @@ require 'spec_helper'
RSpec.describe Packages::CleanupPackageRegistryWorker do
describe '#perform' do
let_it_be_with_reload(:package_files) { create_list(:package_file, 2, :pending_destruction) }
+ let_it_be(:policy) { create(:packages_cleanup_policy, :runnable) }
+ let_it_be(:package) { create(:package, project: policy.project) }
let(:worker) { described_class.new }
@@ -34,6 +36,28 @@ RSpec.describe Packages::CleanupPackageRegistryWorker do
end
end
+ context 'with runnable policies' do
+ it_behaves_like 'an idempotent worker'
+
+ it 'queues the cleanup job' do
+ expect(Packages::Cleanup::ExecutePolicyWorker).to receive(:perform_with_capacity)
+
+ perform
+ end
+ end
+
+ context 'with no runnable policies' do
+ before do
+ policy.update_column(:next_run_at, 5.minutes.from_now)
+ end
+
+ it 'does not queue the cleanup job' do
+ expect(Packages::Cleanup::ExecutePolicyWorker).not_to receive(:perform_with_capacity)
+
+ perform
+ end
+ end
+
describe 'counts logging' do
let_it_be(:processing_package_file) { create(:package_file, status: :processing) }
@@ -41,6 +65,7 @@ RSpec.describe Packages::CleanupPackageRegistryWorker do
expect(worker).to receive(:log_extra_metadata_on_done).with(:pending_destruction_package_files_count, 2)
expect(worker).to receive(:log_extra_metadata_on_done).with(:processing_package_files_count, 1)
expect(worker).to receive(:log_extra_metadata_on_done).with(:error_package_files_count, 0)
+ expect(worker).to receive(:log_extra_metadata_on_done).with(:pending_cleanup_policies_count, 1)
perform
end
diff --git a/spec/workers/packages/debian/generate_distribution_worker_spec.rb b/spec/workers/packages/debian/generate_distribution_worker_spec.rb
index a4627ec5d36..a3e956f14c8 100644
--- a/spec/workers/packages/debian/generate_distribution_worker_spec.rb
+++ b/spec/workers/packages/debian/generate_distribution_worker_spec.rb
@@ -18,6 +18,12 @@ RSpec.describe Packages::Debian::GenerateDistributionWorker, type: :worker do
context "for #{container_type}" do
include_context 'with Debian distribution', container_type
+ context 'with FIPS mode enabled', :fips_mode do
+ it 'raises an error' do
+ expect { subject }.to raise_error(::Packages::FIPS::DisabledError)
+ end
+ end
+
context 'with mocked service' do
it 'calls GenerateDistributionService' do
expect(Gitlab::ErrorTracking).not_to receive(:log_exception)
diff --git a/spec/workers/packages/debian/process_changes_worker_spec.rb b/spec/workers/packages/debian/process_changes_worker_spec.rb
index 4a8eb855398..93eba4bfa9a 100644
--- a/spec/workers/packages/debian/process_changes_worker_spec.rb
+++ b/spec/workers/packages/debian/process_changes_worker_spec.rb
@@ -16,6 +16,12 @@ RSpec.describe Packages::Debian::ProcessChangesWorker, type: :worker do
subject { worker.perform(package_file_id, user_id) }
+ context 'with FIPS mode enabled', :fips_mode do
+ it 'raises an error' do
+ expect { subject }.to raise_error(::Packages::FIPS::DisabledError)
+ end
+ end
+
context 'with mocked service' do
it 'calls ProcessChangesService' do
expect(Gitlab::ErrorTracking).not_to receive(:log_exception)
diff --git a/spec/workers/pages/invalidate_domain_cache_worker_spec.rb b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb
new file mode 100644
index 00000000000..1c1586ef199
--- /dev/null
+++ b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Pages::InvalidateDomainCacheWorker do
+ shared_examples 'clears caches with' do |event_class:, event_data:, caches:|
+ let(:event) do
+ event_class.new(data: event_data)
+ end
+
+ subject { consume_event(subscriber: described_class, event: event) }
+
+ it_behaves_like 'subscribes to event'
+
+ it 'clears the cache with Gitlab::Pages::CacheControl' do
+ caches.each do |cache_type, cache_id|
+ expect_next_instance_of(Gitlab::Pages::CacheControl, type: cache_type, id: cache_id) do |cache_control|
+ expect(cache_control).to receive(:clear_cache)
+ end
+ end
+
+ subject
+ end
+ end
+
+ it_behaves_like 'clears caches with',
+ event_class: Pages::PageDeployedEvent,
+ event_data: { project_id: 1, namespace_id: 2, root_namespace_id: 3 },
+ caches: { namespace: 3, project: 1 }
+
+ it_behaves_like 'clears caches with',
+ event_class: Pages::PageDeletedEvent,
+ event_data: { project_id: 1, namespace_id: 2, root_namespace_id: 3 },
+ caches: { namespace: 3, project: 1 }
+
+ it_behaves_like 'clears caches with',
+ event_class: Projects::ProjectDeletedEvent,
+ event_data: { project_id: 1, namespace_id: 2, root_namespace_id: 3 },
+ caches: { namespace: 3, project: 1 }
+
+ it_behaves_like 'clears caches with',
+ event_class: Projects::ProjectCreatedEvent,
+ event_data: { project_id: 1, namespace_id: 2, root_namespace_id: 3 },
+ caches: { namespace: 3, project: 1 }
+end
diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb
index 3951c20c048..4ddb793516f 100644
--- a/spec/workers/post_receive_spec.rb
+++ b/spec/workers/post_receive_spec.rb
@@ -274,6 +274,32 @@ RSpec.describe PostReceive do
expect { perform }.to change { counter.read(:pushes) }.by(1)
end
+
+ it 'records correct payload with Snowplow event', :snowplow do
+ stub_feature_flags(route_hll_to_snowplow_phase2: true)
+
+ perform
+
+ expect_snowplow_event(
+ category: 'PostReceive',
+ action: 'source_code_pushes',
+ namespace: project.namespace,
+ user: project.first_owner,
+ project: project
+ )
+ end
+
+ context 'when FF is disabled' do
+ before do
+ stub_feature_flags(route_hll_to_snowplow_phase2: false)
+ end
+
+ it 'doesnt emit snowplow events', :snowplow do
+ perform
+
+ expect_no_snowplow_event
+ end
+ end
end
end
diff --git a/spec/workers/projects/after_import_worker_spec.rb b/spec/workers/projects/after_import_worker_spec.rb
index 332b547bb66..a14b2443173 100644
--- a/spec/workers/projects/after_import_worker_spec.rb
+++ b/spec/workers/projects/after_import_worker_spec.rb
@@ -39,8 +39,7 @@ RSpec.describe Projects::AfterImportWorker do
end
it 'removes refs/pull/**/*' do
- expect(rugged.references.map(&:name))
- .not_to include(%r{\Arefs/pull/})
+ expect(repository.list_refs(['refs/pull/'])).to be_empty
end
end
@@ -53,8 +52,7 @@ RSpec.describe Projects::AfterImportWorker do
end
it "does not remove refs/#{name}/tmp" do
- expect(rugged.references.map(&:name))
- .to include("refs/#{name}/tmp")
+ expect(repository.list_refs(["refs/#{name}/tmp"]).length).to be(1)
end
end
end
@@ -100,8 +98,7 @@ RSpec.describe Projects::AfterImportWorker do
it 'removes refs/pull/**/*' do
subject
- expect(rugged.references.map(&:name))
- .not_to include(%r{\Arefs/pull/})
+ expect(repository.list_refs(['refs/pull/'])).to be_empty
end
it 'records the failures in the database', :aggregate_failures do
@@ -123,9 +120,5 @@ RSpec.describe Projects::AfterImportWorker do
expect(import_failure.correlation_id_value).not_to be_empty
end
end
-
- def rugged
- rugged_repo(repository)
- end
end
end
diff --git a/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb b/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb
index 4a6a525a5a7..c7e45e7e4d7 100644
--- a/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb
+++ b/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb
@@ -62,32 +62,11 @@ RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsWorker do
describe '#max_running_jobs' do
subject { worker.max_running_jobs }
- context 'when all projects_build_artifacts_size_refresh flags are enabled' do
- it { is_expected.to eq(described_class::MAX_RUNNING_HIGH) }
- end
-
- context 'when projects_build_artifacts_size_refresh_high flags is disabled' do
- before do
- stub_feature_flags(projects_build_artifacts_size_refresh_high: false)
- end
-
- it { is_expected.to eq(described_class::MAX_RUNNING_MEDIUM) }
- end
-
- context 'when projects_build_artifacts_size_refresh_high and projects_build_artifacts_size_refresh_medium flags are disabled' do
- before do
- stub_feature_flags(projects_build_artifacts_size_refresh_high: false)
- stub_feature_flags(projects_build_artifacts_size_refresh_medium: false)
- end
-
- it { is_expected.to eq(described_class::MAX_RUNNING_LOW) }
- end
+ it { is_expected.to eq(10) }
- context 'when all projects_build_artifacts_size_refresh flags are disabled' do
+ context 'when projects_build_artifacts_size_refresh flag is disabled' do
before do
- stub_feature_flags(projects_build_artifacts_size_refresh_low: false)
- stub_feature_flags(projects_build_artifacts_size_refresh_medium: false)
- stub_feature_flags(projects_build_artifacts_size_refresh_high: false)
+ stub_feature_flags(projects_build_artifacts_size_refresh: false)
end
it { is_expected.to eq(0) }
diff --git a/spec/workers/remove_expired_group_links_worker_spec.rb b/spec/workers/remove_expired_group_links_worker_spec.rb
index 151bbb75226..7bdf6fc0d59 100644
--- a/spec/workers/remove_expired_group_links_worker_spec.rb
+++ b/spec/workers/remove_expired_group_links_worker_spec.rb
@@ -51,16 +51,41 @@ RSpec.describe RemoveExpiredGroupLinksWorker do
subject.perform
end
- it 'removes project authorization', :sidekiq_inline do
- shared_group = group_group_link.shared_group
- shared_with_group = group_group_link.shared_with_group
- project = create(:project, group: shared_group)
+ context 'with skip_group_share_unlink_auth_refresh feature flag disabled' do
+ before do
+ stub_feature_flags(skip_group_share_unlink_auth_refresh: false)
+ end
+
+ it 'removes project authorization', :sidekiq_inline do
+ shared_group = group_group_link.shared_group
+ shared_with_group = group_group_link.shared_with_group
+ project = create(:project, group: shared_group)
+
+ user = create(:user)
+ shared_with_group.add_maintainer(user)
+
+ expect { subject.perform }.to(
+ change { user.can?(:read_project, project) }.from(true).to(false))
+ end
+ end
+
+ context 'with skip_group_share_unlink_auth_refresh feature flag enabled' do
+ before do
+ stub_feature_flags(skip_group_share_unlink_auth_refresh: true)
+ end
+
+ it 'does not remove project authorization', :sidekiq_inline do
+ shared_group = group_group_link.shared_group
+ shared_with_group = group_group_link.shared_with_group
+ project = create(:project, group: shared_group)
+
+ user = create(:user)
+ shared_with_group.add_maintainer(user)
- user = create(:user)
- shared_with_group.add_maintainer(user)
+ subject.perform
- expect { subject.perform }.to(
- change { user.can?(:read_project, project) }.from(true).to(false))
+ expect(user.can?(:read_project, project)).to be_truthy
+ end
end
end
diff --git a/spec/workers/remove_expired_members_worker_spec.rb b/spec/workers/remove_expired_members_worker_spec.rb
index 6d0d4aeef89..8d7d488094f 100644
--- a/spec/workers/remove_expired_members_worker_spec.rb
+++ b/spec/workers/remove_expired_members_worker_spec.rb
@@ -47,7 +47,7 @@ RSpec.describe RemoveExpiredMembersWorker do
let_it_be(:expired_project_bot) { create(:user, :project_bot) }
before do
- project.add_user(expired_project_bot, :maintainer, expires_at: 1.day.from_now)
+ project.add_member(expired_project_bot, :maintainer, expires_at: 1.day.from_now)
travel_to(3.days.from_now)
end
@@ -67,7 +67,7 @@ RSpec.describe RemoveExpiredMembersWorker do
let_it_be(:other_project_bot) { create(:user, :project_bot) }
before do
- project.add_user(other_project_bot, :maintainer, expires_at: 10.days.from_now)
+ project.add_member(other_project_bot, :maintainer, expires_at: 10.days.from_now)
travel_to(3.days.from_now)
end
diff --git a/spec/workers/stage_update_worker_spec.rb b/spec/workers/stage_update_worker_spec.rb
index 75b324a9e0a..e50c7183153 100644
--- a/spec/workers/stage_update_worker_spec.rb
+++ b/spec/workers/stage_update_worker_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe StageUpdateWorker do
describe '#perform' do
context 'when stage exists' do
- let(:stage) { create(:ci_stage_entity) }
+ let(:stage) { create(:ci_stage) }
it 'updates stage status' do
expect_any_instance_of(Ci::Stage).to receive(:set_status).with('skipped')
diff --git a/spec/workers/web_hooks/destroy_worker_spec.rb b/spec/workers/web_hooks/destroy_worker_spec.rb
deleted file mode 100644
index 8e75610a031..00000000000
--- a/spec/workers/web_hooks/destroy_worker_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe WebHooks::DestroyWorker do
- include AfterNextHelpers
-
- let_it_be(:project) { create(:project) }
- let_it_be(:user) { create(:user) }
-
- before_all do
- project.add_maintainer(user)
- end
-
- subject { described_class.new }
-
- describe "#perform" do
- context 'with a Web hook' do
- let!(:hook) { create(:project_hook, project: project) }
- let!(:other_hook) { create(:project_hook, project: project) }
- let!(:log) { create(:web_hook_log, web_hook: hook) }
- let!(:other_log) { create(:web_hook_log, web_hook: other_hook) }
-
- it "deletes the Web hook and logs", :aggregate_failures do
- expect(WebHooks::LogDestroyWorker).to receive(:perform_async)
-
- expect { subject.perform(user.id, hook.id) }
- .to change { WebHook.count }.from(2).to(1)
-
- expect(WebHook.find(other_hook.id)).to be_present
- expect(WebHookLog.find(other_log.id)).to be_present
- end
-
- it "raises and tracks an error if destroy failed" do
- expect_next(::WebHooks::DestroyService)
- .to receive(:sync_destroy).with(anything)
- .and_return(ServiceResponse.error(message: "failed"))
-
- expect(Gitlab::ErrorTracking)
- .to receive(:track_and_raise_exception)
- .with(an_instance_of(described_class::DestroyError), { web_hook_id: hook.id })
- .and_call_original
-
- expect { subject.perform(user.id, hook.id) }.to raise_error(described_class::DestroyError)
- end
-
- context 'with unknown hook' do
- it 'does not raise an error' do
- expect { subject.perform(user.id, non_existing_record_id) }.not_to raise_error
-
- expect(WebHook.count).to eq(2)
- end
- end
-
- context 'with unknown user' do
- it 'does not raise an error' do
- expect { subject.perform(non_existing_record_id, hook.id) }.not_to raise_error
-
- expect(WebHook.count).to eq(2)
- end
- end
- end
- end
-end