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-09-20 02:18:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-20 02:18:09 +0300
commit6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch)
treedc4d20fe6064752c0bd323187252c77e0a89144b /spec/workers
parent9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff)
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/analytics/usage_trends/counter_job_worker_spec.rb34
-rw-r--r--spec/workers/bulk_imports/export_request_worker_spec.rb2
-rw-r--r--spec/workers/ci/build_finished_worker_spec.rb13
-rw-r--r--spec/workers/ci/job_artifacts/track_artifact_report_worker_spec.rb60
-rw-r--r--spec/workers/cleanup_container_repository_worker_spec.rb2
-rw-r--r--spec/workers/clusters/cleanup/project_namespace_worker_spec.rb2
-rw-r--r--spec/workers/concerns/application_worker_spec.rb2
-rw-r--r--spec/workers/concerns/cluster_agent_queue_spec.rb1
-rw-r--r--spec/workers/concerns/cluster_queue_spec.rb21
-rw-r--r--spec/workers/concerns/cronjob_queue_spec.rb4
-rw-r--r--spec/workers/concerns/gitlab/github_import/queue_spec.rb18
-rw-r--r--spec/workers/concerns/pipeline_background_queue_spec.rb21
-rw-r--r--spec/workers/concerns/pipeline_queue_spec.rb21
-rw-r--r--spec/workers/concerns/repository_check_queue_spec.rb4
-rw-r--r--spec/workers/concerns/waitable_worker_spec.rb3
-rw-r--r--spec/workers/disallow_two_factor_for_group_worker_spec.rb2
-rw-r--r--spec/workers/emails_on_push_worker_spec.rb2
-rw-r--r--spec/workers/every_sidekiq_worker_spec.rb6
-rw-r--r--spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb40
-rw-r--r--spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb48
-rw-r--r--spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb49
-rw-r--r--spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb2
-rw-r--r--spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb58
-rw-r--r--spec/workers/gitlab_service_ping_worker_spec.rb21
-rw-r--r--spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb15
-rw-r--r--spec/workers/groups/update_two_factor_requirement_for_members_worker_spec.rb39
-rw-r--r--spec/workers/issues/close_worker_spec.rb86
-rw-r--r--spec/workers/namespaces/onboarding_issue_created_worker_spec.rb4
-rw-r--r--spec/workers/namespaces/process_sync_events_worker_spec.rb24
-rw-r--r--spec/workers/packages/helm/extraction_worker_spec.rb2
-rw-r--r--spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb4
-rw-r--r--spec/workers/pages_worker_spec.rb2
-rw-r--r--spec/workers/process_commit_worker_spec.rb50
-rw-r--r--spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb92
-rw-r--r--spec/workers/projects/process_sync_events_worker_spec.rb8
-rw-r--r--spec/workers/purge_dependency_proxy_cache_worker_spec.rb4
-rw-r--r--spec/workers/releases/manage_evidence_worker_spec.rb2
-rw-r--r--spec/workers/remove_expired_members_worker_spec.rb23
-rw-r--r--spec/workers/repository_check/dispatch_worker_spec.rb4
-rw-r--r--spec/workers/ssh_keys/expired_notification_worker_spec.rb1
-rw-r--r--spec/workers/ssh_keys/expiring_soon_notification_worker_spec.rb1
-rw-r--r--spec/workers/users/deactivate_dormant_users_worker_spec.rb10
-rw-r--r--spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb53
43 files changed, 637 insertions, 223 deletions
diff --git a/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb b/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb
index c45ec20fe5a..ee1bbafa9b5 100644
--- a/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb
+++ b/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb
@@ -48,11 +48,43 @@ RSpec.describe Analytics::UsageTrends::CounterJobWorker do
end
it 'does not insert anything when BatchCount returns error' do
- allow(Gitlab::Database::BatchCount).to receive(:batch_count).and_return(Gitlab::Database::BatchCounter::FALLBACK)
+ allow(Gitlab::Database::BatchCount).to receive(:batch_count_with_timeout)
+ .and_return({ status: :canceled })
expect { subject }.not_to change { Analytics::UsageTrends::Measurement.count }
end
+ context 'when the timeout elapses' do
+ let(:min_id) { 1 }
+ let(:max_id) { 12345 }
+ let(:continue_from) { 321 }
+ let(:partial_results) { 42 }
+ let(:final_count) { 123 }
+
+ subject { described_class.new.perform(users_measurement_identifier, min_id, max_id, recorded_at) }
+
+ it 'continues counting later when the timeout elapses' do
+ expect(Gitlab::Database::BatchCount).to receive(:batch_count_with_timeout)
+ .with(anything, start: min_id, finish: max_id, timeout: 250.seconds, partial_results: nil)
+ .and_return({ status: :timeout, partial_results: partial_results, continue_from: continue_from })
+
+ expect(described_class).to receive(:perform_async).with(anything, continue_from, max_id, recorded_at, partial_results) do |*args|
+ described_class.new.perform(*args)
+ end
+
+ expect(Gitlab::Database::BatchCount).to receive(:batch_count_with_timeout)
+ .with(anything, start: continue_from, finish: max_id, timeout: 250.seconds, partial_results: partial_results)
+ .and_return({ status: :completed, count: final_count })
+
+ expect { subject }.to change { Analytics::UsageTrends::Measurement.count }
+
+ measurement = Analytics::UsageTrends::Measurement.users.last
+ expect(measurement.recorded_at).to be_like_time(recorded_at)
+ expect(measurement.identifier).to eq('users')
+ expect(measurement.count).to eq(final_count)
+ end
+ end
+
context 'when pipelines_succeeded identifier is passed' do
let_it_be(:pipeline) { create(:ci_pipeline, :success) }
diff --git a/spec/workers/bulk_imports/export_request_worker_spec.rb b/spec/workers/bulk_imports/export_request_worker_spec.rb
index 846df63a4d7..a7f7aaa7dba 100644
--- a/spec/workers/bulk_imports/export_request_worker_spec.rb
+++ b/spec/workers/bulk_imports/export_request_worker_spec.rb
@@ -60,7 +60,7 @@ RSpec.describe BulkImports::ExportRequestWorker do
context 'when entity is group' do
let(:entity) { create(:bulk_import_entity, :group_entity, source_full_path: 'foo/bar', bulk_import: bulk_import) }
- let(:expected) { '/groups/foo%2Fbar/export_relations'}
+ let(:expected) { '/groups/foo%2Fbar/export_relations' }
include_examples 'requests relations export for api resource'
end
diff --git a/spec/workers/ci/build_finished_worker_spec.rb b/spec/workers/ci/build_finished_worker_spec.rb
index 5ddaabc3938..e8bb3988001 100644
--- a/spec/workers/ci/build_finished_worker_spec.rb
+++ b/spec/workers/ci/build_finished_worker_spec.rb
@@ -27,19 +27,6 @@ RSpec.describe Ci::BuildFinishedWorker do
subject
end
- context 'when the execute_build_hooks_inline feature flag is disabled' do
- before do
- stub_feature_flags(execute_build_hooks_inline: false)
- end
-
- it 'uses the BuildHooksWorker' do
- expect(build).not_to receive(:execute_hooks)
- expect(BuildHooksWorker).to receive(:perform_async).with(build)
-
- subject
- end
- end
-
context 'when build is failed' do
before do
build.update!(status: :failed)
diff --git a/spec/workers/ci/job_artifacts/track_artifact_report_worker_spec.rb b/spec/workers/ci/job_artifacts/track_artifact_report_worker_spec.rb
new file mode 100644
index 00000000000..e18539cc6e3
--- /dev/null
+++ b/spec/workers/ci/job_artifacts/track_artifact_report_worker_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::JobArtifacts::TrackArtifactReportWorker do
+ describe '#perform', :clean_gitlab_redis_shared_state do
+ let_it_be(:group) { create(:group, :private) }
+ let_it_be(:project) { create(:project, group: group) }
+ let_it_be(:user) { create(:user) }
+
+ let_it_be(:pipeline) { create(:ci_pipeline, :with_test_reports, project: project, user: user) }
+
+ subject(:perform) { described_class.new.perform(pipeline_id) }
+
+ context 'when pipeline is found' do
+ let(:pipeline_id) { pipeline.id }
+
+ it 'executed service' do
+ expect_next_instance_of(Ci::JobArtifacts::TrackArtifactReportService) do |instance|
+ expect(instance).to receive(:execute).with(pipeline)
+ end
+
+ perform
+ end
+
+ it_behaves_like 'an idempotent worker' do
+ let(:job_args) { pipeline_id }
+ let(:test_event_name) { 'i_testing_test_report_uploaded' }
+ let(:start_time) { 1.week.ago }
+ let(:end_time) { 1.week.from_now }
+
+ subject(:idempotent_perform) { perform_multiple(pipeline_id, exec_times: 2) }
+
+ it 'does not try to increment again' do
+ idempotent_perform
+
+ unique_pipeline_pass = Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(
+ event_names: test_event_name,
+ start_date: start_time,
+ end_date: end_time
+ )
+ expect(unique_pipeline_pass).to eq(1)
+ end
+ end
+ end
+
+ context 'when pipeline is not found' do
+ let(:pipeline_id) { non_existing_record_id }
+
+ it 'does not execute service' do
+ allow_next_instance_of(Ci::JobArtifacts::TrackArtifactReportService) do |instance|
+ expect(instance).not_to receive(:execute)
+ end
+
+ expect { perform }
+ .not_to raise_error
+ end
+ end
+ end
+end
diff --git a/spec/workers/cleanup_container_repository_worker_spec.rb b/spec/workers/cleanup_container_repository_worker_spec.rb
index edb815f426d..817b71c8cc6 100644
--- a/spec/workers/cleanup_container_repository_worker_spec.rb
+++ b/spec/workers/cleanup_container_repository_worker_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe CleanupContainerRepositoryWorker, :clean_gitlab_redis_shared_stat
it 'executes the destroy service' do
expect(Projects::ContainerRepository::CleanupTagsService).to receive(:new)
- .with(repository, user, params)
+ .with(container_repository: repository, current_user: user, params: params)
.and_return(service)
expect(service).to receive(:execute)
diff --git a/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb b/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb
index b9219586a0b..c24ca71eb35 100644
--- a/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb
+++ b/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe Clusters::Cleanup::ProjectNamespaceWorker do
end
context 'when exceeded the execution limit' do
- subject { worker_instance.perform(cluster.id, worker_instance.send(:execution_limit))}
+ subject { worker_instance.perform(cluster.id, worker_instance.send(:execution_limit)) }
it 'logs the error' do
expect(logger).to receive(:error)
diff --git a/spec/workers/concerns/application_worker_spec.rb b/spec/workers/concerns/application_worker_spec.rb
index 707fa0c9c78..5fde54b98f0 100644
--- a/spec/workers/concerns/application_worker_spec.rb
+++ b/spec/workers/concerns/application_worker_spec.rb
@@ -289,7 +289,6 @@ RSpec.describe ApplicationWorker do
perform_action
expect(worker.jobs.count).to eq args.count
- expect(worker.jobs).to all(include('enqueued_at'))
end
end
@@ -302,7 +301,6 @@ RSpec.describe ApplicationWorker do
perform_action
expect(worker.jobs.count).to eq args.count
- expect(worker.jobs).to all(include('enqueued_at'))
end
end
diff --git a/spec/workers/concerns/cluster_agent_queue_spec.rb b/spec/workers/concerns/cluster_agent_queue_spec.rb
index b5189cbd8c8..4f67102a0be 100644
--- a/spec/workers/concerns/cluster_agent_queue_spec.rb
+++ b/spec/workers/concerns/cluster_agent_queue_spec.rb
@@ -14,6 +14,5 @@ RSpec.describe ClusterAgentQueue do
end
end
- it { expect(worker.queue).to eq('cluster_agent:example') }
it { expect(worker.get_feature_category).to eq(:kubernetes_management) }
end
diff --git a/spec/workers/concerns/cluster_queue_spec.rb b/spec/workers/concerns/cluster_queue_spec.rb
deleted file mode 100644
index c03ca9cea48..00000000000
--- a/spec/workers/concerns/cluster_queue_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe ClusterQueue do
- let(:worker) do
- Class.new do
- def self.name
- 'DummyWorker'
- end
-
- include ApplicationWorker
- include ClusterQueue
- end
- end
-
- it 'sets a default pipelines queue automatically' do
- expect(worker.sidekiq_options['queue'])
- .to eq 'gcp_cluster:dummy'
- end
-end
diff --git a/spec/workers/concerns/cronjob_queue_spec.rb b/spec/workers/concerns/cronjob_queue_spec.rb
index 0244535051f..7dd016fc78a 100644
--- a/spec/workers/concerns/cronjob_queue_spec.rb
+++ b/spec/workers/concerns/cronjob_queue_spec.rb
@@ -40,10 +40,6 @@ RSpec.describe CronjobQueue do
stub_const("AnotherWorker", another_worker)
end
- it 'sets the queue name of a worker' do
- expect(worker.sidekiq_options['queue'].to_s).to eq('cronjob:dummy')
- end
-
it 'disables retrying of failed jobs' do
expect(worker.sidekiq_options['retry']).to eq(false)
end
diff --git a/spec/workers/concerns/gitlab/github_import/queue_spec.rb b/spec/workers/concerns/gitlab/github_import/queue_spec.rb
deleted file mode 100644
index beca221b593..00000000000
--- a/spec/workers/concerns/gitlab/github_import/queue_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::GithubImport::Queue do
- it 'sets the Sidekiq options for the worker' do
- worker = Class.new do
- def self.name
- 'DummyWorker'
- end
-
- include ApplicationWorker
- include Gitlab::GithubImport::Queue
- end
-
- expect(worker.sidekiq_options['queue']).to eq('github_importer:dummy')
- end
-end
diff --git a/spec/workers/concerns/pipeline_background_queue_spec.rb b/spec/workers/concerns/pipeline_background_queue_spec.rb
deleted file mode 100644
index 77c7e7440c5..00000000000
--- a/spec/workers/concerns/pipeline_background_queue_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe PipelineBackgroundQueue do
- let(:worker) do
- Class.new do
- def self.name
- 'DummyWorker'
- end
-
- include ApplicationWorker
- include PipelineBackgroundQueue
- end
- end
-
- it 'sets a default object storage queue automatically' do
- expect(worker.sidekiq_options['queue'])
- .to eq 'pipeline_background:dummy'
- end
-end
diff --git a/spec/workers/concerns/pipeline_queue_spec.rb b/spec/workers/concerns/pipeline_queue_spec.rb
deleted file mode 100644
index 6c1ac2052e4..00000000000
--- a/spec/workers/concerns/pipeline_queue_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe PipelineQueue do
- let(:worker) do
- Class.new do
- def self.name
- 'DummyWorker'
- end
-
- include ApplicationWorker
- include PipelineQueue
- end
- end
-
- it 'sets a default pipelines queue automatically' do
- expect(worker.sidekiq_options['queue'])
- .to eq 'pipeline_default:dummy'
- end
-end
diff --git a/spec/workers/concerns/repository_check_queue_spec.rb b/spec/workers/concerns/repository_check_queue_spec.rb
index ae377c09b37..08ac73aac7b 100644
--- a/spec/workers/concerns/repository_check_queue_spec.rb
+++ b/spec/workers/concerns/repository_check_queue_spec.rb
@@ -14,10 +14,6 @@ RSpec.describe RepositoryCheckQueue do
end
end
- it 'sets the queue name of a worker' do
- expect(worker.sidekiq_options['queue'].to_s).to eq('repository_check:dummy')
- end
-
it 'disables retrying of failed jobs' do
expect(worker.sidekiq_options['retry']).to eq(false)
end
diff --git a/spec/workers/concerns/waitable_worker_spec.rb b/spec/workers/concerns/waitable_worker_spec.rb
index bf156c3b8cb..2df5b60deaf 100644
--- a/spec/workers/concerns/waitable_worker_spec.rb
+++ b/spec/workers/concerns/waitable_worker_spec.rb
@@ -49,8 +49,7 @@ RSpec.describe WaitableWorker do
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'))
+ 'job_status' => 'running'))
.once)
worker.bulk_perform_and_wait(args_list)
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 f30b12dd7f4..3a875727cce 100644
--- a/spec/workers/disallow_two_factor_for_group_worker_spec.rb
+++ b/spec/workers/disallow_two_factor_for_group_worker_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe DisallowTwoFactorForGroupWorker do
expect(group.reload.require_two_factor_authentication).to eq(false)
end
- it "updates group members" do
+ it "updates group members", :sidekiq_inline do
group.add_member(user, GroupMember::DEVELOPER)
described_class.new.perform(group.id)
diff --git a/spec/workers/emails_on_push_worker_spec.rb b/spec/workers/emails_on_push_worker_spec.rb
index 3e313610054..7d11957e2df 100644
--- a/spec/workers/emails_on_push_worker_spec.rb
+++ b/spec/workers/emails_on_push_worker_spec.rb
@@ -51,7 +51,7 @@ RSpec.describe EmailsOnPushWorker, :mailer do
context "when push is a force push to delete commits" do
before do
data_force_push = data.stringify_keys.merge(
- "after" => data[:before],
+ "after" => data[:before],
"before" => data[:after]
)
diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb
index 4a1bf7dbbf9..6b67c2b474c 100644
--- a/spec/workers/every_sidekiq_worker_spec.rb
+++ b/spec/workers/every_sidekiq_worker_spec.rb
@@ -257,11 +257,13 @@ RSpec.describe 'Every Sidekiq worker' do
'GeoRepositoryDestroyWorker' => 3,
'GitGarbageCollectWorker' => false,
'Gitlab::GithubImport::AdvanceStageWorker' => 3,
+ 'Gitlab::GithubImport::ImportReleaseAttachmentsWorker' => 5,
'Gitlab::GithubImport::ImportDiffNoteWorker' => 5,
'Gitlab::GithubImport::ImportIssueWorker' => 5,
'Gitlab::GithubImport::ImportIssueEventWorker' => 5,
'Gitlab::GithubImport::ImportLfsObjectWorker' => 5,
'Gitlab::GithubImport::ImportNoteWorker' => 5,
+ 'Gitlab::GithubImport::ImportProtectedBranchWorker' => 5,
'Gitlab::GithubImport::ImportPullRequestMergedByWorker' => 5,
'Gitlab::GithubImport::ImportPullRequestReviewWorker' => 5,
'Gitlab::GithubImport::ImportPullRequestWorker' => 5,
@@ -271,6 +273,8 @@ RSpec.describe 'Every Sidekiq worker' do
'Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker' => 5,
'Gitlab::GithubImport::Stage::ImportIssueEventsWorker' => 5,
'Gitlab::GithubImport::Stage::ImportLfsObjectsWorker' => 5,
+ 'Gitlab::GithubImport::Stage::ImportAttachmentsWorker' => 5,
+ 'Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker' => 5,
'Gitlab::GithubImport::Stage::ImportNotesWorker' => 5,
'Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker' => 5,
'Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker' => 5,
@@ -311,6 +315,7 @@ RSpec.describe 'Every Sidekiq worker' do
'Integrations::IrkerWorker' => 3,
'InvalidGpgSignatureUpdateWorker' => 3,
'IssuableExportCsvWorker' => 3,
+ 'Issues::CloseWorker' => 3,
'Issues::PlacementWorker' => 3,
'Issues::RebalancingWorker' => 3,
'IterationsUpdateStatusWorker' => 3,
@@ -356,6 +361,7 @@ RSpec.describe 'Every Sidekiq worker' do
'ObjectPool::ScheduleJoinWorker' => 3,
'ObjectStorage::BackgroundMoveWorker' => 5,
'ObjectStorage::MigrateUploadsWorker' => 3,
+ 'Onboarding::CreateLearnGitlabWorker' => 3,
'Packages::CleanupPackageFileWorker' => 0,
'Packages::Cleanup::ExecutePolicyWorker' => 0,
'Packages::Composer::CacheUpdateWorker' => false,
diff --git a/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb b/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb
new file mode 100644
index 00000000000..4a3ef2bf560
--- /dev/null
+++ b/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::ImportProtectedBranchWorker do
+ let(:worker) { described_class.new }
+
+ let(:import_state) { build_stubbed(:import_state, :started) }
+ let(:project) { instance_double('Project', full_path: 'foo/bar', id: 1, import_state: import_state) }
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+ let(:importer) { instance_double('Gitlab::GithubImport::Importer::ProtectedBranchImporter') }
+
+ describe '#import' do
+ let(:json_hash) do
+ {
+ id: 'main',
+ allow_force_pushes: true
+ }
+ end
+
+ it 'imports protected branch rule' do
+ expect(Gitlab::GithubImport::Importer::ProtectedBranchImporter)
+ .to receive(:new)
+ .with(
+ an_instance_of(Gitlab::GithubImport::Representation::ProtectedBranch),
+ project,
+ client
+ )
+ .and_return(importer)
+
+ expect(importer).to receive(:execute)
+
+ expect(Gitlab::GithubImport::ObjectCounter)
+ .to receive(:increment)
+ .with(project, :protected_branch, :imported)
+
+ worker.import(project, client, json_hash)
+ end
+ end
+end
diff --git a/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb b/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb
new file mode 100644
index 00000000000..cd53c6ee9c0
--- /dev/null
+++ b/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::ImportReleaseAttachmentsWorker 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::ReleaseAttachmentsImporter') }
+
+ let(:release_hash) do
+ {
+ 'release_db_id' => rand(100),
+ 'description' => <<-TEXT
+ Some text...
+
+ ![special-image](https://user-images.githubusercontent.com...)
+ TEXT
+ }
+ end
+
+ it 'imports an issue event' do
+ expect(Gitlab::GithubImport::Importer::ReleaseAttachmentsImporter)
+ .to receive(:new)
+ .with(
+ an_instance_of(Gitlab::GithubImport::Representation::ReleaseAttachments),
+ project,
+ client
+ )
+ .and_return(importer)
+
+ expect(importer).to receive(:execute)
+
+ expect(Gitlab::GithubImport::ObjectCounter)
+ .to receive(:increment)
+ .and_call_original
+
+ worker.import(project, client, release_hash)
+ end
+ end
+end
diff --git a/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb
new file mode 100644
index 00000000000..c2c5e1dbf4e
--- /dev/null
+++ b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker 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::ReleasesAttachmentsImporter') }
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+
+ before do
+ stub_feature_flags(github_importer_attachments_import: feature_flag_state)
+ end
+
+ it 'imports release attachments' do
+ waiter = Gitlab::JobWaiter.new(2, '123')
+
+ expect(Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter)
+ .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 }, :protected_branches)
+
+ worker.import(client, project)
+ end
+
+ context 'when feature flag is disabled' do
+ let(:feature_flag_state) { false }
+
+ it 'skips release attachments import and calls next stage' do
+ expect(Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter).not_to receive(:new)
+ expect(Gitlab::GithubImport::AdvanceStageWorker)
+ .to receive(:perform_async).with(project.id, {}, :protected_branches)
+
+ worker.import(client, project)
+ end
+ end
+ end
+end
diff --git a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb
index f9f21e4dfa2..adf20d24a7e 100644
--- a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb
+++ b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb
@@ -26,7 +26,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker do
expect(Gitlab::GithubImport::AdvanceStageWorker)
.to receive(:perform_async)
- .with(project.id, { '123' => 2 }, :lfs_objects)
+ .with(project.id, { '123' => 2 }, :attachments)
worker.import(client, project)
end
diff --git a/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb
new file mode 100644
index 00000000000..0770af524a1
--- /dev/null
+++ b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:import_state) { create(:import_state, project: project) }
+
+ let(:worker) { described_class.new }
+ let(:importer) { instance_double('Gitlab::GithubImport::Importer::ProtectedBranchImporter') }
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+
+ describe '#import' do
+ it 'imports all the pull requests' do
+ waiter = Gitlab::JobWaiter.new(2, '123')
+
+ expect(Gitlab::GithubImport::Importer::ProtectedBranchesImporter)
+ .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 }, :lfs_objects)
+
+ worker.import(client, project)
+ end
+
+ context 'when an error raised' do
+ let(:exception) { StandardError.new('_some_error_') }
+
+ before do
+ allow_next_instance_of(Gitlab::GithubImport::Importer::ProtectedBranchesImporter) do |importer|
+ allow(importer).to receive(:execute).and_raise(exception)
+ end
+ end
+
+ it 'raises an error' do
+ expect(Gitlab::Import::ImportFailureService).to receive(:track)
+ .with(
+ project_id: project.id,
+ exception: exception,
+ error_source: described_class.name,
+ metrics: true
+ ).and_call_original
+
+ expect { worker.import(client, project) }.to raise_error(StandardError)
+ end
+ end
+ end
+end
diff --git a/spec/workers/gitlab_service_ping_worker_spec.rb b/spec/workers/gitlab_service_ping_worker_spec.rb
index c88708dc50a..f17847a7b33 100644
--- a/spec/workers/gitlab_service_ping_worker_spec.rb
+++ b/spec/workers/gitlab_service_ping_worker_spec.rb
@@ -14,21 +14,36 @@ RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do
allow(subject).to receive(:sleep)
end
- it 'does not run for GitLab.com' do
+ it 'does not run for GitLab.com when triggered from cron' do
allow(Gitlab).to receive(:com?).and_return(true)
expect(ServicePing::SubmitService).not_to receive(:new)
subject.perform
end
+ it 'runs for GitLab.com when triggered manually' do
+ allow(Gitlab).to receive(:com?).and_return(true)
+ expect(ServicePing::SubmitService).to receive(:new)
+
+ subject.perform('triggered_from_cron' => false)
+ end
+
it 'delegates to ServicePing::SubmitService' do
- expect_next_instance_of(ServicePing::SubmitService, payload: payload) do |service|
+ expect_next_instance_of(ServicePing::SubmitService, payload: payload, skip_db_write: false) do |service|
expect(service).to receive(:execute)
end
subject.perform
end
+ it 'passes Hash arguments to ServicePing::SubmitService' do
+ expect_next_instance_of(ServicePing::SubmitService, payload: payload, skip_db_write: true) do |service|
+ expect(service).to receive(:execute)
+ end
+
+ subject.perform('skip_db_write' => true)
+ end
+
context 'payload computation' do
it 'creates RawUsageData entry when there is NO entry with the same recorded_at timestamp' do
expect { subject.perform }.to change { RawUsageData.count }.by(1)
@@ -46,7 +61,7 @@ RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do
allow(::ServicePing::BuildPayload).to receive(:new).and_raise(error)
expect(::Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(error)
- expect_next_instance_of(::ServicePing::SubmitService, payload: nil) do |service|
+ expect_next_instance_of(::ServicePing::SubmitService, payload: nil, skip_db_write: false) do |service|
expect(service).to receive(:execute)
end
diff --git a/spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb b/spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb
new file mode 100644
index 00000000000..c0b32515d15
--- /dev/null
+++ b/spec/workers/google_cloud/fetch_google_ip_list_worker_spec.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GoogleCloud::FetchGoogleIpListWorker do
+ describe '#perform' do
+ it 'returns success' do
+ allow_next_instance_of(GoogleCloud::FetchGoogleIpListService) do |service|
+ expect(service).to receive(:execute).and_return({ status: :success })
+ end
+
+ expect(described_class.new.perform).to eq({ status: :success })
+ end
+ end
+end
diff --git a/spec/workers/groups/update_two_factor_requirement_for_members_worker_spec.rb b/spec/workers/groups/update_two_factor_requirement_for_members_worker_spec.rb
new file mode 100644
index 00000000000..9d202b9452f
--- /dev/null
+++ b/spec/workers/groups/update_two_factor_requirement_for_members_worker_spec.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Groups::UpdateTwoFactorRequirementForMembersWorker do
+ let_it_be(:group) { create(:group) }
+
+ let(:worker) { described_class.new }
+
+ describe '#perform' do
+ it 'calls #update_two_factor_requirement_for_members' do
+ allow(Group).to receive(:find_by_id).with(group.id).and_return(group)
+ expect(group).to receive(:update_two_factor_requirement_for_members)
+
+ worker.perform(group.id)
+ end
+
+ context 'when group not found' do
+ it 'returns nil' do
+ expect(worker.perform(non_existing_record_id)).to be_nil
+ end
+ end
+
+ include_examples 'an idempotent worker' do
+ let(:subject) { described_class.new.perform(group.id) }
+
+ it 'requires 2fa for group members correctly' do
+ group.update!(require_two_factor_authentication: true)
+ user = create(:user, require_two_factor_authentication_from_group: false)
+ group.add_member(user, GroupMember::OWNER)
+
+ # Using subject inside this block will process the job multiple times
+ subject
+
+ expect(user.reload.require_two_factor_authentication_from_group).to be true
+ end
+ end
+ end
+end
diff --git a/spec/workers/issues/close_worker_spec.rb b/spec/workers/issues/close_worker_spec.rb
new file mode 100644
index 00000000000..41611447db1
--- /dev/null
+++ b/spec/workers/issues/close_worker_spec.rb
@@ -0,0 +1,86 @@
+# frozen_string_literal: true
+
+require "spec_helper"
+
+RSpec.describe Issues::CloseWorker do
+ describe "#perform" do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :public, :repository) }
+ let_it_be(:issue) { create(:issue, project: project, author: user) }
+
+ let(:commit) { project.commit }
+ let(:opts) do
+ { "closed_by" => user&.id, "commit_hash" => commit.to_hash }
+ end
+
+ subject(:worker) { described_class.new }
+
+ describe "#perform" do
+ context "when the user can update the issues" do
+ it "closes the issues" do
+ worker.perform(project.id, issue.id, issue.class.to_s, opts)
+
+ issue.reload
+
+ expect(issue.closed?).to eq(true)
+ end
+
+ it "closes external issues" do
+ external_issue = ExternalIssue.new("foo", project)
+ closer = instance_double(Issues::CloseService, execute: true)
+
+ expect(Issues::CloseService).to receive(:new).with(project: project, current_user: user).and_return(closer)
+ expect(closer).to receive(:execute).with(external_issue, commit: commit)
+
+ worker.perform(project.id, external_issue.id, external_issue.class.to_s, opts)
+ end
+ end
+
+ context "when the user can not update the issues" do
+ it "does not close the issues" do
+ other_user = create(:user)
+ opts = { "closed_by" => other_user.id, "commit_hash" => commit.to_hash }
+
+ worker.perform(project.id, issue.id, issue.class.to_s, opts)
+
+ issue.reload
+
+ expect(issue.closed?).to eq(false)
+ end
+ end
+ end
+
+ shared_examples "when object does not exist" do
+ it "does not call the close issue service" do
+ expect(Issues::CloseService).not_to receive(:new)
+
+ expect { worker.perform(project.id, issue.id, issue.class.to_s, opts) }
+ .not_to raise_exception
+ end
+ end
+
+ context "when the project does not exist" do
+ before do
+ allow(Project).to receive(:find_by_id).with(project.id).and_return(nil)
+ end
+
+ it_behaves_like "when object does not exist"
+ end
+
+ context "when the user does not exist" do
+ before do
+ allow(User).to receive(:find_by_id).with(user.id).and_return(nil)
+ end
+
+ it_behaves_like "when object does not exist"
+ end
+
+ context "when the issue does not exist" do
+ before do
+ allow(Issue).to receive(:find_by_id).with(issue.id).and_return(nil)
+ end
+
+ it_behaves_like "when object does not exist"
+ end
+ end
+end
diff --git a/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb b/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb
index 53116815ce7..0a896d864b7 100644
--- a/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb
+++ b/spec/workers/namespaces/onboarding_issue_created_worker_spec.rb
@@ -19,11 +19,11 @@ RSpec.describe Namespaces::OnboardingIssueCreatedWorker, '#perform' do
let(:job_args) { [namespace.id] }
it 'sets the onboarding progress action' do
- OnboardingProgress.onboard(namespace)
+ Onboarding::Progress.onboard(namespace)
subject
- expect(OnboardingProgress.completed?(namespace, :issue_created)).to eq(true)
+ expect(Onboarding::Progress.completed?(namespace, :issue_created)).to eq(true)
end
end
end
diff --git a/spec/workers/namespaces/process_sync_events_worker_spec.rb b/spec/workers/namespaces/process_sync_events_worker_spec.rb
index c15a74a2934..5e5179eab62 100644
--- a/spec/workers/namespaces/process_sync_events_worker_spec.rb
+++ b/spec/workers/namespaces/process_sync_events_worker_spec.rb
@@ -11,6 +11,30 @@ RSpec.describe Namespaces::ProcessSyncEventsWorker do
include_examples 'an idempotent worker'
+ describe 'deduplication' do
+ before do
+ stub_const("Ci::ProcessSyncEventsService::BATCH_SIZE", 2)
+ end
+
+ it 'has the `until_executed` deduplicate strategy' do
+ expect(described_class.get_deduplicate_strategy).to eq(:until_executed)
+ end
+
+ it 'has an option to reschedule once if deduplicated' do
+ expect(described_class.get_deduplication_options).to include({ if_deduplicated: :reschedule_once })
+ end
+
+ it 'expect the job to enqueue itself again if there was more items to be processed', :sidekiq_inline do
+ Namespaces::SyncEvent.delete_all # delete the sync_events that have been created by triggers of previous groups
+ create_list(:sync_event, 3, namespace_id: group1.id)
+ # It's called more than twice, because the job deduplication and rescheduling calls the perform_async again
+ expect(described_class).to receive(:perform_async).at_least(:twice).and_call_original
+ expect do
+ described_class.perform_async
+ end.to change(Namespaces::SyncEvent, :count).from(3).to(0)
+ end
+ end
+
describe '#perform' do
subject(:perform) { worker.perform }
diff --git a/spec/workers/packages/helm/extraction_worker_spec.rb b/spec/workers/packages/helm/extraction_worker_spec.rb
index daebbda3077..70a090d6989 100644
--- a/spec/workers/packages/helm/extraction_worker_spec.rb
+++ b/spec/workers/packages/helm/extraction_worker_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Packages::Helm::ExtractionWorker, type: :worker do
describe '#perform' do
- let_it_be(:package) { create(:helm_package, without_package_files: true, status: 'processing')}
+ let_it_be(:package) { create(:helm_package, without_package_files: true, status: 'processing') }
let!(:package_file) { create(:helm_package_file, without_loaded_metadatum: true, package: package) }
let(:package_file_id) { package_file.id }
diff --git a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb
index 563bbdef1be..70ffef5342e 100644
--- a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb
+++ b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb
@@ -25,8 +25,8 @@ RSpec.describe PagesDomainSslRenewalCronWorker do
end
let!(:domain_with_failed_auto_ssl) do
- create(:pages_domain, :without_certificate, :without_key, project: project,
- auto_ssl_enabled: true, auto_ssl_failed: true)
+ create(:pages_domain, :without_certificate, :without_key,
+ project: project, auto_ssl_enabled: true, auto_ssl_failed: true)
end
let!(:domain_with_expired_auto_ssl) do
diff --git a/spec/workers/pages_worker_spec.rb b/spec/workers/pages_worker_spec.rb
index 5ddfd5b43b9..ad714d8d11e 100644
--- a/spec/workers/pages_worker_spec.rb
+++ b/spec/workers/pages_worker_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe PagesWorker, :sidekiq_inline do
let(:project) { create(:project) }
- let(:ci_build) { create(:ci_build, project: project)}
+ let(:ci_build) { create(:ci_build, project: project) }
it 'calls UpdatePagesService' do
expect_next_instance_of(Projects::UpdatePagesService, project, ci_build) do |service|
diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb
index 3df26c774ba..a445db3a276 100644
--- a/spec/workers/process_commit_worker_spec.rb
+++ b/spec/workers/process_commit_worker_spec.rb
@@ -115,25 +115,37 @@ RSpec.describe ProcessCommitWorker do
end
describe '#close_issues' do
- context 'when the user can update the issues' do
- it 'closes the issues' do
+ it 'creates Issue::CloseWorker jobs' do
+ expect do
worker.close_issues(project, user, user, commit, [issue])
+ end.to change(Issues::CloseWorker.jobs, :size).by(1)
+ end
+
+ context 'when process_issue_closure_in_background flag is disabled' do
+ before do
+ stub_feature_flags(process_issue_closure_in_background: false)
+ end
- issue.reload
+ context 'when the user can update the issues' do
+ it 'closes the issues' do
+ worker.close_issues(project, user, user, commit, [issue])
- expect(issue.closed?).to eq(true)
+ issue.reload
+
+ expect(issue.closed?).to eq(true)
+ end
end
- end
- context 'when the user can not update the issues' do
- it 'does not close the issues' do
- other_user = create(:user)
+ context 'when the user can not update the issues' do
+ it 'does not close the issues' do
+ other_user = create(:user)
- worker.close_issues(project, other_user, other_user, commit, [issue])
+ worker.close_issues(project, other_user, other_user, commit, [issue])
- issue.reload
+ issue.reload
- expect(issue.closed?).to eq(false)
+ expect(issue.closed?).to eq(false)
+ end
end
end
end
@@ -189,20 +201,4 @@ RSpec.describe ProcessCommitWorker do
end
end
end
-
- describe '#build_commit' do
- it 'returns a Commit' do
- commit = worker.build_commit(project, id: '123')
-
- expect(commit).to be_an_instance_of(Commit)
- end
-
- it 'parses date strings into Time instances' do
- commit = worker.build_commit(project,
- id: '123',
- authored_date: Time.current.to_s)
-
- expect(commit.authored_date).to be_a_kind_of(Time)
- end
- end
end
diff --git a/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb b/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb
index ec10c66968d..50b5b0a6e7b 100644
--- a/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb
+++ b/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb
@@ -85,86 +85,58 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do
end
end
- context 'when delete inactive projects feature is enabled' do
+ context 'when delete inactive projects feature is enabled', :clean_gitlab_redis_shared_state, :sidekiq_inline do
before do
stub_application_setting(delete_inactive_projects: true)
end
- context 'when feature flag is disabled' do
- before do
- stub_feature_flags(inactive_projects_deletion: false)
- end
-
- it 'does not invoke Projects::InactiveProjectsDeletionNotificationWorker' do
- expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async)
- expect(::Projects::DestroyService).not_to receive(:new)
-
- worker.perform
- end
-
- it 'does not delete the inactive projects' do
- worker.perform
-
- expect(inactive_large_project.reload.pending_delete).to eq(false)
+ it 'invokes Projects::InactiveProjectsDeletionNotificationWorker for inactive projects' do
+ Gitlab::Redis::SharedState.with do |redis|
+ expect(redis).to receive(:hset).with('inactive_projects_deletion_warning_email_notified',
+ "project:#{inactive_large_project.id}", Date.current)
end
+ expect(::Projects::InactiveProjectsDeletionNotificationWorker).to receive(:perform_async).with(
+ inactive_large_project.id, deletion_date).and_call_original
+ expect(::Projects::DestroyService).not_to receive(:new)
- it_behaves_like 'worker is running for more than 4 minutes'
- it_behaves_like 'worker finishes processing in less than 4 minutes'
+ worker.perform
end
- context 'when feature flag is enabled', :clean_gitlab_redis_shared_state, :sidekiq_inline do
- before do
- stub_feature_flags(inactive_projects_deletion: true)
- end
-
- it 'invokes Projects::InactiveProjectsDeletionNotificationWorker for inactive projects' do
- Gitlab::Redis::SharedState.with do |redis|
- expect(redis).to receive(:hset).with('inactive_projects_deletion_warning_email_notified',
- "project:#{inactive_large_project.id}", Date.current)
- end
- expect(::Projects::InactiveProjectsDeletionNotificationWorker).to receive(:perform_async).with(
- inactive_large_project.id, deletion_date).and_call_original
- expect(::Projects::DestroyService).not_to receive(:new)
-
- worker.perform
+ it 'does not invoke InactiveProjectsDeletionNotificationWorker for already notified inactive projects' do
+ Gitlab::Redis::SharedState.with do |redis|
+ redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}",
+ Date.current.to_s)
end
- it 'does not invoke InactiveProjectsDeletionNotificationWorker for already notified inactive projects' do
- Gitlab::Redis::SharedState.with do |redis|
- redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}",
- Date.current.to_s)
- end
+ expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async)
+ expect(::Projects::DestroyService).not_to receive(:new)
- expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async)
- expect(::Projects::DestroyService).not_to receive(:new)
+ worker.perform
+ end
- worker.perform
+ it 'invokes Projects::DestroyService for projects that are inactive even after being notified' do
+ Gitlab::Redis::SharedState.with do |redis|
+ redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}",
+ 15.months.ago.to_date.to_s)
end
- it 'invokes Projects::DestroyService for projects that are inactive even after being notified' do
- Gitlab::Redis::SharedState.with do |redis|
- redis.hset('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}",
- 15.months.ago.to_date.to_s)
- end
-
- expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async)
- expect(::Projects::DestroyService).to receive(:new).with(inactive_large_project, admin_user, {})
- .at_least(:once).and_call_original
+ expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async)
+ expect(::Projects::DestroyService).to receive(:new).with(inactive_large_project, admin_user, {})
+ .at_least(:once).and_call_original
- worker.perform
+ worker.perform
- expect(inactive_large_project.reload.pending_delete).to eq(true)
+ expect(inactive_large_project.reload.pending_delete).to eq(true)
- Gitlab::Redis::SharedState.with do |redis|
- expect(redis.hget('inactive_projects_deletion_warning_email_notified',
- "project:#{inactive_large_project.id}")).to be_nil
- end
+ Gitlab::Redis::SharedState.with do |redis|
+ expect(redis.hget('inactive_projects_deletion_warning_email_notified',
+ "project:#{inactive_large_project.id}")).to be_nil
end
-
- it_behaves_like 'worker is running for more than 4 minutes'
- it_behaves_like 'worker finishes processing in less than 4 minutes'
end
+ it_behaves_like 'worker is running for more than 4 minutes'
+ it_behaves_like 'worker finishes processing in less than 4 minutes'
+
it_behaves_like 'an idempotent worker'
end
end
diff --git a/spec/workers/projects/process_sync_events_worker_spec.rb b/spec/workers/projects/process_sync_events_worker_spec.rb
index 963e0ad1028..202942ce905 100644
--- a/spec/workers/projects/process_sync_events_worker_spec.rb
+++ b/spec/workers/projects/process_sync_events_worker_spec.rb
@@ -10,6 +10,14 @@ RSpec.describe Projects::ProcessSyncEventsWorker do
include_examples 'an idempotent worker'
+ it 'has the `until_executed` deduplicate strategy' do
+ expect(described_class.get_deduplicate_strategy).to eq(:until_executed)
+ end
+
+ it 'has an option to reschedule once if deduplicated' do
+ expect(described_class.get_deduplication_options).to include({ if_deduplicated: :reschedule_once })
+ end
+
describe '#perform' do
subject(:perform) { worker.perform }
diff --git a/spec/workers/purge_dependency_proxy_cache_worker_spec.rb b/spec/workers/purge_dependency_proxy_cache_worker_spec.rb
index 3de59670f8d..84315fd6ee9 100644
--- a/spec/workers/purge_dependency_proxy_cache_worker_spec.rb
+++ b/spec/workers/purge_dependency_proxy_cache_worker_spec.rb
@@ -4,9 +4,9 @@ require 'spec_helper'
RSpec.describe PurgeDependencyProxyCacheWorker do
let_it_be(:user) { create(:admin) }
- let_it_be_with_refind(:blob) { create(:dependency_proxy_blob )}
+ let_it_be_with_refind(:blob) { create(:dependency_proxy_blob ) }
let_it_be_with_reload(:group) { blob.group }
- let_it_be_with_refind(:manifest) { create(:dependency_proxy_manifest, group: group )}
+ let_it_be_with_refind(:manifest) { create(:dependency_proxy_manifest, group: group ) }
let_it_be(:group_id) { group.id }
subject { described_class.new.perform(user.id, group_id) }
diff --git a/spec/workers/releases/manage_evidence_worker_spec.rb b/spec/workers/releases/manage_evidence_worker_spec.rb
index 2fbfb6c9dc1..886fcd346eb 100644
--- a/spec/workers/releases/manage_evidence_worker_spec.rb
+++ b/spec/workers/releases/manage_evidence_worker_spec.rb
@@ -29,7 +29,7 @@ RSpec.describe Releases::ManageEvidenceWorker do
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 )}
+ let!(:evidence) { create(:evidence, release: release ) }
it_behaves_like 'does not create a new Evidence record'
end
diff --git a/spec/workers/remove_expired_members_worker_spec.rb b/spec/workers/remove_expired_members_worker_spec.rb
index 8d7d488094f..44b8fa21be4 100644
--- a/spec/workers/remove_expired_members_worker_spec.rb
+++ b/spec/workers/remove_expired_members_worker_spec.rb
@@ -56,10 +56,27 @@ RSpec.describe RemoveExpiredMembersWorker do
expect(Member.find_by(user_id: expired_project_bot.id)).to be_nil
end
- it 'deletes expired project bot' do
- worker.perform
+ context 'when user_destroy_with_limited_execution_time_worker is enabled' do
+ it 'initiates project bot removal' do
+ worker.perform
+
+ expect(
+ Users::GhostUserMigration.where(user: expired_project_bot,
+ initiator_user: nil)
+ ).to be_exists
+ end
+ end
+
+ context 'when user_destroy_with_limited_execution_time_worker is disabled' do
+ before do
+ stub_feature_flags(user_destroy_with_limited_execution_time_worker: false)
+ end
+
+ it 'deletes expired project bot' do
+ worker.perform
- expect(User.exists?(expired_project_bot.id)).to be(false)
+ expect(User.exists?(expired_project_bot.id)).to be(false)
+ end
end
end
diff --git a/spec/workers/repository_check/dispatch_worker_spec.rb b/spec/workers/repository_check/dispatch_worker_spec.rb
index 829abc7d895..146228c0852 100644
--- a/spec/workers/repository_check/dispatch_worker_spec.rb
+++ b/spec/workers/repository_check/dispatch_worker_spec.rb
@@ -22,6 +22,10 @@ RSpec.describe RepositoryCheck::DispatchWorker do
end
it 'dispatches work to RepositoryCheck::BatchWorker' do
+ expect_next_instance_of(Gitlab::GitalyClient::ServerService) do |service|
+ expect(service).to receive(:readiness_check).and_return({ success: true })
+ end
+
expect(RepositoryCheck::BatchWorker).to receive(:perform_async).at_least(:once)
subject.perform
diff --git a/spec/workers/ssh_keys/expired_notification_worker_spec.rb b/spec/workers/ssh_keys/expired_notification_worker_spec.rb
index 26d9460d73e..f93d02e86c0 100644
--- a/spec/workers/ssh_keys/expired_notification_worker_spec.rb
+++ b/spec/workers/ssh_keys/expired_notification_worker_spec.rb
@@ -7,7 +7,6 @@ RSpec.describe SshKeys::ExpiredNotificationWorker, type: :worker do
it 'uses a cronjob queue' do
expect(worker.sidekiq_options_hash).to include(
- 'queue' => 'cronjob:ssh_keys_expired_notification',
'queue_namespace' => :cronjob
)
end
diff --git a/spec/workers/ssh_keys/expiring_soon_notification_worker_spec.rb b/spec/workers/ssh_keys/expiring_soon_notification_worker_spec.rb
index e907d035020..ed6701532a5 100644
--- a/spec/workers/ssh_keys/expiring_soon_notification_worker_spec.rb
+++ b/spec/workers/ssh_keys/expiring_soon_notification_worker_spec.rb
@@ -7,7 +7,6 @@ RSpec.describe SshKeys::ExpiringSoonNotificationWorker, type: :worker do
it 'uses a cronjob queue' do
expect(worker.sidekiq_options_hash).to include(
- 'queue' => 'cronjob:ssh_keys_expiring_soon_notification',
'queue_namespace' => :cronjob
)
end
diff --git a/spec/workers/users/deactivate_dormant_users_worker_spec.rb b/spec/workers/users/deactivate_dormant_users_worker_spec.rb
index 263ca31e0a0..a8318de669b 100644
--- a/spec/workers/users/deactivate_dormant_users_worker_spec.rb
+++ b/spec/workers/users/deactivate_dormant_users_worker_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do
using RSpec::Parameterized::TableSyntax
describe '#perform' do
- let_it_be(:dormant) { create(:user, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date) }
+ let_it_be(:dormant) { create(:user, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date) }
let_it_be(:inactive) { create(:user, last_activity_on: nil, created_at: User::MINIMUM_DAYS_CREATED.days.ago.to_date) }
let_it_be(:inactive_recently_created) { create(:user, last_activity_on: nil, created_at: (User::MINIMUM_DAYS_CREATED - 1).days.ago.to_date) }
@@ -14,7 +14,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do
it 'does not run for GitLab.com' do
expect(Gitlab).to receive(:com?).and_return(true)
- expect(Gitlab::CurrentSettings).not_to receive(:current_application_settings)
+ # Now makes a call to current settings to determine period of dormancy
worker.perform
@@ -48,7 +48,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do
end
with_them do
it 'deactivates certain user types' do
- user = create(:user, user_type: user_type, state: :active, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date)
+ user = create(:user, user_type: user_type, state: :active, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date)
worker.perform
@@ -57,8 +57,8 @@ RSpec.describe Users::DeactivateDormantUsersWorker do
end
it 'does not deactivate non-active users' do
- human_user = create(:user, user_type: :human, state: :blocked, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date)
- service_user = create(:user, user_type: :service_user, state: :blocked, last_activity_on: User::MINIMUM_INACTIVE_DAYS.days.ago.to_date)
+ human_user = create(:user, user_type: :human, state: :blocked, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date)
+ service_user = create(:user, user_type: :service_user, state: :blocked, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date)
worker.perform
diff --git a/spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb b/spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb
new file mode 100644
index 00000000000..f42033fdb9c
--- /dev/null
+++ b/spec/workers/users/migrate_records_to_ghost_user_in_batches_worker_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Users::MigrateRecordsToGhostUserInBatchesWorker do
+ include ExclusiveLeaseHelpers
+
+ let(:worker) { described_class.new }
+
+ describe '#perform', :clean_gitlab_redis_shared_state do
+ it 'executes service with lease' do
+ lease_key = described_class.name.underscore
+
+ expect_to_obtain_exclusive_lease(lease_key, 'uuid')
+ expect_next_instance_of(Users::MigrateRecordsToGhostUserInBatchesService) do |service|
+ expect(service).to receive(:execute).and_return(true)
+ end
+
+ worker.perform
+ end
+ end
+
+ include_examples 'an idempotent worker' do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, namespace: create(:group)) }
+ let_it_be(:issue) { create(:issue, project: project, author: user, last_edited_by: user) }
+
+ subject { worker.perform }
+
+ before do
+ create(:ghost_user_migration, user: user, initiator_user: user)
+ end
+
+ it 'migrates issue to ghost user' do
+ subject
+
+ expect(issue.reload.author).to eq(User.ghost)
+ expect(issue.last_edited_by).to eq(User.ghost)
+ end
+ end
+
+ context 'when user_destroy_with_limited_execution_time_worker is disabled' do
+ before do
+ stub_feature_flags(user_destroy_with_limited_execution_time_worker: false)
+ end
+
+ it 'does not execute the service' do
+ expect(Users::MigrateRecordsToGhostUserInBatchesService).not_to receive(:new)
+
+ worker.perform
+ end
+ end
+end