diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /spec/workers | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'spec/workers')
376 files changed, 2555 insertions, 1085 deletions
diff --git a/spec/workers/admin_email_worker_spec.rb b/spec/workers/admin_email_worker_spec.rb index 1a5cb90bc17..bedf8f0362f 100644 --- a/spec/workers/admin_email_worker_spec.rb +++ b/spec/workers/admin_email_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AdminEmailWorker do +RSpec.describe AdminEmailWorker, feature_category: :source_code_management do subject(:worker) { described_class.new } describe '.perform' do diff --git a/spec/workers/analytics/usage_trends/count_job_trigger_worker_spec.rb b/spec/workers/analytics/usage_trends/count_job_trigger_worker_spec.rb index 735e4a214a9..cdb7357c184 100644 --- a/spec/workers/analytics/usage_trends/count_job_trigger_worker_spec.rb +++ b/spec/workers/analytics/usage_trends/count_job_trigger_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Analytics::UsageTrends::CountJobTriggerWorker do +RSpec.describe Analytics::UsageTrends::CountJobTriggerWorker, feature_category: :devops_reports do it_behaves_like 'an idempotent worker' context 'triggers a job for each measurement identifiers' do 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 ee1bbafa9b5..4155e3522a7 100644 --- a/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb +++ b/spec/workers/analytics/usage_trends/counter_job_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Analytics::UsageTrends::CounterJobWorker do +RSpec.describe Analytics::UsageTrends::CounterJobWorker, feature_category: :devops_reports do let_it_be(:user_1) { create(:user) } let_it_be(:user_2) { create(:user) } diff --git a/spec/workers/approve_blocked_pending_approval_users_worker_spec.rb b/spec/workers/approve_blocked_pending_approval_users_worker_spec.rb index bd603bd870d..ffcc58132db 100644 --- a/spec/workers/approve_blocked_pending_approval_users_worker_spec.rb +++ b/spec/workers/approve_blocked_pending_approval_users_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ApproveBlockedPendingApprovalUsersWorker, type: :worker do +RSpec.describe ApproveBlockedPendingApprovalUsersWorker, type: :worker, feature_category: :user_profile do let_it_be(:admin) { create(:admin) } let_it_be(:active_user) { create(:user) } let_it_be(:blocked_user) { create(:user, state: 'blocked_pending_approval') } diff --git a/spec/workers/authorized_keys_worker_spec.rb b/spec/workers/authorized_keys_worker_spec.rb index 50236f9ea7b..9fab6910441 100644 --- a/spec/workers/authorized_keys_worker_spec.rb +++ b/spec/workers/authorized_keys_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AuthorizedKeysWorker do +RSpec.describe AuthorizedKeysWorker, feature_category: :source_code_management do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/authorized_project_update/periodic_recalculate_worker_spec.rb b/spec/workers/authorized_project_update/periodic_recalculate_worker_spec.rb index 9d4d48d0568..77c56497ef0 100644 --- a/spec/workers/authorized_project_update/periodic_recalculate_worker_spec.rb +++ b/spec/workers/authorized_project_update/periodic_recalculate_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AuthorizedProjectUpdate::PeriodicRecalculateWorker do +RSpec.describe AuthorizedProjectUpdate::PeriodicRecalculateWorker, feature_category: :source_code_management do describe '#perform' do it 'calls AuthorizedProjectUpdate::PeriodicRecalculateService' do expect_next_instance_of(AuthorizedProjectUpdate::PeriodicRecalculateService) do |service| diff --git a/spec/workers/authorized_project_update/project_recalculate_per_user_worker_spec.rb b/spec/workers/authorized_project_update/project_recalculate_per_user_worker_spec.rb index 57a0726000f..5dcb4a67ae4 100644 --- a/spec/workers/authorized_project_update/project_recalculate_per_user_worker_spec.rb +++ b/spec/workers/authorized_project_update/project_recalculate_per_user_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AuthorizedProjectUpdate::ProjectRecalculatePerUserWorker do +RSpec.describe AuthorizedProjectUpdate::ProjectRecalculatePerUserWorker, feature_category: :system_access do include ExclusiveLeaseHelpers let_it_be(:project) { create(:project) } diff --git a/spec/workers/authorized_project_update/project_recalculate_worker_spec.rb b/spec/workers/authorized_project_update/project_recalculate_worker_spec.rb index a9a15565580..7c9d2891b01 100644 --- a/spec/workers/authorized_project_update/project_recalculate_worker_spec.rb +++ b/spec/workers/authorized_project_update/project_recalculate_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AuthorizedProjectUpdate::ProjectRecalculateWorker do +RSpec.describe AuthorizedProjectUpdate::ProjectRecalculateWorker, feature_category: :system_access do include ExclusiveLeaseHelpers let_it_be(:project) { create(:project) } diff --git a/spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb b/spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb index da4b726c0b5..e6a312d34ce 100644 --- a/spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb +++ b/spec/workers/authorized_project_update/user_refresh_from_replica_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AuthorizedProjectUpdate::UserRefreshFromReplicaWorker do +RSpec.describe AuthorizedProjectUpdate::UserRefreshFromReplicaWorker, feature_category: :system_access do let_it_be(:project) { create(:project) } let_it_be(:user) { project.namespace.owner } diff --git a/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb b/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb index 7c0c4d5bab4..fcc157f9998 100644 --- a/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb +++ b/spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do +RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker, feature_category: :system_access do let_it_be(:project) { create(:project) } let(:user) { project.namespace.owner } @@ -10,9 +10,7 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do let(:end_user_id) { start_user_id } let(:execute_worker) { subject.perform(start_user_id, end_user_id) } - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed describe '#perform' do context 'checks if project authorization update is required' do diff --git a/spec/workers/authorized_project_update/user_refresh_with_low_urgency_worker_spec.rb b/spec/workers/authorized_project_update/user_refresh_with_low_urgency_worker_spec.rb index bd16eeb4712..ef6c3dd43c8 100644 --- a/spec/workers/authorized_project_update/user_refresh_with_low_urgency_worker_spec.rb +++ b/spec/workers/authorized_project_update/user_refresh_with_low_urgency_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker do +RSpec.describe AuthorizedProjectUpdate::UserRefreshWithLowUrgencyWorker, feature_category: :system_access do it 'is labeled as low urgency' do expect(described_class.get_urgency).to eq(:low) end diff --git a/spec/workers/authorized_projects_worker_spec.rb b/spec/workers/authorized_projects_worker_spec.rb index fbfde77be97..ea009f06a28 100644 --- a/spec/workers/authorized_projects_worker_spec.rb +++ b/spec/workers/authorized_projects_worker_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -RSpec.describe AuthorizedProjectsWorker do +RSpec.describe AuthorizedProjectsWorker, feature_category: :system_access do it_behaves_like "refreshes user's project authorizations" end diff --git a/spec/workers/auto_devops/disable_worker_spec.rb b/spec/workers/auto_devops/disable_worker_spec.rb index e1de97e0ce5..8f7f305b186 100644 --- a/spec/workers/auto_devops/disable_worker_spec.rb +++ b/spec/workers/auto_devops/disable_worker_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe AutoDevops::DisableWorker, '#perform' do +RSpec.describe AutoDevops::DisableWorker, '#perform', feature_category: :auto_devops do let(:user) { create(:user, developer_projects: [project]) } let(:project) { create(:project, :repository, :auto_devops) } let(:auto_devops) { project.auto_devops } diff --git a/spec/workers/auto_merge_process_worker_spec.rb b/spec/workers/auto_merge_process_worker_spec.rb index 00d27d9c2b5..550590ff6a3 100644 --- a/spec/workers/auto_merge_process_worker_spec.rb +++ b/spec/workers/auto_merge_process_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe AutoMergeProcessWorker do +RSpec.describe AutoMergeProcessWorker, feature_category: :continuous_delivery do describe '#perform' do subject { described_class.new.perform(merge_request&.id) } diff --git a/spec/workers/background_migration/ci_database_worker_spec.rb b/spec/workers/background_migration/ci_database_worker_spec.rb index 82c562c4042..3f2977a0aaa 100644 --- a/spec/workers/background_migration/ci_database_worker_spec.rb +++ b/spec/workers/background_migration/ci_database_worker_spec.rb @@ -2,6 +2,10 @@ require 'spec_helper' -RSpec.describe BackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state, if: Gitlab::Database.has_config?(:ci) do +RSpec.describe BackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state, feature_category: :database do + before do + skip_if_shared_database(:ci) + end + it_behaves_like 'it runs background migration jobs', 'ci' end diff --git a/spec/workers/background_migration_worker_spec.rb b/spec/workers/background_migration_worker_spec.rb index 1558c3c9250..32ee6708736 100644 --- a/spec/workers/background_migration_worker_spec.rb +++ b/spec/workers/background_migration_worker_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -RSpec.describe BackgroundMigrationWorker, :clean_gitlab_redis_shared_state do +RSpec.describe BackgroundMigrationWorker, :clean_gitlab_redis_shared_state, feature_category: :database do it_behaves_like 'it runs background migration jobs', 'main' end diff --git a/spec/workers/build_hooks_worker_spec.rb b/spec/workers/build_hooks_worker_spec.rb index 80dc36d268f..adae0417a9a 100644 --- a/spec/workers/build_hooks_worker_spec.rb +++ b/spec/workers/build_hooks_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BuildHooksWorker do +RSpec.describe BuildHooksWorker, feature_category: :continuous_integration do describe '#perform' do context 'when build exists' do let!(:build) { create(:ci_build) } @@ -42,7 +42,5 @@ RSpec.describe BuildHooksWorker do end end - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed end diff --git a/spec/workers/build_queue_worker_spec.rb b/spec/workers/build_queue_worker_spec.rb index 0786722e647..079e11acde3 100644 --- a/spec/workers/build_queue_worker_spec.rb +++ b/spec/workers/build_queue_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BuildQueueWorker do +RSpec.describe BuildQueueWorker, feature_category: :continuous_integration do describe '#perform' do context 'when build exists' do let!(:build) { create(:ci_build) } @@ -24,7 +24,5 @@ RSpec.describe BuildQueueWorker do end end - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :sticky + it_behaves_like 'worker with data consistency', described_class, data_consistency: :sticky end diff --git a/spec/workers/build_success_worker_spec.rb b/spec/workers/build_success_worker_spec.rb index 3241c931dc5..be9802eb2ce 100644 --- a/spec/workers/build_success_worker_spec.rb +++ b/spec/workers/build_success_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BuildSuccessWorker do +RSpec.describe BuildSuccessWorker, feature_category: :continuous_integration do describe '#perform' do subject { described_class.new.perform(build.id) } diff --git a/spec/workers/bulk_imports/entity_worker_spec.rb b/spec/workers/bulk_imports/entity_worker_spec.rb index 4cd37c93d5f..dada4ef63b3 100644 --- a/spec/workers/bulk_imports/entity_worker_spec.rb +++ b/spec/workers/bulk_imports/entity_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BulkImports::EntityWorker do +RSpec.describe BulkImports::EntityWorker, feature_category: :importers do let_it_be(:entity) { create(:bulk_import_entity) } let_it_be(:pipeline_tracker) do diff --git a/spec/workers/bulk_imports/export_request_worker_spec.rb b/spec/workers/bulk_imports/export_request_worker_spec.rb index 7260e0c0f67..2faa28ba489 100644 --- a/spec/workers/bulk_imports/export_request_worker_spec.rb +++ b/spec/workers/bulk_imports/export_request_worker_spec.rb @@ -80,7 +80,7 @@ RSpec.describe BulkImports::ExportRequestWorker, feature_category: :importers do 'source_full_path' => entity.source_full_path, 'exception.backtrace' => anything, 'exception.class' => 'NoMethodError', - 'exception.message' => "undefined method `model_id' for nil:NilClass", + 'exception.message' => /^undefined method `model_id' for nil:NilClass/, 'message' => 'Failed to fetch source entity id', 'importer' => 'gitlab_migration', 'source_version' => entity.bulk_import.source_version_info.to_s diff --git a/spec/workers/bulk_imports/finish_batched_relation_export_worker_spec.rb b/spec/workers/bulk_imports/finish_batched_relation_export_worker_spec.rb new file mode 100644 index 00000000000..6fbcb267c0a --- /dev/null +++ b/spec/workers/bulk_imports/finish_batched_relation_export_worker_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::FinishBatchedRelationExportWorker, feature_category: :importers do + let(:export) { create(:bulk_import_export, :started) } + let(:batch) { create(:bulk_import_export_batch, :finished, export: export) } + let(:export_id) { export.id } + let(:job_args) { [export_id] } + + describe '#perform' do + it_behaves_like 'an idempotent worker' do + it 'marks export as finished and expires batches cache' do + cache_key = BulkImports::BatchedRelationExportService.cache_key(export.id, batch.id) + + expect(Gitlab::Cache::Import::Caching).to receive(:expire).with(cache_key, 0) + + perform_multiple(job_args) + + expect(export.reload.finished?).to eq(true) + end + + context 'when export is finished' do + let(:export) { create(:bulk_import_export, :finished) } + + it 'returns without updating export' do + perform_multiple(job_args) + + expect(export.reload.finished?).to eq(true) + end + end + + context 'when export is failed' do + let(:export) { create(:bulk_import_export, :failed) } + + it 'returns without updating export' do + perform_multiple(job_args) + + expect(export.reload.failed?).to eq(true) + end + end + + context 'when export is in progress' do + it 'reenqueues itself' do + create(:bulk_import_export_batch, :started, export: export) + + expect(described_class).to receive(:perform_in).twice + + perform_multiple(job_args) + + expect(export.reload.started?).to eq(true) + end + end + + context 'when export timed out' do + it 'marks export as failed' do + expect(export.reload.failed?).to eq(false) + expect(batch.reload.failed?).to eq(false) + + export.update!(updated_at: 1.day.ago) + + perform_multiple(job_args) + + expect(export.reload.failed?).to eq(true) + expect(batch.reload.failed?).to eq(true) + end + end + + context 'when export is missing' do + let(:export_id) { nil } + + it 'returns' do + expect(described_class).not_to receive(:perform_in) + + perform_multiple(job_args) + end + end + end + end +end diff --git a/spec/workers/bulk_imports/relation_batch_export_worker_spec.rb b/spec/workers/bulk_imports/relation_batch_export_worker_spec.rb new file mode 100644 index 00000000000..4a2c8d48742 --- /dev/null +++ b/spec/workers/bulk_imports/relation_batch_export_worker_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::RelationBatchExportWorker, feature_category: :importers do + let_it_be(:user) { create(:user) } + let_it_be(:batch) { create(:bulk_import_export_batch) } + + let(:job_args) { [user.id, batch.id] } + + describe '#perform' do + include_examples 'an idempotent worker' do + it 'executes RelationBatchExportService' do + service = instance_double(BulkImports::RelationBatchExportService) + + expect(BulkImports::RelationBatchExportService) + .to receive(:new) + .with(user.id, batch.id) + .twice.and_return(service) + expect(service).to receive(:execute).twice + + perform_multiple(job_args) + end + end + end +end diff --git a/spec/workers/bulk_imports/relation_export_worker_spec.rb b/spec/workers/bulk_imports/relation_export_worker_spec.rb index 63f1992d186..f91db0388a4 100644 --- a/spec/workers/bulk_imports/relation_export_worker_spec.rb +++ b/spec/workers/bulk_imports/relation_export_worker_spec.rb @@ -2,19 +2,20 @@ require 'spec_helper' -RSpec.describe BulkImports::RelationExportWorker do +RSpec.describe BulkImports::RelationExportWorker, feature_category: :importers do let_it_be(:jid) { 'jid' } - let_it_be(:relation) { 'labels' } let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group) } - let(:job_args) { [user.id, group.id, group.class.name, relation] } + let(:batched) { false } + let(:relation) { 'labels' } + let(:job_args) { [user.id, group.id, group.class.name, relation, batched] } describe '#perform' do include_examples 'an idempotent worker' do context 'when export record does not exist' do let(:another_group) { create(:group) } - let(:job_args) { [user.id, another_group.id, another_group.class.name, relation] } + let(:job_args) { [user.id, another_group.id, another_group.class.name, relation, batched] } it 'creates export record' do another_group.add_owner(user) @@ -26,21 +27,53 @@ RSpec.describe BulkImports::RelationExportWorker do end end - it 'executes RelationExportService' do - group.add_owner(user) + shared_examples 'export service' do |export_service| + it 'executes export service' do + group.add_owner(user) - service = instance_double(BulkImports::RelationExportService) + service = instance_double(export_service) - expect(BulkImports::RelationExportService) - .to receive(:new) - .with(user, group, relation, anything) - .twice - .and_return(service) - expect(service) - .to receive(:execute) - .twice + expect(export_service) + .to receive(:new) + .with(user, group, relation, anything) + .twice + .and_return(service) + expect(service).to receive(:execute).twice - perform_multiple(job_args) + perform_multiple(job_args) + end + end + + context 'when export is batched' do + let(:batched) { true } + + context 'when bulk_imports_batched_import_export feature flag is disabled' do + before do + stub_feature_flags(bulk_imports_batched_import_export: false) + end + + include_examples 'export service', BulkImports::RelationExportService + end + + context 'when bulk_imports_batched_import_export feature flag is enabled' do + before do + stub_feature_flags(bulk_imports_batched_import_export: true) + end + + context 'when relation is batchable' do + include_examples 'export service', BulkImports::BatchedRelationExportService + end + + context 'when relation is not batchable' do + let(:relation) { 'namespace_settings' } + + include_examples 'export service', BulkImports::RelationExportService + end + end + end + + context 'when export is not batched' do + include_examples 'export service', BulkImports::RelationExportService end end end diff --git a/spec/workers/bulk_imports/stuck_import_worker_spec.rb b/spec/workers/bulk_imports/stuck_import_worker_spec.rb index 7dfb6532c07..ba1b1b66b00 100644 --- a/spec/workers/bulk_imports/stuck_import_worker_spec.rb +++ b/spec/workers/bulk_imports/stuck_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BulkImports::StuckImportWorker do +RSpec.describe BulkImports::StuckImportWorker, feature_category: :importers do let_it_be(:created_bulk_import) { create(:bulk_import, :created) } let_it_be(:started_bulk_import) { create(:bulk_import, :started) } let_it_be(:stale_created_bulk_import) { create(:bulk_import, :created, created_at: 3.days.ago) } diff --git a/spec/workers/chat_notification_worker_spec.rb b/spec/workers/chat_notification_worker_spec.rb index a20a136d197..a9413a94e4b 100644 --- a/spec/workers/chat_notification_worker_spec.rb +++ b/spec/workers/chat_notification_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ChatNotificationWorker do +RSpec.describe ChatNotificationWorker, feature_category: :integrations do let(:worker) { described_class.new } let(:chat_build) do create(:ci_build, pipeline: create(:ci_pipeline, source: :chat)) diff --git a/spec/workers/ci/archive_trace_worker_spec.rb b/spec/workers/ci/archive_trace_worker_spec.rb index 3ac769aab9e..056093f01b4 100644 --- a/spec/workers/ci/archive_trace_worker_spec.rb +++ b/spec/workers/ci/archive_trace_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::ArchiveTraceWorker do +RSpec.describe Ci::ArchiveTraceWorker, feature_category: :continuous_integration do describe '#perform' do subject { described_class.new.perform(job&.id) } diff --git a/spec/workers/ci/archive_traces_cron_worker_spec.rb b/spec/workers/ci/archive_traces_cron_worker_spec.rb index 0c1010960a1..1eb88258c62 100644 --- a/spec/workers/ci/archive_traces_cron_worker_spec.rb +++ b/spec/workers/ci/archive_traces_cron_worker_spec.rb @@ -42,20 +42,6 @@ RSpec.describe Ci::ArchiveTracesCronWorker, feature_category: :continuous_integr subject end - context "with FF deduplicate_archive_traces_cron_worker false" do - before do - stub_feature_flags(deduplicate_archive_traces_cron_worker: false) - end - - it 'calls execute service' do - expect_next_instance_of(Ci::ArchiveTraceService) do |instance| - expect(instance).to receive(:execute).with(build, worker_name: "Ci::ArchiveTracesCronWorker") - end - - subject - end - end - context 'when the job finished recently' do let(:finished_at) { 1.hour.ago } diff --git a/spec/workers/ci/build_finished_worker_spec.rb b/spec/workers/ci/build_finished_worker_spec.rb index 049f3af1dd7..6da30a86b54 100644 --- a/spec/workers/ci/build_finished_worker_spec.rb +++ b/spec/workers/ci/build_finished_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::BuildFinishedWorker do +RSpec.describe Ci::BuildFinishedWorker, feature_category: :continuous_integration do include AfterNextHelpers subject { described_class.new.perform(build.id) } diff --git a/spec/workers/ci/build_prepare_worker_spec.rb b/spec/workers/ci/build_prepare_worker_spec.rb index b2c74a920ea..d3d607d8f39 100644 --- a/spec/workers/ci/build_prepare_worker_spec.rb +++ b/spec/workers/ci/build_prepare_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::BuildPrepareWorker do +RSpec.describe Ci::BuildPrepareWorker, feature_category: :continuous_integration do subject { described_class.new.perform(build_id) } context 'build exists' do diff --git a/spec/workers/ci/build_schedule_worker_spec.rb b/spec/workers/ci/build_schedule_worker_spec.rb index f8b4efc562b..f0d43ef810d 100644 --- a/spec/workers/ci/build_schedule_worker_spec.rb +++ b/spec/workers/ci/build_schedule_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::BuildScheduleWorker do +RSpec.describe Ci::BuildScheduleWorker, feature_category: :continuous_integration do subject { described_class.new.perform(build.id) } context 'when build is found' do diff --git a/spec/workers/ci/build_trace_chunk_flush_worker_spec.rb b/spec/workers/ci/build_trace_chunk_flush_worker_spec.rb index 8aac80a02be..851b8f6bc90 100644 --- a/spec/workers/ci/build_trace_chunk_flush_worker_spec.rb +++ b/spec/workers/ci/build_trace_chunk_flush_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::BuildTraceChunkFlushWorker do +RSpec.describe Ci::BuildTraceChunkFlushWorker, feature_category: :continuous_integration do let(:data) { 'x' * Ci::BuildTraceChunk::CHUNK_SIZE } let(:chunk) do diff --git a/spec/workers/ci/cancel_pipeline_worker_spec.rb b/spec/workers/ci/cancel_pipeline_worker_spec.rb index 6165aaff1c7..874273a39e1 100644 --- a/spec/workers/ci/cancel_pipeline_worker_spec.rb +++ b/spec/workers/ci/cancel_pipeline_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::CancelPipelineWorker, :aggregate_failures do +RSpec.describe Ci::CancelPipelineWorker, :aggregate_failures, feature_category: :continuous_integration do let!(:pipeline) { create(:ci_pipeline, :running) } describe '#perform' do diff --git a/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb b/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb deleted file mode 100644 index 372b0de1b54..00000000000 --- a/spec/workers/ci/create_cross_project_pipeline_worker_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Ci::CreateCrossProjectPipelineWorker do - let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } - let_it_be(:pipeline) { create(:ci_pipeline, project: project) } - - let(:bridge) { create(:ci_bridge, user: user, pipeline: pipeline) } - - let(:service) { double('pipeline creation service') } - - describe '#perform' do - context 'when bridge exists' do - it 'calls cross project pipeline creation service' do - expect(Ci::CreateDownstreamPipelineService) - .to receive(:new) - .with(project, user) - .and_return(service) - - expect(service).to receive(:execute).with(bridge) - - described_class.new.perform(bridge.id) - end - end - - context 'when bridge does not exist' do - it 'does nothing' do - expect(Ci::CreateDownstreamPipelineService) - .not_to receive(:new) - - described_class.new.perform(non_existing_record_id) - end - end - end -end diff --git a/spec/workers/ci/create_downstream_pipeline_worker_spec.rb b/spec/workers/ci/create_downstream_pipeline_worker_spec.rb index b4add681e67..bb763e68504 100644 --- a/spec/workers/ci/create_downstream_pipeline_worker_spec.rb +++ b/spec/workers/ci/create_downstream_pipeline_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::CreateDownstreamPipelineWorker do +RSpec.describe Ci::CreateDownstreamPipelineWorker, feature_category: :continuous_integration do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } diff --git a/spec/workers/ci/daily_build_group_report_results_worker_spec.rb b/spec/workers/ci/daily_build_group_report_results_worker_spec.rb index e13c6311e46..3d86ff6999b 100644 --- a/spec/workers/ci/daily_build_group_report_results_worker_spec.rb +++ b/spec/workers/ci/daily_build_group_report_results_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::DailyBuildGroupReportResultsWorker do +RSpec.describe Ci::DailyBuildGroupReportResultsWorker, feature_category: :code_testing do describe '#perform' do let!(:pipeline) { create(:ci_pipeline) } diff --git a/spec/workers/ci/delete_objects_worker_spec.rb b/spec/workers/ci/delete_objects_worker_spec.rb index 3d985dffdc5..808ad95531e 100644 --- a/spec/workers/ci/delete_objects_worker_spec.rb +++ b/spec/workers/ci/delete_objects_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::DeleteObjectsWorker do +RSpec.describe Ci::DeleteObjectsWorker, feature_category: :continuous_integration do let(:worker) { described_class.new } it { expect(described_class.idempotent?).to be_truthy } diff --git a/spec/workers/ci/delete_unit_tests_worker_spec.rb b/spec/workers/ci/delete_unit_tests_worker_spec.rb index ff2575b19c1..ae8fe762334 100644 --- a/spec/workers/ci/delete_unit_tests_worker_spec.rb +++ b/spec/workers/ci/delete_unit_tests_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::DeleteUnitTestsWorker do +RSpec.describe Ci::DeleteUnitTestsWorker, feature_category: :code_testing do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/ci/drop_pipeline_worker_spec.rb b/spec/workers/ci/drop_pipeline_worker_spec.rb index 5e626112520..23ae95ee53a 100644 --- a/spec/workers/ci/drop_pipeline_worker_spec.rb +++ b/spec/workers/ci/drop_pipeline_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::DropPipelineWorker do +RSpec.describe Ci::DropPipelineWorker, feature_category: :continuous_integration do include AfterNextHelpers let(:pipeline) { create(:ci_pipeline, :running) } diff --git a/spec/workers/ci/job_artifacts/expire_project_build_artifacts_worker_spec.rb b/spec/workers/ci/job_artifacts/expire_project_build_artifacts_worker_spec.rb index 0460738f3f2..9d4e5380474 100644 --- a/spec/workers/ci/job_artifacts/expire_project_build_artifacts_worker_spec.rb +++ b/spec/workers/ci/job_artifacts/expire_project_build_artifacts_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::JobArtifacts::ExpireProjectBuildArtifactsWorker do +RSpec.describe Ci::JobArtifacts::ExpireProjectBuildArtifactsWorker, feature_category: :build_artifacts do let(:worker) { described_class.new } let(:current_time) { Time.current } 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 index 0d4b8243050..9c3d249c6aa 100644 --- a/spec/workers/ci/job_artifacts/track_artifact_report_worker_spec.rb +++ b/spec/workers/ci/job_artifacts/track_artifact_report_worker_spec.rb @@ -2,15 +2,14 @@ require 'spec_helper' -RSpec.describe Ci::JobArtifacts::TrackArtifactReportWorker do +RSpec.describe Ci::JobArtifacts::TrackArtifactReportWorker, feature_category: :code_testing 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) do - create(:ci_pipeline, :with_test_reports, :with_coverage_reports, - project: project, user: user) + create(:ci_pipeline, :with_test_reports, :with_coverage_reports, project: project, user: user) end subject(:perform) { described_class.new.perform(pipeline_id) } diff --git a/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb b/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb index e5de0ba0143..ec12ee845a4 100644 --- a/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb +++ b/spec/workers/ci/merge_requests/add_todo_when_build_fails_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::MergeRequests::AddTodoWhenBuildFailsWorker do +RSpec.describe Ci::MergeRequests::AddTodoWhenBuildFailsWorker, feature_category: :code_review_workflow do describe '#perform' do let_it_be(:project) { create(:project) } let_it_be(:pipeline) { create(:ci_pipeline, :detached_merge_request_pipeline) } diff --git a/spec/workers/ci/parse_secure_file_metadata_worker_spec.rb b/spec/workers/ci/parse_secure_file_metadata_worker_spec.rb index 57bbd8a6ff0..11a01352fcc 100644 --- a/spec/workers/ci/parse_secure_file_metadata_worker_spec.rb +++ b/spec/workers/ci/parse_secure_file_metadata_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::ParseSecureFileMetadataWorker do +RSpec.describe Ci::ParseSecureFileMetadataWorker, feature_category: :mobile_devops do describe '#perform' do include_examples 'an idempotent worker' do let(:secure_file) { create(:ci_secure_file) } diff --git a/spec/workers/ci/pending_builds/update_group_worker_spec.rb b/spec/workers/ci/pending_builds/update_group_worker_spec.rb index 8c6bf018158..c16262c0502 100644 --- a/spec/workers/ci/pending_builds/update_group_worker_spec.rb +++ b/spec/workers/ci/pending_builds/update_group_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PendingBuilds::UpdateGroupWorker do +RSpec.describe Ci::PendingBuilds::UpdateGroupWorker, feature_category: :subgroups do describe '#perform' do let(:worker) { described_class.new } diff --git a/spec/workers/ci/pending_builds/update_project_worker_spec.rb b/spec/workers/ci/pending_builds/update_project_worker_spec.rb index 4a67127564e..281b4fb920b 100644 --- a/spec/workers/ci/pending_builds/update_project_worker_spec.rb +++ b/spec/workers/ci/pending_builds/update_project_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PendingBuilds::UpdateProjectWorker do +RSpec.describe Ci::PendingBuilds::UpdateProjectWorker, feature_category: :projects do describe '#perform' do let(:worker) { described_class.new } 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 7b28384a5bf..b594f661a9a 100644 --- a/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb +++ b/spec/workers/ci/pipeline_artifacts/coverage_report_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PipelineArtifacts::CoverageReportWorker do +RSpec.describe Ci::PipelineArtifacts::CoverageReportWorker, feature_category: :code_testing do describe '#perform' do let(:pipeline_id) { pipeline.id } diff --git a/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb index 5096691270a..2ad1609c7c4 100644 --- a/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb +++ b/spec/workers/ci/pipeline_artifacts/create_quality_report_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Ci::PipelineArtifacts::CreateQualityReportWorker do +RSpec.describe ::Ci::PipelineArtifacts::CreateQualityReportWorker, feature_category: :code_quality do describe '#perform' do subject { described_class.new.perform(pipeline_id) } diff --git a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb index 274f848ad88..ca4fcc564fa 100644 --- a/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb +++ b/spec/workers/ci/pipeline_artifacts/expire_artifacts_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do +RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker, feature_category: :build_artifacts do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/ci/pipeline_bridge_status_worker_spec.rb b/spec/workers/ci/pipeline_bridge_status_worker_spec.rb index 6ec5eb0e639..4662b25a3cb 100644 --- a/spec/workers/ci/pipeline_bridge_status_worker_spec.rb +++ b/spec/workers/ci/pipeline_bridge_status_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PipelineBridgeStatusWorker do +RSpec.describe Ci::PipelineBridgeStatusWorker, feature_category: :continuous_integration do describe '#perform' do subject { described_class.new.perform(pipeline_id) } diff --git a/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb b/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb index 3b33972c76f..70821f3a833 100644 --- a/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb +++ b/spec/workers/ci/pipeline_success_unlock_artifacts_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::PipelineSuccessUnlockArtifactsWorker do +RSpec.describe Ci::PipelineSuccessUnlockArtifactsWorker, feature_category: :build_artifacts do describe '#perform' do subject(:perform) { described_class.new.perform(pipeline_id) } diff --git a/spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb b/spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb index f14b7f9d1d0..ede4dad1272 100644 --- a/spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb +++ b/spec/workers/ci/ref_delete_unlock_artifacts_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::RefDeleteUnlockArtifactsWorker do +RSpec.describe Ci::RefDeleteUnlockArtifactsWorker, feature_category: :build_artifacts do describe '#perform' do subject(:perform) { worker.perform(project_id, user_id, ref) } diff --git a/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb b/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb index 785cba24f9d..e3e7047db56 100644 --- a/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb +++ b/spec/workers/ci/resource_groups/assign_resource_from_resource_group_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::ResourceGroups::AssignResourceFromResourceGroupWorker do +RSpec.describe Ci::ResourceGroups::AssignResourceFromResourceGroupWorker, feature_category: :continuous_delivery do let(:worker) { described_class.new } it 'has the `until_executed` deduplicate strategy' do diff --git a/spec/workers/ci/retry_pipeline_worker_spec.rb b/spec/workers/ci/retry_pipeline_worker_spec.rb index c7600a24280..f41b6b88c6f 100644 --- a/spec/workers/ci/retry_pipeline_worker_spec.rb +++ b/spec/workers/ci/retry_pipeline_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::RetryPipelineWorker do +RSpec.describe Ci::RetryPipelineWorker, feature_category: :continuous_integration do describe '#perform' do subject(:perform) { described_class.new.perform(pipeline_id, user_id) } diff --git a/spec/workers/ci/runners/stale_machines_cleanup_cron_worker_spec.rb b/spec/workers/ci/runners/stale_machines_cleanup_cron_worker_spec.rb index d8f620bc024..619012eaa6e 100644 --- a/spec/workers/ci/runners/stale_machines_cleanup_cron_worker_spec.rb +++ b/spec/workers/ci/runners/stale_machines_cleanup_cron_worker_spec.rb @@ -8,16 +8,16 @@ RSpec.describe Ci::Runners::StaleMachinesCleanupCronWorker, feature_category: :r describe '#perform', :freeze_time do subject(:perform) { worker.perform } - let!(:runner_machine1) do + let!(:runner_manager1) do create(:ci_runner_machine, created_at: 7.days.ago, contacted_at: 7.days.ago) end - let!(:runner_machine2) { create(:ci_runner_machine) } - let!(:runner_machine3) { create(:ci_runner_machine, created_at: 6.days.ago) } + let!(:runner_manager2) { create(:ci_runner_machine) } + let!(:runner_manager3) { create(:ci_runner_machine, created_at: 6.days.ago) } it_behaves_like 'an idempotent worker' do it 'delegates to Ci::Runners::StaleMachinesCleanupService' do - expect_next_instance_of(Ci::Runners::StaleMachinesCleanupService) do |service| + expect_next_instance_of(Ci::Runners::StaleManagersCleanupService) do |service| expect(service) .to receive(:execute).and_call_original end @@ -26,16 +26,16 @@ RSpec.describe Ci::Runners::StaleMachinesCleanupCronWorker, feature_category: :r expect(worker.logging_extras).to eq({ "extra.ci_runners_stale_machines_cleanup_cron_worker.status" => :success, - "extra.ci_runners_stale_machines_cleanup_cron_worker.deleted_machines" => true + "extra.ci_runners_stale_machines_cleanup_cron_worker.deleted_managers" => true }) end - it 'cleans up stale runner machines', :aggregate_failures do - expect(Ci::RunnerMachine.stale.count).to eq 1 + it 'cleans up stale runner managers', :aggregate_failures do + expect(Ci::RunnerManager.stale.count).to eq 1 - expect { perform }.to change { Ci::RunnerMachine.count }.from(3).to(2) + expect { perform }.to change { Ci::RunnerManager.count }.from(3).to(2) - expect(Ci::RunnerMachine.all).to match_array [runner_machine2, runner_machine3] + expect(Ci::RunnerManager.all).to match_array [runner_manager2, runner_manager3] end end end diff --git a/spec/workers/ci/schedule_delete_objects_cron_worker_spec.rb b/spec/workers/ci/schedule_delete_objects_cron_worker_spec.rb index 142df271f90..cab282df5f2 100644 --- a/spec/workers/ci/schedule_delete_objects_cron_worker_spec.rb +++ b/spec/workers/ci/schedule_delete_objects_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::ScheduleDeleteObjectsCronWorker do +RSpec.describe Ci::ScheduleDeleteObjectsCronWorker, feature_category: :continuous_integration do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb b/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb index 6d3aa71fe81..6823686997f 100644 --- a/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb +++ b/spec/workers/ci/stuck_builds/drop_running_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::StuckBuilds::DropRunningWorker do +RSpec.describe Ci::StuckBuilds::DropRunningWorker, feature_category: :continuous_integration do include ExclusiveLeaseHelpers let(:worker) { described_class.new } diff --git a/spec/workers/ci/stuck_builds/drop_scheduled_worker_spec.rb b/spec/workers/ci/stuck_builds/drop_scheduled_worker_spec.rb index 57be799d890..58b07d11d33 100644 --- a/spec/workers/ci/stuck_builds/drop_scheduled_worker_spec.rb +++ b/spec/workers/ci/stuck_builds/drop_scheduled_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::StuckBuilds::DropScheduledWorker do +RSpec.describe Ci::StuckBuilds::DropScheduledWorker, feature_category: :continuous_integration do include ExclusiveLeaseHelpers let(:worker) { described_class.new } diff --git a/spec/workers/ci/test_failure_history_worker_spec.rb b/spec/workers/ci/test_failure_history_worker_spec.rb index 7530077d4ad..bf8ec44ce4d 100644 --- a/spec/workers/ci/test_failure_history_worker_spec.rb +++ b/spec/workers/ci/test_failure_history_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Ci::TestFailureHistoryWorker do +RSpec.describe ::Ci::TestFailureHistoryWorker, feature_category: :static_application_security_testing do describe '#perform' do subject(:perform) { described_class.new.perform(pipeline_id) } diff --git a/spec/workers/ci/track_failed_build_worker_spec.rb b/spec/workers/ci/track_failed_build_worker_spec.rb index 12d0e64afc5..5d12e86d844 100644 --- a/spec/workers/ci/track_failed_build_worker_spec.rb +++ b/spec/workers/ci/track_failed_build_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Ci::TrackFailedBuildWorker do +RSpec.describe ::Ci::TrackFailedBuildWorker, feature_category: :static_application_security_testing do let_it_be(:build) { create(:ci_build, :failed, :sast_report) } let_it_be(:exit_code) { 42 } let_it_be(:failure_reason) { "script_failure" } diff --git a/spec/workers/ci/update_locked_unknown_artifacts_worker_spec.rb b/spec/workers/ci/update_locked_unknown_artifacts_worker_spec.rb index b42d135b1b6..4bb1d3561f9 100644 --- a/spec/workers/ci/update_locked_unknown_artifacts_worker_spec.rb +++ b/spec/workers/ci/update_locked_unknown_artifacts_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Ci::UpdateLockedUnknownArtifactsWorker do +RSpec.describe Ci::UpdateLockedUnknownArtifactsWorker, feature_category: :build_artifacts do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/ci_platform_metrics_update_cron_worker_spec.rb b/spec/workers/ci_platform_metrics_update_cron_worker_spec.rb index 0bb6822a0a5..ac00956e1c0 100644 --- a/spec/workers/ci_platform_metrics_update_cron_worker_spec.rb +++ b/spec/workers/ci_platform_metrics_update_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe CiPlatformMetricsUpdateCronWorker, type: :worker do +RSpec.describe CiPlatformMetricsUpdateCronWorker, type: :worker, feature_category: :continuous_integration do describe '#perform' do subject { described_class.new.perform } diff --git a/spec/workers/cleanup_container_repository_worker_spec.rb b/spec/workers/cleanup_container_repository_worker_spec.rb index 817b71c8cc6..c970c9ef842 100644 --- a/spec/workers/cleanup_container_repository_worker_spec.rb +++ b/spec/workers/cleanup_container_repository_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe CleanupContainerRepositoryWorker, :clean_gitlab_redis_shared_state do +RSpec.describe CleanupContainerRepositoryWorker, :clean_gitlab_redis_shared_state, feature_category: :container_registry do let(:repository) { create(:container_repository) } let(:project) { repository.project } let(:user) { project.first_owner } diff --git a/spec/workers/clusters/agents/delete_expired_events_worker_spec.rb b/spec/workers/clusters/agents/delete_expired_events_worker_spec.rb index 1a5ca744091..8f2bd189d5c 100644 --- a/spec/workers/clusters/agents/delete_expired_events_worker_spec.rb +++ b/spec/workers/clusters/agents/delete_expired_events_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Agents::DeleteExpiredEventsWorker do +RSpec.describe Clusters::Agents::DeleteExpiredEventsWorker, feature_category: :deployment_management do let(:agent) { create(:cluster_agent) } describe '#perform' do diff --git a/spec/workers/clusters/agents/notify_git_push_worker_spec.rb b/spec/workers/clusters/agents/notify_git_push_worker_spec.rb new file mode 100644 index 00000000000..561a66b86e9 --- /dev/null +++ b/spec/workers/clusters/agents/notify_git_push_worker_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Clusters::Agents::NotifyGitPushWorker, feature_category: :deployment_management do + let_it_be(:project) { create(:project) } + + describe '#perform' do + let(:project_id) { project.id } + let(:kas_client) { instance_double(Gitlab::Kas::Client) } + + subject { described_class.new.perform(project_id) } + + it 'calls the deletion service' do + expect(Gitlab::Kas::Client).to receive(:new).and_return(kas_client) + expect(kas_client).to receive(:send_git_push_event).with(project: project) + + subject + end + + context 'when the project no longer exists' do + let(:project_id) { -1 } + + it 'completes without raising an error' do + expect { subject }.not_to raise_error + end + end + + context 'when the :notify_kas_on_git_push feature flag is disabled' do + before do + stub_feature_flags(notify_kas_on_git_push: false) + end + + it 'does not notify KAS' do + expect(Gitlab::Kas::Client).not_to receive(:new) + + subject + end + end + end +end diff --git a/spec/workers/clusters/applications/activate_integration_worker_spec.rb b/spec/workers/clusters/applications/activate_integration_worker_spec.rb index 5163e4681fa..58b133aa6de 100644 --- a/spec/workers/clusters/applications/activate_integration_worker_spec.rb +++ b/spec/workers/clusters/applications/activate_integration_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Applications::ActivateIntegrationWorker, '#perform' do +RSpec.describe Clusters::Applications::ActivateIntegrationWorker, '#perform', feature_category: :deployment_management do context 'when cluster exists' do describe 'prometheus integration' do let(:integration_name) { 'prometheus' } diff --git a/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb b/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb index 62792a3b7d9..5f7cd786ea3 100644 --- a/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb +++ b/spec/workers/clusters/applications/deactivate_integration_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Applications::DeactivateIntegrationWorker, '#perform' do +RSpec.describe Clusters::Applications::DeactivateIntegrationWorker, '#perform', feature_category: :deployment_management do context 'when cluster exists' do describe 'prometheus integration' do let(:integration_name) { 'prometheus' } diff --git a/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb b/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb index c24ca71eb35..7119664d706 100644 --- a/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb +++ b/spec/workers/clusters/cleanup/project_namespace_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Cleanup::ProjectNamespaceWorker do +RSpec.describe Clusters::Cleanup::ProjectNamespaceWorker, feature_category: :deployment_management do describe '#perform' do context 'when cluster.cleanup_status is cleanup_removing_project_namespaces' do let!(:cluster) { create(:cluster, :with_environments, :cleanup_removing_project_namespaces) } @@ -27,7 +27,6 @@ RSpec.describe Clusters::Cleanup::ProjectNamespaceWorker do exception: 'ClusterCleanupMethods::ExceededExecutionLimitError', cluster_id: kind_of(Integer), class_name: described_class.name, - applications: "", cleanup_status: cluster.cleanup_status_name, event: :failed_to_remove_cluster_and_resources, message: "exceeded execution limit of 10 tries" diff --git a/spec/workers/clusters/cleanup/service_account_worker_spec.rb b/spec/workers/clusters/cleanup/service_account_worker_spec.rb index dabc32a0ccd..cc388841c91 100644 --- a/spec/workers/clusters/cleanup/service_account_worker_spec.rb +++ b/spec/workers/clusters/cleanup/service_account_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Cleanup::ServiceAccountWorker do +RSpec.describe Clusters::Cleanup::ServiceAccountWorker, feature_category: :deployment_management do describe '#perform' do let!(:cluster) { create(:cluster, :cleanup_removing_service_account) } diff --git a/spec/workers/clusters/integrations/check_prometheus_health_worker_spec.rb b/spec/workers/clusters/integrations/check_prometheus_health_worker_spec.rb index 6f70870bd09..1f5892a36da 100644 --- a/spec/workers/clusters/integrations/check_prometheus_health_worker_spec.rb +++ b/spec/workers/clusters/integrations/check_prometheus_health_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Clusters::Integrations::CheckPrometheusHealthWorker, '#perform' do +RSpec.describe Clusters::Integrations::CheckPrometheusHealthWorker, '#perform', feature_category: :incident_management do subject { described_class.new.perform } it 'triggers health service' do diff --git a/spec/workers/concerns/application_worker_spec.rb b/spec/workers/concerns/application_worker_spec.rb index 0abb029f146..e4df91adef2 100644 --- a/spec/workers/concerns/application_worker_spec.rb +++ b/spec/workers/concerns/application_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ApplicationWorker do +RSpec.describe ApplicationWorker, feature_category: :shared do # We depend on the lazy-load characteristic of rspec. If the worker is loaded # before setting up, it's likely to go wrong. Consider this catcha: # before do diff --git a/spec/workers/concerns/cluster_agent_queue_spec.rb b/spec/workers/concerns/cluster_agent_queue_spec.rb index b5189cbd8c8..77417601748 100644 --- a/spec/workers/concerns/cluster_agent_queue_spec.rb +++ b/spec/workers/concerns/cluster_agent_queue_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ClusterAgentQueue do +RSpec.describe ClusterAgentQueue, feature_category: :deployment_management do let(:worker) do Class.new do def self.name @@ -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) } + it { expect(worker.get_feature_category).to eq(:deployment_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..26680fcc870 100644 --- a/spec/workers/concerns/cronjob_queue_spec.rb +++ b/spec/workers/concerns/cronjob_queue_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe CronjobQueue do +RSpec.describe CronjobQueue, feature_category: :shared do let(:worker) do Class.new do def self.name @@ -40,15 +40,11 @@ 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 - it 'automatically clears project, user and namespace from the context', :aggregate_failues do + it 'automatically clears project, user and namespace from the context', :aggregate_failures do worker_context = worker.get_worker_context.to_lazy_hash.transform_values { |v| v.try(:call) } expect(worker_context[:user]).to be_nil 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 02190201986..18a3e3c2c5b 100644 --- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do +RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, feature_category: :importers do let(:worker) do Class.new do def self.name @@ -30,7 +30,8 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do let(:github_identifiers) do { some_id: 1, - some_type: '_some_type_' + some_type: '_some_type_', + object_type: 'dummy' } end @@ -52,7 +53,8 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do def github_identifiers { some_id: 1, - some_type: '_some_type_' + some_type: '_some_type_', + object_type: 'dummy' } end end @@ -196,6 +198,19 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do end context 'when the record is invalid' do + let(:exception) { ActiveRecord::RecordInvalid.new } + + before do + expect(importer_class) + .to receive(:new) + .with(instance_of(MockRepresantation), project, client) + .and_return(importer_instance) + + expect(importer_instance) + .to receive(:execute) + .and_raise(exception) + end + it 'logs an error' do expect(Gitlab::GithubImport::Logger) .to receive(:info) @@ -208,16 +223,6 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do } ) - expect(importer_class) - .to receive(:new) - .with(instance_of(MockRepresantation), project, client) - .and_return(importer_instance) - - exception = ActiveRecord::RecordInvalid.new - expect(importer_instance) - .to receive(:execute) - .and_raise(exception) - expect(Gitlab::Import::ImportFailureService) .to receive(:track) .with( @@ -230,6 +235,15 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do worker.import(project, client, { 'number' => 10, 'github_id' => 1 }) end + + it 'updates external_identifiers of the correct failure' do + worker.import(project, client, { 'number' => 10, 'github_id' => 1 }) + + import_failures = project.import_failures + + expect(import_failures.count).to eq(1) + expect(import_failures.first.external_identifiers).to eq(github_identifiers.with_indifferent_access) + end end end @@ -240,4 +254,56 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do expect(worker).to be_increment_object_counter(issue) end end + + describe '.sidekiq_retries_exhausted' do + let(:correlation_id) { 'abc' } + let(:job) do + { + 'args' => [project.id, { number: 123, state: 'open' }, '123abc'], + 'jid' => '123', + 'correlation_id' => correlation_id + } + end + + subject(:sidekiq_retries_exhausted) { worker.class.sidekiq_retries_exhausted_block.call(job, StandardError.new) } + + context 'when all arguments are given' do + it 'notifies the JobWaiter' do + expect(Gitlab::JobWaiter) + .to receive(:notify) + .with( + job['args'].last, + job['jid'] + ) + + sidekiq_retries_exhausted + end + end + + context 'when not all arguments are given' do + let(:job) do + { + 'args' => [project.id, { number: 123, state: 'open' }], + 'jid' => '123', + 'correlation_id' => correlation_id + } + end + + it 'does not notify the JobWaiter' do + expect(Gitlab::JobWaiter).not_to receive(:notify) + + sidekiq_retries_exhausted + end + end + + it 'updates external_identifiers of the correct failure' do + failure_1, failure_2 = create_list(:import_failure, 2, project: project) + failure_2.update_column(:correlation_id_value, correlation_id) + + sidekiq_retries_exhausted + + expect(failure_1.reload.external_identifiers).to be_empty + expect(failure_2.reload.external_identifiers).to eq(github_identifiers.with_indifferent_access) + end + end 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/gitlab/github_import/rescheduling_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb index 8727756ce50..cdaff2fc1f4 100644 --- a/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ReschedulingMethods do +RSpec.describe Gitlab::GithubImport::ReschedulingMethods, feature_category: :importers do let(:worker) do Class.new { include(Gitlab::GithubImport::ReschedulingMethods) }.new end @@ -25,9 +25,15 @@ RSpec.describe Gitlab::GithubImport::ReschedulingMethods do end end - context 'with an existing project' do + context 'with an existing project', :clean_gitlab_redis_cache do let(:project) { create(:project, import_url: 'https://t0ken@github.com/repo/repo.git') } + before do + allow_next_instance_of(Gitlab::GithubImport::Client) do |instance| + allow(instance).to receive(:rate_limit_resets_in).and_return(14) + end + end + it 'notifies any waiters upon successfully importing the data' do expect(worker) .to receive(:try_import) @@ -57,13 +63,13 @@ RSpec.describe Gitlab::GithubImport::ReschedulingMethods do expect(worker) .not_to receive(:notify_waiter) - expect_next_instance_of(Gitlab::GithubImport::Client) do |instance| - expect(instance).to receive(:rate_limit_resets_in).and_return(14) - end + expect(worker) + .to receive(:object_type) + .and_return(:pull_request) expect(worker.class) .to receive(:perform_in) - .with(14, project.id, { 'number' => 2 }, '123') + .with(15, project.id, { 'number' => 2 }, '123') worker.perform(project.id, { 'number' => 2 }, '123') end 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 0ac1733781a..ce9a9db5dd9 100644 --- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::StageMethods do +RSpec.describe Gitlab::GithubImport::StageMethods, feature_category: :importers 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) } diff --git a/spec/workers/concerns/gitlab/notify_upon_death_spec.rb b/spec/workers/concerns/gitlab/notify_upon_death_spec.rb index dd0a1cadc9c..36faf3ee296 100644 --- a/spec/workers/concerns/gitlab/notify_upon_death_spec.rb +++ b/spec/workers/concerns/gitlab/notify_upon_death_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::NotifyUponDeath do +RSpec.describe Gitlab::NotifyUponDeath, feature_category: :shared do let(:worker_class) do Class.new do include Sidekiq::Worker diff --git a/spec/workers/concerns/limited_capacity/job_tracker_spec.rb b/spec/workers/concerns/limited_capacity/job_tracker_spec.rb index 0e3fa350fcd..20635d1a045 100644 --- a/spec/workers/concerns/limited_capacity/job_tracker_spec.rb +++ b/spec/workers/concerns/limited_capacity/job_tracker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe LimitedCapacity::JobTracker, :clean_gitlab_redis_shared_state do +RSpec.describe LimitedCapacity::JobTracker, :clean_gitlab_redis_shared_state, feature_category: :shared do let(:job_tracker) do described_class.new('namespace') end diff --git a/spec/workers/concerns/limited_capacity/worker_spec.rb b/spec/workers/concerns/limited_capacity/worker_spec.rb index 790b5c3544d..65906eef0fa 100644 --- a/spec/workers/concerns/limited_capacity/worker_spec.rb +++ b/spec/workers/concerns/limited_capacity/worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe LimitedCapacity::Worker, :clean_gitlab_redis_queues, :aggregate_failures do +RSpec.describe LimitedCapacity::Worker, :clean_gitlab_redis_queues, :aggregate_failures, feature_category: :shared do let(:worker_class) do Class.new do def self.name diff --git a/spec/workers/concerns/packages/cleanup_artifact_worker_spec.rb b/spec/workers/concerns/packages/cleanup_artifact_worker_spec.rb index 95962d4810e..daecda8c92e 100644 --- a/spec/workers/concerns/packages/cleanup_artifact_worker_spec.rb +++ b/spec/workers/concerns/packages/cleanup_artifact_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Packages::CleanupArtifactWorker do +RSpec.describe ::Packages::CleanupArtifactWorker, feature_category: :build_artifacts do let_it_be(:worker_class) do Class.new do def self.name 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/project_import_options_spec.rb b/spec/workers/concerns/project_import_options_spec.rb index 85a26ddb0cb..51d7f9fdea4 100644 --- a/spec/workers/concerns/project_import_options_spec.rb +++ b/spec/workers/concerns/project_import_options_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ProjectImportOptions do +RSpec.describe ProjectImportOptions, feature_category: :importers do let(:project) { create(:project, :import_started) } let(:job) { { 'args' => [project.id, nil, nil], 'jid' => '123' } } let(:worker_class) do diff --git a/spec/workers/concerns/reenqueuer_spec.rb b/spec/workers/concerns/reenqueuer_spec.rb index e7287b55af2..42873578014 100644 --- a/spec/workers/concerns/reenqueuer_spec.rb +++ b/spec/workers/concerns/reenqueuer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Reenqueuer do +RSpec.describe Reenqueuer, feature_category: :shared do include ExclusiveLeaseHelpers let_it_be(:worker_class) do diff --git a/spec/workers/concerns/repository_check_queue_spec.rb b/spec/workers/concerns/repository_check_queue_spec.rb index ae377c09b37..12082e2dff5 100644 --- a/spec/workers/concerns/repository_check_queue_spec.rb +++ b/spec/workers/concerns/repository_check_queue_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RepositoryCheckQueue do +RSpec.describe RepositoryCheckQueue, feature_category: :source_code_management do let(:worker) do Class.new do def self.name @@ -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 deleted file mode 100644 index 737424ffd8c..00000000000 --- a/spec/workers/concerns/waitable_worker_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe WaitableWorker do - let(:worker) do - Class.new do - def self.name - 'Gitlab::Foo::Bar::DummyWorker' - end - - cattr_accessor(:counter) { 0 } - - include ApplicationWorker - prepend WaitableWorker - - def perform(count = 0) - self.class.counter += count - end - end - end - - subject(:job) { worker.new } - - describe '#perform' do - shared_examples 'perform' do - it 'notifies the JobWaiter when done if the key is provided' do - key = Gitlab::JobWaiter.new.key - expect(Gitlab::JobWaiter).to receive(:notify).with(key, job.jid) - - job.perform(*args, key) - end - - it 'does not notify the JobWaiter when done if no key is provided' do - expect(Gitlab::JobWaiter).not_to receive(:notify) - - job.perform(*args) - end - end - - context 'when the worker takes arguments' do - let(:args) { [1] } - - it_behaves_like 'perform' - end - - context 'when the worker takes no arguments' do - let(:args) { [] } - - it_behaves_like 'perform' - end - end -end diff --git a/spec/workers/concerns/worker_attributes_spec.rb b/spec/workers/concerns/worker_attributes_spec.rb index 5e8f68923fd..ac9d3fa824e 100644 --- a/spec/workers/concerns/worker_attributes_spec.rb +++ b/spec/workers/concerns/worker_attributes_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe WorkerAttributes do +RSpec.describe WorkerAttributes, feature_category: :shared do using RSpec::Parameterized::TableSyntax let(:worker) do diff --git a/spec/workers/concerns/worker_context_spec.rb b/spec/workers/concerns/worker_context_spec.rb index 80b427b2b42..700d9e37a55 100644 --- a/spec/workers/concerns/worker_context_spec.rb +++ b/spec/workers/concerns/worker_context_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe WorkerContext do +RSpec.describe WorkerContext, feature_category: :shared do let(:worker) do Class.new do def self.name @@ -73,9 +73,11 @@ RSpec.describe WorkerContext do describe '.bulk_perform_async_with_contexts' do subject do - worker.bulk_perform_async_with_contexts(%w(hello world), - context_proc: -> (_) { { user: build_stubbed(:user) } }, - arguments_proc: -> (word) { word }) + worker.bulk_perform_async_with_contexts( + %w(hello world), + context_proc: -> (_) { { user: build_stubbed(:user) } }, + arguments_proc: -> (word) { word } + ) end it 'calls bulk_perform_async with the arguments' do @@ -89,10 +91,12 @@ RSpec.describe WorkerContext do describe '.bulk_perform_in_with_contexts' do subject do - worker.bulk_perform_in_with_contexts(10.minutes, - %w(hello world), - context_proc: -> (_) { { user: build_stubbed(:user) } }, - arguments_proc: -> (word) { word }) + worker.bulk_perform_in_with_contexts( + 10.minutes, + %w(hello world), + context_proc: -> (_) { { user: build_stubbed(:user) } }, + arguments_proc: -> (word) { word } + ) end it 'calls bulk_perform_in with the arguments and delay' do diff --git a/spec/workers/container_expiration_policies/cleanup_container_repository_worker_spec.rb b/spec/workers/container_expiration_policies/cleanup_container_repository_worker_spec.rb index 8eda943f36e..8dae859b168 100644 --- a/spec/workers/container_expiration_policies/cleanup_container_repository_worker_spec.rb +++ b/spec/workers/container_expiration_policies/cleanup_container_repository_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do +RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker, feature_category: :container_registry do using RSpec::Parameterized::TableSyntax let_it_be(:repository, refind: true) { create(:container_repository, :cleanup_scheduled, expiration_policy_started_at: 1.month.ago) } @@ -348,16 +348,18 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do subject { worker.send(:container_repository) } - if params[:expected_selected_repository] == :none - it 'does not select any repository' do + it 'selects the correct repository', :freeze_time do + case expected_selected_repository + when :none expect(subject).to eq(nil) + next + when :repository + expect(subject).to eq(repository) + when :other_repository + expect(subject).to eq(other_repository) end - else - it 'does select a repository' do - selected_repository = expected_selected_repository == :repository ? repository : other_repository - - expect(subject).to eq(selected_repository) - end + expect(subject).to be_cleanup_ongoing + expect(subject.expiration_policy_started_at).to eq(Time.zone.now) end def update_container_repository(container_repository, cleanup_status, policy_status) @@ -511,6 +513,16 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do subject end end + + context 'with a stuck container repository' do + before do + repository.cleanup_ongoing! + repository.update_column(:expiration_policy_started_at, nil) + policy.update_column(:next_run_at, 5.minutes.ago) + end + + it { is_expected.to eq(0) } + end end describe '#max_running_jobs' do diff --git a/spec/workers/container_expiration_policy_worker_spec.rb b/spec/workers/container_expiration_policy_worker_spec.rb index ef6266aeba3..fcb43b86084 100644 --- a/spec/workers/container_expiration_policy_worker_spec.rb +++ b/spec/workers/container_expiration_policy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ContainerExpirationPolicyWorker do +RSpec.describe ContainerExpirationPolicyWorker, feature_category: :container_registry do include ExclusiveLeaseHelpers let(:worker) { described_class.new } @@ -33,15 +33,17 @@ RSpec.describe ContainerExpirationPolicyWorker do end context 'process stale ongoing cleanups' do - let_it_be(:stuck_cleanup) { create(:container_repository, :cleanup_ongoing, expiration_policy_started_at: 1.day.ago) } + let_it_be(:stuck_cleanup1) { create(:container_repository, :cleanup_ongoing, expiration_policy_started_at: 1.day.ago) } + let_it_be(:stuck_cleanup2) { create(:container_repository, :cleanup_ongoing, expiration_policy_started_at: nil) } let_it_be(:container_repository1) { create(:container_repository, :cleanup_scheduled) } let_it_be(:container_repository2) { create(:container_repository, :cleanup_unfinished) } it 'set them as unfinished' do expect { subject } - .to change { ContainerRepository.cleanup_ongoing.count }.from(1).to(0) - .and change { ContainerRepository.cleanup_unfinished.count }.from(1).to(2) - expect(stuck_cleanup.reload).to be_cleanup_unfinished + .to change { ContainerRepository.cleanup_ongoing.count }.from(2).to(0) + .and change { ContainerRepository.cleanup_unfinished.count }.from(1).to(3) + expect(stuck_cleanup1.reload).to be_cleanup_unfinished + expect(stuck_cleanup2.reload).to be_cleanup_unfinished end end diff --git a/spec/workers/container_registry/cleanup_worker_spec.rb b/spec/workers/container_registry/cleanup_worker_spec.rb index a510b660412..955d2175085 100644 --- a/spec/workers/container_registry/cleanup_worker_spec.rb +++ b/spec/workers/container_registry/cleanup_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ContainerRegistry::CleanupWorker, :aggregate_failures do +RSpec.describe ContainerRegistry::CleanupWorker, :aggregate_failures, feature_category: :container_registry do let(:worker) { described_class.new } describe '#perform' do @@ -46,6 +46,77 @@ RSpec.describe ContainerRegistry::CleanupWorker, :aggregate_failures do end end + context 'with stale ongoing repair details' do + let_it_be(:stale_updated_at) { (described_class::STALE_REPAIR_DETAIL_THRESHOLD + 5.minutes).ago } + let_it_be(:recent_updated_at) { (described_class::STALE_REPAIR_DETAIL_THRESHOLD - 5.minutes).ago } + let_it_be(:old_repair_detail) { create(:container_registry_data_repair_detail, updated_at: stale_updated_at) } + let_it_be(:new_repair_detail) { create(:container_registry_data_repair_detail, updated_at: recent_updated_at) } + + it 'deletes them' do + expect { perform }.to change { ContainerRegistry::DataRepairDetail.count }.from(2).to(1) + expect(ContainerRegistry::DataRepairDetail.all).to contain_exactly(new_repair_detail) + end + end + + shared_examples 'does not enqueue record repair detail jobs' do + it 'does not enqueue record repair detail jobs' do + expect(ContainerRegistry::RecordDataRepairDetailWorker).not_to receive(:perform_with_capacity) + + perform + end + end + + context 'when on gitlab.com', :saas do + context 'when the gitlab api is supported' do + let(:relation) { instance_double(ActiveRecord::Relation) } + + before do + allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(true) + allow(Project).to receive(:pending_data_repair_analysis).and_return(relation) + end + + context 'when there are pending projects to analyze' do + before do + allow(relation).to receive(:exists?).and_return(true) + end + + it "enqueues record repair detail jobs" do + expect(ContainerRegistry::RecordDataRepairDetailWorker).to receive(:perform_with_capacity) + + perform + end + end + + context 'when there are no pending projects to analyze' do + before do + allow(relation).to receive(:exists?).and_return(false) + end + + it_behaves_like 'does not enqueue record repair detail jobs' + end + end + + context 'when the Gitlab API is not supported' do + before do + allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(false) + end + + it_behaves_like 'does not enqueue record repair detail jobs' + end + end + + context 'when not on Gitlab.com' do + it_behaves_like 'does not enqueue record repair detail jobs' + end + + context 'when registry_data_repair_worker feature is disabled' do + before do + stub_feature_flags(registry_data_repair_worker: false) + end + + it_behaves_like 'does not enqueue record repair detail jobs' + end + context 'for counts logging' do let_it_be(:delete_started_at) { (described_class::STALE_DELETE_THRESHOLD + 5.minutes).ago } let_it_be(:stale_delete_container_repository) do diff --git a/spec/workers/container_registry/delete_container_repository_worker_spec.rb b/spec/workers/container_registry/delete_container_repository_worker_spec.rb index 381e0cc164c..8bab0133d55 100644 --- a/spec/workers/container_registry/delete_container_repository_worker_spec.rb +++ b/spec/workers/container_registry/delete_container_repository_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ContainerRegistry::DeleteContainerRepositoryWorker, :aggregate_failures do +RSpec.describe ContainerRegistry::DeleteContainerRepositoryWorker, :aggregate_failures, feature_category: :container_registry do let_it_be_with_reload(:container_repository) { create(:container_repository) } let_it_be(:second_container_repository) { create(:container_repository) } diff --git a/spec/workers/container_registry/migration/enqueuer_worker_spec.rb b/spec/workers/container_registry/migration/enqueuer_worker_spec.rb index c2381c0ced7..4a603e538ef 100644 --- a/spec/workers/container_registry/migration/enqueuer_worker_spec.rb +++ b/spec/workers/container_registry/migration/enqueuer_worker_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' -RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures, :clean_gitlab_redis_shared_state do +RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures, :clean_gitlab_redis_shared_state, + feature_category: :container_registry do using RSpec::Parameterized::TableSyntax include ExclusiveLeaseHelpers diff --git a/spec/workers/container_registry/migration/guard_worker_spec.rb b/spec/workers/container_registry/migration/guard_worker_spec.rb index 4ad2d5c300c..40ade93ab0d 100644 --- a/spec/workers/container_registry/migration/guard_worker_spec.rb +++ b/spec/workers/container_registry/migration/guard_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ContainerRegistry::Migration::GuardWorker, :aggregate_failures do +RSpec.describe ContainerRegistry::Migration::GuardWorker, :aggregate_failures, feature_category: :container_registry do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/container_registry/migration/observer_worker_spec.rb b/spec/workers/container_registry/migration/observer_worker_spec.rb index fec6640d7ec..7bf3d90d9d3 100644 --- a/spec/workers/container_registry/migration/observer_worker_spec.rb +++ b/spec/workers/container_registry/migration/observer_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ContainerRegistry::Migration::ObserverWorker, :aggregate_failures do +RSpec.describe ContainerRegistry::Migration::ObserverWorker, :aggregate_failures, feature_category: :container_registry do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/container_registry/record_data_repair_detail_worker_spec.rb b/spec/workers/container_registry/record_data_repair_detail_worker_spec.rb new file mode 100644 index 00000000000..f107144d397 --- /dev/null +++ b/spec/workers/container_registry/record_data_repair_detail_worker_spec.rb @@ -0,0 +1,191 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ContainerRegistry::RecordDataRepairDetailWorker, :aggregate_failures, :clean_gitlab_redis_shared_state, + feature_category: :container_registry do + include ExclusiveLeaseHelpers + + let(:worker) { described_class.new } + + describe '#perform_work' do + subject(:perform_work) { worker.perform_work } + + context 'with no work to do - no projects pending analysis' do + it 'will not try to get an exclusive lease and connect to the endpoint' do + allow(Project).to receive(:pending_data_repair_analysis).and_return([]) + expect(::Gitlab::ExclusiveLease).not_to receive(:new) + + expect(::ContainerRegistry::GitlabApiClient).not_to receive(:each_sub_repositories_with_tag_page) + + perform_work + end + end + + context 'with work to do' do + let_it_be(:path) { 'build/cng/docker-alpine' } + let_it_be(:group) { create(:group, path: 'build') } + let_it_be(:project) { create(:project, name: 'cng', namespace: group) } + + let_it_be(:container_repository) { create(:container_repository, project: project, name: "docker-alpine") } + let_it_be(:lease_key) { "container_registry_data_repair_detail_worker:#{project.id}" } + + before do + allow(ContainerRegistry::GitlabApiClient).to receive(:each_sub_repositories_with_tag_page) + allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(true) + end + + context 'when on Gitlab.com', :saas do + it 'obtains exclusive lease on the project' do + expect(Project).to receive(:pending_data_repair_analysis).and_call_original + expect_to_obtain_exclusive_lease("container_registry_data_repair_detail_worker:#{project.id}", + timeout: described_class::LEASE_TIMEOUT) + expect_to_cancel_exclusive_lease("container_registry_data_repair_detail_worker:#{project.id}", 'uuid') + + perform_work + end + + it 'queries how many are existing repositories and counts the missing ones' do + stub_exclusive_lease("container_registry_data_repair_detail_worker:#{project.id}", + timeout: described_class::LEASE_TIMEOUT) + allow(ContainerRegistry::GitlabApiClient).to receive(:each_sub_repositories_with_tag_page) + .with(path: project.full_path, page_size: 50).and_yield( + [ + { "path" => container_repository.path }, + { "path" => 'missing1/repository' }, + { "path" => 'missing2/repository' } + ] + ) + + expect(worker).not_to receive(:log_extra_metadata_on_done) + expect { perform_work }.to change { ContainerRegistry::DataRepairDetail.count }.from(0).to(1) + expect(ContainerRegistry::DataRepairDetail.first).to have_attributes(project: project, missing_count: 2) + end + + it 'logs invalid paths' do + stub_exclusive_lease("container_registry_data_repair_detail_worker:#{project.id}", + timeout: described_class::LEASE_TIMEOUT) + valid_path = ContainerRegistry::Path.new('valid/path') + invalid_path = ContainerRegistry::Path.new('invalid/path') + allow(valid_path).to receive(:valid?).and_return(true) + allow(invalid_path).to receive(:valid?).and_return(false) + + allow(ContainerRegistry::GitlabApiClient).to receive(:each_sub_repositories_with_tag_page) + .with(path: project.full_path, page_size: 50).and_yield( + [ + { "path" => valid_path.to_s }, + { "path" => invalid_path.to_s } + ] + ) + + allow(ContainerRegistry::Path).to receive(:new).with(valid_path.to_s).and_return(valid_path) + allow(ContainerRegistry::Path).to receive(:new).with(invalid_path.to_s).and_return(invalid_path) + + expect(worker).to receive(:log_extra_metadata_on_done).with( + :invalid_paths_parsed_in_container_repository_repair, + "invalid/path" + ) + perform_work + end + + it_behaves_like 'an idempotent worker' do + it 'creates a data repair detail' do + expect { perform_work }.to change { ContainerRegistry::DataRepairDetail.count }.from(0).to(1) + expect(project.container_registry_data_repair_detail).to be_present + end + end + + context 'when the lease cannot be obtained' do + before do + stub_exclusive_lease_taken(lease_key, timeout: described_class::LEASE_TIMEOUT) + end + + it 'logs an error and does not proceed' do + expect(worker).to receive(:log_lease_taken) + expect(ContainerRegistry::GitlabApiClient).not_to receive(:each_sub_repositories_with_tag_page) + + perform_work + end + + it 'does not create the data repair detail' do + perform_work + + expect(project.reload.container_registry_data_repair_detail).to be_nil + end + end + + context 'when an error occurs' do + before do + stub_exclusive_lease("container_registry_data_repair_detail_worker:#{project.id}", + timeout: described_class::LEASE_TIMEOUT) + allow(ContainerRegistry::GitlabApiClient).to receive(:each_sub_repositories_with_tag_page) + .with(path: project.full_path, page_size: 50).and_raise(RuntimeError) + end + + it 'logs the error' do + expect(::Gitlab::ErrorTracking).to receive(:log_exception) + .with(instance_of(RuntimeError), class: described_class.name) + + perform_work + end + + it 'sets the status of the repair detail to failed' do + expect { perform_work }.to change { ContainerRegistry::DataRepairDetail.failed.count }.from(0).to(1) + expect(project.reload.container_registry_data_repair_detail.failed?).to eq(true) + end + end + end + + context 'when not on Gitlab.com' do + it 'will not do anything' do + expect(::Gitlab::ExclusiveLease).not_to receive(:new) + expect(::ContainerRegistry::GitlabApiClient).not_to receive(:each_sub_repositories_with_tag_page) + + perform_work + end + end + end + end + + describe '#max_running_jobs' do + subject { worker.max_running_jobs } + + it { is_expected.to eq(described_class::MAX_CAPACITY) } + end + + describe '#remaining_work_count' do + let_it_be(:pending_projects) do + create_list(:project, described_class::MAX_CAPACITY + 2) + end + + subject { worker.remaining_work_count } + + context 'when on Gitlab.com', :saas do + before do + allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(true) + end + + it { is_expected.to eq(described_class::MAX_CAPACITY + 1) } + + context 'when the Gitlab API is not supported' do + before do + allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(false) + end + + it { is_expected.to eq(0) } + end + end + + context 'when not on Gitlab.com' do + it { is_expected.to eq(0) } + end + + context 'when registry_data_repair_worker feature is disabled' do + before do + stub_feature_flags(registry_data_repair_worker: false) + end + + it { is_expected.to eq(0) } + end + end +end diff --git a/spec/workers/counters/cleanup_refresh_worker_spec.rb b/spec/workers/counters/cleanup_refresh_worker_spec.rb index a56c98f72a0..a18f78f1706 100644 --- a/spec/workers/counters/cleanup_refresh_worker_spec.rb +++ b/spec/workers/counters/cleanup_refresh_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Counters::CleanupRefreshWorker do +RSpec.describe Counters::CleanupRefreshWorker, feature_category: :shared do let(:model) { create(:project_statistics) } describe '#perform', :redis do diff --git a/spec/workers/create_commit_signature_worker_spec.rb b/spec/workers/create_commit_signature_worker_spec.rb index 9d3c63efc8a..722632b6796 100644 --- a/spec/workers/create_commit_signature_worker_spec.rb +++ b/spec/workers/create_commit_signature_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe CreateCommitSignatureWorker do +RSpec.describe CreateCommitSignatureWorker, feature_category: :source_code_management do let(:project) { create(:project, :repository) } let(:commits) { project.repository.commits('HEAD', limit: 3).commits } let(:commit_shas) { commits.map(&:id) } diff --git a/spec/workers/create_note_diff_file_worker_spec.rb b/spec/workers/create_note_diff_file_worker_spec.rb index 6d1d6d93e44..6e4a5e3ab6a 100644 --- a/spec/workers/create_note_diff_file_worker_spec.rb +++ b/spec/workers/create_note_diff_file_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe CreateNoteDiffFileWorker do +RSpec.describe CreateNoteDiffFileWorker, feature_category: :code_review_workflow do describe '#perform' do let(:diff_note) { create(:diff_note_on_merge_request) } diff --git a/spec/workers/create_pipeline_worker_spec.rb b/spec/workers/create_pipeline_worker_spec.rb index da85d700429..23a2dc075a7 100644 --- a/spec/workers/create_pipeline_worker_spec.rb +++ b/spec/workers/create_pipeline_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe CreatePipelineWorker do +RSpec.describe CreatePipelineWorker, feature_category: :continuous_integration do describe '#perform' do let(:worker) { described_class.new } diff --git a/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb b/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb index dfe7a266be2..782f949eacf 100644 --- a/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb +++ b/spec/workers/database/batched_background_migration/ci_database_worker_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' -RSpec.describe Database::BatchedBackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state do +RSpec.describe Database::BatchedBackgroundMigration::CiDatabaseWorker, :clean_gitlab_redis_shared_state, + feature_category: :database do it_behaves_like 'it runs batched background migration jobs', :ci, :ci_builds end diff --git a/spec/workers/database/batched_background_migration_worker_spec.rb b/spec/workers/database/batched_background_migration_worker_spec.rb index e57bd7581c2..a6825c5ca76 100644 --- a/spec/workers/database/batched_background_migration_worker_spec.rb +++ b/spec/workers/database/batched_background_migration_worker_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -RSpec.describe Database::BatchedBackgroundMigrationWorker do +RSpec.describe Database::BatchedBackgroundMigrationWorker, feature_category: :database do it_behaves_like 'it runs batched background migration jobs', :main, :events end diff --git a/spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb b/spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb index 1c083d1d8a3..84ea5db4bab 100644 --- a/spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb +++ b/spec/workers/database/ci_namespace_mirrors_consistency_check_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Database::CiNamespaceMirrorsConsistencyCheckWorker do +RSpec.describe Database::CiNamespaceMirrorsConsistencyCheckWorker, feature_category: :cell do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb b/spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb index 8c839410ccd..0895f3d0559 100644 --- a/spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb +++ b/spec/workers/database/ci_project_mirrors_consistency_check_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Database::CiProjectMirrorsConsistencyCheckWorker do +RSpec.describe Database::CiProjectMirrorsConsistencyCheckWorker, feature_category: :cell do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/database/drop_detached_partitions_worker_spec.rb b/spec/workers/database/drop_detached_partitions_worker_spec.rb index a10fcaaa5d9..2ab77e71070 100644 --- a/spec/workers/database/drop_detached_partitions_worker_spec.rb +++ b/spec/workers/database/drop_detached_partitions_worker_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Database::DropDetachedPartitionsWorker do +RSpec.describe Database::DropDetachedPartitionsWorker, feature_category: :database do describe '#perform' do subject { described_class.new.perform } diff --git a/spec/workers/database/partition_management_worker_spec.rb b/spec/workers/database/partition_management_worker_spec.rb index e5362e95f48..203181ef28d 100644 --- a/spec/workers/database/partition_management_worker_spec.rb +++ b/spec/workers/database/partition_management_worker_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Database::PartitionManagementWorker do +RSpec.describe Database::PartitionManagementWorker, feature_category: :database do describe '#perform' do subject { described_class.new.perform } diff --git a/spec/workers/delete_container_repository_worker_spec.rb b/spec/workers/delete_container_repository_worker_spec.rb index 6ad131b4c14..6260bea6949 100644 --- a/spec/workers/delete_container_repository_worker_spec.rb +++ b/spec/workers/delete_container_repository_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DeleteContainerRepositoryWorker do +RSpec.describe DeleteContainerRepositoryWorker, feature_category: :container_registry do let_it_be(:repository) { create(:container_repository) } let(:project) { repository.project } diff --git a/spec/workers/delete_diff_files_worker_spec.rb b/spec/workers/delete_diff_files_worker_spec.rb index c124847ca45..1f1b00e324e 100644 --- a/spec/workers/delete_diff_files_worker_spec.rb +++ b/spec/workers/delete_diff_files_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DeleteDiffFilesWorker do +RSpec.describe DeleteDiffFilesWorker, feature_category: :code_review_workflow do describe '#perform' do let(:merge_request) { create(:merge_request) } let(:merge_request_diff) { merge_request.merge_request_diff } diff --git a/spec/workers/delete_merged_branches_worker_spec.rb b/spec/workers/delete_merged_branches_worker_spec.rb index 056fcb1200d..f3b6dccad2e 100644 --- a/spec/workers/delete_merged_branches_worker_spec.rb +++ b/spec/workers/delete_merged_branches_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DeleteMergedBranchesWorker do +RSpec.describe DeleteMergedBranchesWorker, feature_category: :source_code_management do subject(:worker) { described_class.new } let(:project) { create(:project, :repository) } diff --git a/spec/workers/delete_user_worker_spec.rb b/spec/workers/delete_user_worker_spec.rb index 4046b670640..8a99f69c079 100644 --- a/spec/workers/delete_user_worker_spec.rb +++ b/spec/workers/delete_user_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DeleteUserWorker do +RSpec.describe DeleteUserWorker, feature_category: :user_management do let!(:user) { create(:user) } let!(:current_user) { create(:user) } @@ -21,4 +21,54 @@ RSpec.describe DeleteUserWorker do described_class.new.perform(current_user.id, user.id, { "test" => "test" }) end + + shared_examples 'does nothing' do + it "does not instantiate a DeleteUserWorker" do + expect(Users::DestroyService).not_to receive(:new) + + perform + end + end + + context 'when user is banned' do + subject(:perform) { described_class.new.perform(current_user.id, user.id) } + + before do + user.ban + end + + it_behaves_like 'does nothing' + + context 'when delay_delete_own_user feature flag is disabled' do + before do + stub_feature_flags(delay_delete_own_user: false) + end + + it "proceeds with deletion" do + expect_next_instance_of(Users::DestroyService) do |service| + expect(service).to receive(:execute).with(user, {}) + end + + perform + end + end + end + + context 'when user to delete does not exist' do + subject(:perform) { described_class.new.perform(current_user.id, non_existing_record_id) } + + it_behaves_like 'does nothing' + end + + context 'when current user does not exist' do + subject(:perform) { described_class.new.perform(non_existing_record_id, user.id) } + + it_behaves_like 'does nothing' + end + + context 'when user to delete and current user do not exist' do + subject(:perform) { described_class.new.perform(non_existing_record_id, non_existing_record_id) } + + it_behaves_like 'does nothing' + end end diff --git a/spec/workers/dependency_proxy/cleanup_blob_worker_spec.rb b/spec/workers/dependency_proxy/cleanup_blob_worker_spec.rb index b67a56cca7b..9ef5fd9ec93 100644 --- a/spec/workers/dependency_proxy/cleanup_blob_worker_spec.rb +++ b/spec/workers/dependency_proxy/cleanup_blob_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DependencyProxy::CleanupBlobWorker do +RSpec.describe DependencyProxy::CleanupBlobWorker, feature_category: :dependency_proxy do let_it_be(:factory_type) { :dependency_proxy_blob } it_behaves_like 'dependency_proxy_cleanup_worker' diff --git a/spec/workers/dependency_proxy/cleanup_dependency_proxy_worker_spec.rb b/spec/workers/dependency_proxy/cleanup_dependency_proxy_worker_spec.rb index 1100f9a7fae..3040189d1c8 100644 --- a/spec/workers/dependency_proxy/cleanup_dependency_proxy_worker_spec.rb +++ b/spec/workers/dependency_proxy/cleanup_dependency_proxy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DependencyProxy::CleanupDependencyProxyWorker do +RSpec.describe DependencyProxy::CleanupDependencyProxyWorker, feature_category: :dependency_proxy do describe '#perform' do subject { described_class.new.perform } diff --git a/spec/workers/dependency_proxy/cleanup_manifest_worker_spec.rb b/spec/workers/dependency_proxy/cleanup_manifest_worker_spec.rb index d53b3e6a1fd..730acc49110 100644 --- a/spec/workers/dependency_proxy/cleanup_manifest_worker_spec.rb +++ b/spec/workers/dependency_proxy/cleanup_manifest_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DependencyProxy::CleanupManifestWorker do +RSpec.describe DependencyProxy::CleanupManifestWorker, feature_category: :dependency_proxy do let_it_be(:factory_type) { :dependency_proxy_manifest } it_behaves_like 'dependency_proxy_cleanup_worker' diff --git a/spec/workers/dependency_proxy/image_ttl_group_policy_worker_spec.rb b/spec/workers/dependency_proxy/image_ttl_group_policy_worker_spec.rb index 6a2fdfbe8f5..44a21439ff8 100644 --- a/spec/workers/dependency_proxy/image_ttl_group_policy_worker_spec.rb +++ b/spec/workers/dependency_proxy/image_ttl_group_policy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DependencyProxy::ImageTtlGroupPolicyWorker do +RSpec.describe DependencyProxy::ImageTtlGroupPolicyWorker, feature_category: :dependency_proxy do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/deployments/archive_in_project_worker_spec.rb b/spec/workers/deployments/archive_in_project_worker_spec.rb index 6435fe8bea1..2d244344913 100644 --- a/spec/workers/deployments/archive_in_project_worker_spec.rb +++ b/spec/workers/deployments/archive_in_project_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Deployments::ArchiveInProjectWorker do +RSpec.describe Deployments::ArchiveInProjectWorker, feature_category: :continuous_delivery do subject { described_class.new.perform(deployment&.project_id) } describe '#perform' do diff --git a/spec/workers/deployments/drop_older_deployments_worker_spec.rb b/spec/workers/deployments/drop_older_deployments_worker_spec.rb deleted file mode 100644 index 0cf524ca16f..00000000000 --- a/spec/workers/deployments/drop_older_deployments_worker_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Deployments::DropOlderDeploymentsWorker do - subject { described_class.new.perform(deployment&.id) } - - describe '#perform' do - let(:deployment) { create(:deployment, :success) } - - it 'executes Deployments::OlderDeploymentsDropService' do - expect(Deployments::OlderDeploymentsDropService) - .to receive(:new).with(deployment.id).and_call_original - - subject - end - end -end diff --git a/spec/workers/deployments/hooks_worker_spec.rb b/spec/workers/deployments/hooks_worker_spec.rb index 7c5f288fa57..e620ed6e05c 100644 --- a/spec/workers/deployments/hooks_worker_spec.rb +++ b/spec/workers/deployments/hooks_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Deployments::HooksWorker do +RSpec.describe Deployments::HooksWorker, feature_category: :continuous_delivery do let(:worker) { described_class.new } describe '#perform' do @@ -60,8 +60,6 @@ RSpec.describe Deployments::HooksWorker do worker.perform(deployment_id: deployment.id, status_changed_at: status_changed_at) end - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed end end diff --git a/spec/workers/deployments/link_merge_request_worker_spec.rb b/spec/workers/deployments/link_merge_request_worker_spec.rb index a55dd897bc7..0e484c50f21 100644 --- a/spec/workers/deployments/link_merge_request_worker_spec.rb +++ b/spec/workers/deployments/link_merge_request_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Deployments::LinkMergeRequestWorker do +RSpec.describe Deployments::LinkMergeRequestWorker, feature_category: :continuous_delivery do subject(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/deployments/update_environment_worker_spec.rb b/spec/workers/deployments/update_environment_worker_spec.rb index d67cbd62616..befe8576e88 100644 --- a/spec/workers/deployments/update_environment_worker_spec.rb +++ b/spec/workers/deployments/update_environment_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Deployments::UpdateEnvironmentWorker do +RSpec.describe Deployments::UpdateEnvironmentWorker, feature_category: :continuous_delivery do subject(:worker) { described_class.new } context 'when successful deployment' do diff --git a/spec/workers/design_management/copy_design_collection_worker_spec.rb b/spec/workers/design_management/copy_design_collection_worker_spec.rb index 45bfc47ca7e..daa69a8bd6d 100644 --- a/spec/workers/design_management/copy_design_collection_worker_spec.rb +++ b/spec/workers/design_management/copy_design_collection_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DesignManagement::CopyDesignCollectionWorker, :clean_gitlab_redis_shared_state do +RSpec.describe DesignManagement::CopyDesignCollectionWorker, :clean_gitlab_redis_shared_state, feature_category: :design_management do describe '#perform' do let_it_be(:user) { create(:user) } let_it_be(:issue) { create(:issue) } diff --git a/spec/workers/design_management/new_version_worker_spec.rb b/spec/workers/design_management/new_version_worker_spec.rb index 3320d7a062d..baf6409a64f 100644 --- a/spec/workers/design_management/new_version_worker_spec.rb +++ b/spec/workers/design_management/new_version_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DesignManagement::NewVersionWorker do +RSpec.describe DesignManagement::NewVersionWorker, feature_category: :design_management do describe '#perform' do let(:worker) { described_class.new } @@ -57,9 +57,11 @@ RSpec.describe DesignManagement::NewVersionWorker do context 'the version includes multiple types of action' do let_it_be(:version) do - create(:design_version, :with_lfs_file, - created_designs: create_list(:design, 1, :with_lfs_file), - modified_designs: create_list(:design, 1)) + create( + :design_version, :with_lfs_file, + created_designs: create_list(:design, 1, :with_lfs_file), + modified_designs: create_list(:design, 1) + ) end it 'creates two system notes' do diff --git a/spec/workers/destroy_pages_deployments_worker_spec.rb b/spec/workers/destroy_pages_deployments_worker_spec.rb index 2c20c9004ef..4bfde6d220a 100644 --- a/spec/workers/destroy_pages_deployments_worker_spec.rb +++ b/spec/workers/destroy_pages_deployments_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DestroyPagesDeploymentsWorker do +RSpec.describe DestroyPagesDeploymentsWorker, feature_category: :pages do subject(:worker) { described_class.new } let(:project) { create(:project) } diff --git a/spec/workers/detect_repository_languages_worker_spec.rb b/spec/workers/detect_repository_languages_worker_spec.rb index 217e16bd155..27d60720d24 100644 --- a/spec/workers/detect_repository_languages_worker_spec.rb +++ b/spec/workers/detect_repository_languages_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DetectRepositoryLanguagesWorker do +RSpec.describe DetectRepositoryLanguagesWorker, feature_category: :source_code_management do let_it_be(:project) { create(:project) } subject { described_class.new } 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 3a875727cce..c732f8a3d00 100644 --- a/spec/workers/disallow_two_factor_for_group_worker_spec.rb +++ b/spec/workers/disallow_two_factor_for_group_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DisallowTwoFactorForGroupWorker do +RSpec.describe DisallowTwoFactorForGroupWorker, feature_category: :subgroups do let_it_be(:group) { create(:group, require_two_factor_authentication: true) } let_it_be(:user) { create(:user, require_two_factor_authentication_from_group: true) } diff --git a/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb b/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb index c3be8263171..7584355deab 100644 --- a/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb +++ b/spec/workers/disallow_two_factor_for_subgroups_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe DisallowTwoFactorForSubgroupsWorker do +RSpec.describe DisallowTwoFactorForSubgroupsWorker, feature_category: :subgroups do let_it_be(:group) { create(:group) } let_it_be(:subgroup_with_2fa) { create(:group, parent: group, require_two_factor_authentication: true) } let_it_be(:subgroup_without_2fa) { create(:group, parent: group, require_two_factor_authentication: false) } diff --git a/spec/workers/email_receiver_worker_spec.rb b/spec/workers/email_receiver_worker_spec.rb index dba535654a1..51a77a09e16 100644 --- a/spec/workers/email_receiver_worker_spec.rb +++ b/spec/workers/email_receiver_worker_spec.rb @@ -2,12 +2,12 @@ require "spec_helper" -RSpec.describe EmailReceiverWorker, :mailer do +RSpec.describe EmailReceiverWorker, :mailer, feature_category: :team_planning do let(:raw_message) { fixture_file('emails/valid_reply.eml') } context "when reply by email is enabled" do before do - allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(true) + allow(Gitlab::Email::IncomingEmail).to receive(:enabled?).and_return(true) end it "calls the email receiver" do @@ -67,7 +67,7 @@ RSpec.describe EmailReceiverWorker, :mailer do context "when reply by email is disabled" do before do - allow(Gitlab::IncomingEmail).to receive(:enabled?).and_return(false) + allow(Gitlab::Email::IncomingEmail).to receive(:enabled?).and_return(false) end it "doesn't call the email receiver" do diff --git a/spec/workers/emails_on_push_worker_spec.rb b/spec/workers/emails_on_push_worker_spec.rb index 7d11957e2df..9e8fad19c20 100644 --- a/spec/workers/emails_on_push_worker_spec.rb +++ b/spec/workers/emails_on_push_worker_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' -RSpec.describe EmailsOnPushWorker, :mailer do - include RepoHelpers +RSpec.describe EmailsOnPushWorker, :mailer, feature_category: :source_code_management do include EmailSpec::Matchers - let(:project) { create(:project, :repository) } - let(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let(:data) { Gitlab::DataBuilder::Push.build_sample(project, user) } let(:recipients) { user.email } let(:perform) { subject.perform(project.id, recipients, data.stringify_keys) } @@ -91,7 +91,7 @@ RSpec.describe EmailsOnPushWorker, :mailer do context "when there is an SMTP error" do before do - allow(Notify).to receive(:repository_push_email).and_raise(Net::SMTPFatalError) + allow(Notify).to receive(:repository_push_email).and_raise(Net::SMTPFatalError.new(nil)) allow(subject).to receive_message_chain(:logger, :info) perform end diff --git a/spec/workers/environments/auto_delete_cron_worker_spec.rb b/spec/workers/environments/auto_delete_cron_worker_spec.rb index b18f3da5d10..d7e707b225e 100644 --- a/spec/workers/environments/auto_delete_cron_worker_spec.rb +++ b/spec/workers/environments/auto_delete_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Environments::AutoDeleteCronWorker do +RSpec.describe Environments::AutoDeleteCronWorker, feature_category: :continuous_delivery do include CreateEnvironmentsHelpers let(:worker) { described_class.new } diff --git a/spec/workers/environments/auto_stop_cron_worker_spec.rb b/spec/workers/environments/auto_stop_cron_worker_spec.rb index 1e86597d288..ad44cf97e07 100644 --- a/spec/workers/environments/auto_stop_cron_worker_spec.rb +++ b/spec/workers/environments/auto_stop_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Environments::AutoStopCronWorker do +RSpec.describe Environments::AutoStopCronWorker, feature_category: :continuous_delivery do subject { worker.perform } let(:worker) { described_class.new } diff --git a/spec/workers/environments/auto_stop_worker_spec.rb b/spec/workers/environments/auto_stop_worker_spec.rb index cb162b5a01c..cfdca4a385c 100644 --- a/spec/workers/environments/auto_stop_worker_spec.rb +++ b/spec/workers/environments/auto_stop_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Environments::AutoStopWorker do +RSpec.describe Environments::AutoStopWorker, feature_category: :continuous_delivery do include CreateEnvironmentsHelpers subject { worker.perform(environment_id) } diff --git a/spec/workers/environments/canary_ingress/update_worker_spec.rb b/spec/workers/environments/canary_ingress/update_worker_spec.rb index e7782c2fba1..abfca54c850 100644 --- a/spec/workers/environments/canary_ingress/update_worker_spec.rb +++ b/spec/workers/environments/canary_ingress/update_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Environments::CanaryIngress::UpdateWorker do +RSpec.describe Environments::CanaryIngress::UpdateWorker, feature_category: :continuous_delivery do let_it_be(:environment) { create(:environment) } let(:worker) { described_class.new } diff --git a/spec/workers/error_tracking_issue_link_worker_spec.rb b/spec/workers/error_tracking_issue_link_worker_spec.rb index 90e747c8788..fcb39597f9e 100644 --- a/spec/workers/error_tracking_issue_link_worker_spec.rb +++ b/spec/workers/error_tracking_issue_link_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ErrorTrackingIssueLinkWorker do +RSpec.describe ErrorTrackingIssueLinkWorker, feature_category: :error_tracking do let_it_be(:error_tracking) { create(:project_error_tracking_setting) } let_it_be(:project) { error_tracking.project } let_it_be(:issue) { create(:issue, project: project) } diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb index c0d46a206ce..16173e322b6 100644 --- a/spec/workers/every_sidekiq_worker_spec.rb +++ b/spec/workers/every_sidekiq_worker_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe 'Every Sidekiq worker' do +RSpec.describe 'Every Sidekiq worker', feature_category: :shared do + include EverySidekiqWorkerTestHelper + let(:workers_without_defaults) do Gitlab::SidekiqConfig.workers - Gitlab::SidekiqConfig::DEFAULT_WORKERS.values end @@ -154,7 +156,6 @@ RSpec.describe 'Every Sidekiq worker' do 'Ci::BuildPrepareWorker' => 3, 'Ci::BuildScheduleWorker' => 3, 'Ci::BuildTraceChunkFlushWorker' => 3, - 'Ci::CreateCrossProjectPipelineWorker' => 3, 'Ci::CreateDownstreamPipelineWorker' => 3, 'Ci::DailyBuildGroupReportResultsWorker' => 3, 'Ci::DeleteObjectsWorker' => 0, @@ -162,6 +163,7 @@ RSpec.describe 'Every Sidekiq worker' do 'Ci::InitialPipelineProcessWorker' => 3, 'Ci::MergeRequests::AddTodoWhenBuildFailsWorker' => 3, 'Ci::Minutes::UpdateProjectAndNamespaceUsageWorker' => 3, + 'Ci::Llm::GenerateConfigWorker' => 3, 'Ci::PipelineArtifacts::CoverageReportWorker' => 3, 'Ci::PipelineArtifacts::CreateQualityReportWorker' => 3, 'Ci::PipelineBridgeStatusWorker' => 3, @@ -190,6 +192,7 @@ RSpec.describe 'Every Sidekiq worker' do 'Clusters::Cleanup::ServiceAccountWorker' => 3, 'ContainerExpirationPolicies::CleanupContainerRepositoryWorker' => 0, 'ContainerRegistry::DeleteContainerRepositoryWorker' => 0, + 'ContainerRegistry::RecordDataRepairDetailWorker' => 0, 'CreateCommitSignatureWorker' => 3, 'CreateGithubWebhookWorker' => 3, 'CreateNoteDiffFileWorker' => 3, @@ -204,7 +207,6 @@ RSpec.describe 'Every Sidekiq worker' do 'DependencyProxy::CleanupBlobWorker' => 3, 'DependencyProxy::CleanupManifestWorker' => 3, 'Deployments::AutoRollbackWorker' => 3, - 'Deployments::DropOlderDeploymentsWorker' => 3, 'Deployments::FinishedWorker' => 3, 'Deployments::ForwardDeploymentWorker' => 3, 'Deployments::LinkMergeRequestWorker' => 3, @@ -241,7 +243,6 @@ RSpec.describe 'Every Sidekiq worker' do 'Geo::DesignRepositorySyncWorker' => 1, 'Geo::DestroyWorker' => 3, 'Geo::EventWorker' => 3, - 'Geo::FileRegistryRemovalWorker' => 3, 'Geo::FileRemovalWorker' => 3, 'Geo::ProjectSyncWorker' => 1, 'Geo::RenameRepositoryWorker' => 3, @@ -272,9 +273,12 @@ RSpec.describe 'Every Sidekiq worker' do 'Gitlab::GithubImport::ImportLfsObjectWorker' => 5, 'Gitlab::GithubImport::ImportNoteWorker' => 5, 'Gitlab::GithubImport::ImportProtectedBranchWorker' => 5, + 'Gitlab::GithubImport::ImportCollaboratorWorker' => 5, 'Gitlab::GithubImport::ImportPullRequestMergedByWorker' => 5, 'Gitlab::GithubImport::ImportPullRequestReviewWorker' => 5, 'Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker' => 5, + 'Gitlab::GithubImport::PullRequests::ImportReviewWorker' => 5, + 'Gitlab::GithubImport::PullRequests::ImportMergedByWorker' => 5, 'Gitlab::GithubImport::ImportPullRequestWorker' => 5, 'Gitlab::GithubImport::RefreshImportJidWorker' => 5, 'Gitlab::GithubImport::Stage::FinishImportWorker' => 5, @@ -285,6 +289,7 @@ RSpec.describe 'Every Sidekiq worker' do 'Gitlab::GithubImport::Stage::ImportAttachmentsWorker' => 5, 'Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker' => 5, 'Gitlab::GithubImport::Stage::ImportNotesWorker' => 5, + 'Gitlab::GithubImport::Stage::ImportCollaboratorsWorker' => 5, 'Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker' => 5, 'Gitlab::GithubImport::Stage::ImportPullRequestsReviewRequestsWorker' => 5, 'Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker' => 5, @@ -301,7 +306,6 @@ RSpec.describe 'Every Sidekiq worker' do 'Gitlab::JiraImport::Stage::ImportLabelsWorker' => 5, 'Gitlab::JiraImport::Stage::ImportNotesWorker' => 5, 'Gitlab::JiraImport::Stage::StartImportWorker' => 5, - 'Gitlab::PhabricatorImport::ImportTasksWorker' => 5, 'GitlabPerformanceBarStatsWorker' => 3, 'GitlabSubscriptions::RefreshSeatsWorker' => 0, 'GitlabShellWorker' => 3, @@ -368,6 +372,7 @@ RSpec.describe 'Every Sidekiq worker' do 'Namespaces::RefreshRootStatisticsWorker' => 3, 'Namespaces::RootStatisticsWorker' => 3, 'Namespaces::ScheduleAggregationWorker' => 3, + 'Namespaces::FreeUserCap::NotificationClearingWorker' => false, 'NewEpicWorker' => 3, 'NewIssueWorker' => 3, 'NewMergeRequestWorker' => 3, @@ -405,6 +410,7 @@ RSpec.describe 'Every Sidekiq worker' do 'ProjectScheduleBulkRepositoryShardMovesWorker' => 3, 'ProjectTemplateExportWorker' => false, 'ProjectUpdateRepositoryStorageWorker' => 3, + 'Projects::DeregisterSuggestedReviewersProjectWorker' => 3, 'Projects::DisableLegacyOpenSourceLicenseForInactiveProjectsWorker' => 3, 'Projects::GitGarbageCollectWorker' => false, 'Projects::InactiveProjectsDeletionNotificationWorker' => 3, @@ -439,8 +445,6 @@ RSpec.describe 'Every Sidekiq worker' do 'Security::AutoFixWorker' => 3, 'Security::StoreScansWorker' => 3, 'Security::TrackSecureScansWorker' => 1, - 'SelfMonitoringProjectCreateWorker' => 3, - 'SelfMonitoringProjectDeleteWorker' => 3, 'ServiceDeskEmailReceiverWorker' => 3, 'SetUserStatusBasedOnUserCapSettingWorker' => 3, 'SnippetScheduleBulkRepositoryShardMovesWorker' => 3, @@ -475,9 +479,11 @@ RSpec.describe 'Every Sidekiq worker' do 'WebHooks::DestroyWorker' => 3, 'WebHooks::LogExecutionWorker' => 3, 'Wikis::GitGarbageCollectWorker' => false, + 'WorkItems::ImportWorkItemsCsvWorker' => 3, 'X509CertificateRevokeWorker' => 3, - 'ComplianceManagement::MergeRequests::ComplianceViolationsWorker' => 3 - } + 'ComplianceManagement::MergeRequests::ComplianceViolationsWorker' => 3, + 'Zoekt::IndexerWorker' => 2 + }.merge(extra_retry_exceptions) end it 'uses the default number of retries for new jobs' do @@ -491,7 +497,7 @@ RSpec.describe 'Every Sidekiq worker' do it 'uses specified numbers of retries for workers with exceptions encoded here', :aggregate_failures do retry_exception_workers.each do |worker| expect(worker.retries).to eq(retry_exceptions[worker.klass.to_s]), - "#{worker.klass} has #{worker.retries} retries, expected #{retry_exceptions[worker.klass]}" + "#{worker.klass} has #{worker.retries} retries, expected #{retry_exceptions[worker.klass]}" end end end diff --git a/spec/workers/expire_build_artifacts_worker_spec.rb b/spec/workers/expire_build_artifacts_worker_spec.rb index 3f8da3fb71c..2ef832eaaed 100644 --- a/spec/workers/expire_build_artifacts_worker_spec.rb +++ b/spec/workers/expire_build_artifacts_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ExpireBuildArtifactsWorker do +RSpec.describe ExpireBuildArtifactsWorker, feature_category: :build_artifacts do let(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/export_csv_worker_spec.rb b/spec/workers/export_csv_worker_spec.rb index 88ccfac0a02..2de6c58958f 100644 --- a/spec/workers/export_csv_worker_spec.rb +++ b/spec/workers/export_csv_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ExportCsvWorker do +RSpec.describe ExportCsvWorker, feature_category: :team_planning do let(:user) { create(:user) } let(:project) { create(:project, creator: user) } diff --git a/spec/workers/external_service_reactive_caching_worker_spec.rb b/spec/workers/external_service_reactive_caching_worker_spec.rb index 907894d9b9a..58d9bec343a 100644 --- a/spec/workers/external_service_reactive_caching_worker_spec.rb +++ b/spec/workers/external_service_reactive_caching_worker_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -RSpec.describe ExternalServiceReactiveCachingWorker do +RSpec.describe ExternalServiceReactiveCachingWorker, feature_category: :shared do it_behaves_like 'reactive cacheable worker' end diff --git a/spec/workers/file_hook_worker_spec.rb b/spec/workers/file_hook_worker_spec.rb index c171dc37e5f..00cd0e9c98e 100644 --- a/spec/workers/file_hook_worker_spec.rb +++ b/spec/workers/file_hook_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe FileHookWorker do +RSpec.describe FileHookWorker, feature_category: :integrations do include RepoHelpers let(:filename) { 'my_file_hook.rb' } diff --git a/spec/workers/flush_counter_increments_worker_spec.rb b/spec/workers/flush_counter_increments_worker_spec.rb index 83670acf4b6..1bdda3100c9 100644 --- a/spec/workers/flush_counter_increments_worker_spec.rb +++ b/spec/workers/flush_counter_increments_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe FlushCounterIncrementsWorker, :counter_attribute do +RSpec.describe FlushCounterIncrementsWorker, :counter_attribute, feature_category: :shared do let(:project_statistics) { create(:project_statistics) } let(:model) { CounterAttributeModel.find(project_statistics.id) } diff --git a/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb b/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb index 1c24cdcccae..fcbe1b2cf99 100644 --- a/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb +++ b/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb @@ -74,20 +74,68 @@ RSpec.describe Gitlab::GithubGistsImport::ImportGistWorker, feature_category: :i .with(log_attributes.merge('message' => 'importer finished')) subject.perform(user.id, gist_hash, 'some_key') + + expect_snowplow_event( + category: 'Gitlab::GithubGistsImport::ImportGistWorker', + label: 'github_gist_import', + action: 'create', + user: user, + status: 'success' + ) end end - context 'when importer raised an error' do - it 'raises an error' do - exception = StandardError.new('_some_error_') + context 'when failure' do + context 'when importer raised an error' do + it 'raises an error' do + exception = StandardError.new('_some_error_') - expect(importer).to receive(:execute).and_raise(exception) - expect(Gitlab::GithubImport::Logger) - .to receive(:error) - .with(log_attributes.merge('message' => 'importer failed', 'error.message' => '_some_error_')) - expect(Gitlab::ErrorTracking).to receive(:track_exception) + expect(importer).to receive(:execute).and_raise(exception) + expect(Gitlab::GithubImport::Logger) + .to receive(:error) + .with(log_attributes.merge('message' => 'importer failed', 'error.message' => '_some_error_')) + expect(Gitlab::ErrorTracking).to receive(:track_exception) + + expect { subject.perform(user.id, gist_hash, 'some_key') }.to raise_error(StandardError) + end + end + + context 'when importer returns error' do + let(:importer_result) { instance_double('ServiceResponse', errors: 'error_message', success?: false) } + + it 'tracks and logs error' do + expect(importer).to receive(:execute).and_return(importer_result) + expect(Gitlab::GithubImport::Logger) + .to receive(:error) + .with(log_attributes.merge('message' => 'importer failed', 'error.message' => 'error_message')) + expect(Gitlab::JobWaiter).to receive(:notify).with('some_key', subject.jid) + + subject.perform(user.id, gist_hash, 'some_key') + + expect_snowplow_event( + category: 'Gitlab::GithubGistsImport::ImportGistWorker', + label: 'github_gist_import', + action: 'create', + user: user, + status: 'failed' + ) + end + end + end + + describe '.sidekiq_retries_exhausted' do + it 'sends snowplow event' do + job = { 'args' => [user.id, 'some_key', '1'], 'jid' => '123' } + + described_class.sidekiq_retries_exhausted_block.call(job) - expect { subject.perform(user.id, gist_hash, 'some_key') }.to raise_error(StandardError) + expect_snowplow_event( + category: 'Gitlab::GithubGistsImport::ImportGistWorker', + label: 'github_gist_import', + action: 'create', + user: user, + status: 'failed' + ) end end end diff --git a/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb b/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb index 4e8261f61c4..121f30ea9d5 100644 --- a/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb +++ b/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::AdvanceStageWorker, :clean_gitlab_redis_shared_state do +RSpec.describe Gitlab::GithubImport::AdvanceStageWorker, :clean_gitlab_redis_shared_state, feature_category: :importers do let(:project) { create(:project) } let(:import_state) { create(:import_state, project: project, jid: '123') } let(:worker) { described_class.new } diff --git a/spec/workers/gitlab/github_import/attachments/import_issue_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_issue_worker_spec.rb index 6d617755861..e0db440232c 100644 --- a/spec/workers/gitlab/github_import/attachments/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/github_import/attachments/import_issue_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Attachments::ImportIssueWorker do +RSpec.describe Gitlab::GithubImport::Attachments::ImportIssueWorker, feature_category: :importers do subject(:worker) { described_class.new } describe '#import' do @@ -14,6 +14,19 @@ RSpec.describe Gitlab::GithubImport::Attachments::ImportIssueWorker do let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:issue_hash) do + { + 'record_db_id' => rand(100), + 'record_type' => 'Issue', + 'iid' => 2, + 'text' => <<-TEXT + Some text... + + ![special-image](https://user-images.githubusercontent.com...) + TEXT + } + end + it 'imports an issue attachments' do expect_next_instance_of( Gitlab::GithubImport::Importer::NoteAttachmentsImporter, @@ -28,7 +41,7 @@ RSpec.describe Gitlab::GithubImport::Attachments::ImportIssueWorker do .to receive(:increment) .and_call_original - worker.import(project, client, {}) + worker.import(project, client, issue_hash) end end end diff --git a/spec/workers/gitlab/github_import/attachments/import_merge_request_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_merge_request_worker_spec.rb index 66dfc027e6e..b4be229af2a 100644 --- a/spec/workers/gitlab/github_import/attachments/import_merge_request_worker_spec.rb +++ b/spec/workers/gitlab/github_import/attachments/import_merge_request_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Attachments::ImportMergeRequestWorker do +RSpec.describe Gitlab::GithubImport::Attachments::ImportMergeRequestWorker, feature_category: :importers do subject(:worker) { described_class.new } describe '#import' do @@ -14,6 +14,19 @@ RSpec.describe Gitlab::GithubImport::Attachments::ImportMergeRequestWorker do let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:mr_hash) do + { + 'record_db_id' => rand(100), + 'record_type' => 'MergeRequest', + 'iid' => 2, + 'text' => <<-TEXT + Some text... + + ![special-image](https://user-images.githubusercontent.com...) + TEXT + } + end + it 'imports an merge request attachments' do expect_next_instance_of( Gitlab::GithubImport::Importer::NoteAttachmentsImporter, @@ -28,7 +41,7 @@ RSpec.describe Gitlab::GithubImport::Attachments::ImportMergeRequestWorker do .to receive(:increment) .and_call_original - worker.import(project, client, {}) + worker.import(project, client, mr_hash) end end end diff --git a/spec/workers/gitlab/github_import/attachments/import_note_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_note_worker_spec.rb index 7b60cdecca6..60b49901fd9 100644 --- a/spec/workers/gitlab/github_import/attachments/import_note_worker_spec.rb +++ b/spec/workers/gitlab/github_import/attachments/import_note_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Attachments::ImportNoteWorker do +RSpec.describe Gitlab::GithubImport::Attachments::ImportNoteWorker, feature_category: :importers do subject(:worker) { described_class.new } describe '#import' do @@ -19,6 +19,7 @@ RSpec.describe Gitlab::GithubImport::Attachments::ImportNoteWorker do { 'record_db_id' => rand(100), 'record_type' => 'Note', + 'noteable_type' => 'Issue', 'text' => <<-TEXT Some text... diff --git a/spec/workers/gitlab/github_import/attachments/import_release_worker_spec.rb b/spec/workers/gitlab/github_import/attachments/import_release_worker_spec.rb index e49b2fb6504..83cb7b9fecf 100644 --- a/spec/workers/gitlab/github_import/attachments/import_release_worker_spec.rb +++ b/spec/workers/gitlab/github_import/attachments/import_release_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Attachments::ImportReleaseWorker do +RSpec.describe Gitlab::GithubImport::Attachments::ImportReleaseWorker, feature_category: :importers do subject(:worker) { described_class.new } describe '#import' do @@ -19,6 +19,7 @@ RSpec.describe Gitlab::GithubImport::Attachments::ImportReleaseWorker do { 'record_db_id' => rand(100), 'record_type' => 'Release', + 'tag' => 'v1.0', 'text' => <<-TEXT Some text... diff --git a/spec/workers/gitlab/github_import/import_collaborator_worker_spec.rb b/spec/workers/gitlab/github_import/import_collaborator_worker_spec.rb new file mode 100644 index 00000000000..b9463fb9a2d --- /dev/null +++ b/spec/workers/gitlab/github_import/import_collaborator_worker_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::ImportCollaboratorWorker, feature_category: :importers do + let(:worker) { described_class.new } + + describe '#import' do + let(:project) do + instance_double('Project', full_path: 'foo/bar', id: 1, import_state: import_state) + end + + let(:import_state) { build_stubbed(:import_state, :started) } + let(:client) { instance_double('Gitlab::GithubImport::Client') } + let(:importer) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') } + + it 'imports a collaborator' do + expect(Gitlab::GithubImport::Importer::CollaboratorImporter) + .to receive(:new) + .with( + an_instance_of(Gitlab::GithubImport::Representation::Collaborator), + project, + client + ) + .and_return(importer) + + expect(importer).to receive(:execute) + + expect(Gitlab::GithubImport::ObjectCounter) + .to receive(:increment) + .and_call_original + + worker.import( + project, client, { 'id' => 100500, 'login' => 'alice', 'role_name' => 'maintainer' } + ) + end + end +end diff --git a/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb b/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb index c92741e8f10..35d31848fe1 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportDiffNoteWorker do +RSpec.describe Gitlab::GithubImport::ImportDiffNoteWorker, feature_category: :importers do let(:worker) { described_class.new } describe '#import' do 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 index 03a6503fb84..aa8243154ef 100644 --- a/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_issue_event_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker do +RSpec.describe Gitlab::GithubImport::ImportIssueEventWorker, feature_category: :importers do subject(:worker) { described_class.new } describe '#import' do 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 ef1d2e3f3e7..76f0b512af4 100644 --- a/spec/workers/gitlab/github_import/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_issue_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportIssueWorker do +RSpec.describe Gitlab::GithubImport::ImportIssueWorker, feature_category: :importers do let(:worker) { described_class.new } describe '#import' do 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 16ca5658f77..b11ea560516 100644 --- a/spec/workers/gitlab/github_import/import_note_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_note_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportNoteWorker do +RSpec.describe Gitlab::GithubImport::ImportNoteWorker, feature_category: :importers do let(:worker) { described_class.new } describe '#import' do 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 index c2b8ee661a3..d6e8f760033 100644 --- a/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_protected_branch_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportProtectedBranchWorker do +RSpec.describe Gitlab::GithubImport::ImportProtectedBranchWorker, feature_category: :importers do let(:worker) { described_class.new } let(:import_state) { build_stubbed(:import_state, :started) } diff --git a/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb index 728b4c6b440..4fbdfb1903f 100644 --- a/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_pull_request_merged_by_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportPullRequestMergedByWorker do +RSpec.describe Gitlab::GithubImport::ImportPullRequestMergedByWorker, feature_category: :importers do it { is_expected.to include_module(Gitlab::GithubImport::ObjectImporter) } describe '#representation_class' do @@ -10,6 +10,6 @@ RSpec.describe Gitlab::GithubImport::ImportPullRequestMergedByWorker do end describe '#importer_class' do - it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequestMergedByImporter) } + it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequests::MergedByImporter) } end end diff --git a/spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb index 0607add52cd..41f97224bb4 100644 --- a/spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_pull_request_review_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportPullRequestReviewWorker do +RSpec.describe Gitlab::GithubImport::ImportPullRequestReviewWorker, feature_category: :importers do it { is_expected.to include_module(Gitlab::GithubImport::ObjectImporter) } describe '#representation_class' do @@ -10,6 +10,6 @@ RSpec.describe Gitlab::GithubImport::ImportPullRequestReviewWorker do end describe '#importer_class' do - it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequestReviewImporter) } + it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequests::ReviewImporter) } end end diff --git a/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb index 59f45b437c4..8378b67f0b5 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportPullRequestWorker do +RSpec.describe Gitlab::GithubImport::ImportPullRequestWorker, feature_category: :importers do let(:worker) { described_class.new } describe '#import' do @@ -50,5 +50,21 @@ RSpec.describe Gitlab::GithubImport::ImportPullRequestWorker do worker.import(project, client, hash) end + + describe '#importer_class' do + it { expect(worker.importer_class).to eq Gitlab::GithubImport::Importer::PullRequestImporter } + end + + describe '#representation_class' do + it { expect(worker.representation_class).to eq Gitlab::GithubImport::Representation::PullRequest } + end + + describe '#object_type' do + it { expect(worker.object_type).to eq(:pull_request) } + end + + describe '#parallel_import_batch' do + it { expect(worker.parallel_import_batch).to eq({ size: 200, delay: 1.minute }) } + 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 index 1d32d5c0e21..62a9e3446f8 100644 --- a/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_release_attachments_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ImportReleaseAttachmentsWorker do +RSpec.describe Gitlab::GithubImport::ImportReleaseAttachmentsWorker, feature_category: :importers do subject(:worker) { described_class.new } describe '#import' do @@ -17,8 +17,10 @@ RSpec.describe Gitlab::GithubImport::ImportReleaseAttachmentsWorker do let(:release_hash) do { - 'release_db_id' => rand(100), - 'description' => <<-TEXT + 'record_db_id' => rand(100), + 'record_type' => 'Release', + 'tag' => 'v1.0', + 'text' => <<-TEXT Some text... ![special-image](https://user-images.githubusercontent.com...) diff --git a/spec/workers/gitlab/github_import/pull_requests/import_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/pull_requests/import_merged_by_worker_spec.rb new file mode 100644 index 00000000000..23631c76a61 --- /dev/null +++ b/spec/workers/gitlab/github_import/pull_requests/import_merged_by_worker_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::PullRequests::ImportMergedByWorker, feature_category: :importers do + it { is_expected.to include_module(Gitlab::GithubImport::ObjectImporter) } + + describe '#representation_class' do + it { expect(subject.representation_class).to eq(Gitlab::GithubImport::Representation::PullRequest) } + end + + describe '#importer_class' do + it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequests::MergedByImporter) } + end + + describe '#object_type' do + it { expect(subject.object_type).to eq(:pull_request_merged_by) } + end +end diff --git a/spec/workers/gitlab/github_import/pull_requests/import_review_request_worker_spec.rb b/spec/workers/gitlab/github_import/pull_requests/import_review_request_worker_spec.rb index fdcbfb18beb..99ed83ae2db 100644 --- a/spec/workers/gitlab/github_import/pull_requests/import_review_request_worker_spec.rb +++ b/spec/workers/gitlab/github_import/pull_requests/import_review_request_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker do +RSpec.describe Gitlab::GithubImport::PullRequests::ImportReviewRequestWorker, feature_category: :importers do subject(:worker) { described_class.new } describe '#import' do diff --git a/spec/workers/gitlab/github_import/pull_requests/import_review_worker_spec.rb b/spec/workers/gitlab/github_import/pull_requests/import_review_worker_spec.rb new file mode 100644 index 00000000000..59d92a4bb2c --- /dev/null +++ b/spec/workers/gitlab/github_import/pull_requests/import_review_worker_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::PullRequests::ImportReviewWorker, feature_category: :importers do + it { is_expected.to include_module(Gitlab::GithubImport::ObjectImporter) } + + describe '#representation_class' do + it { expect(subject.representation_class).to eq(Gitlab::GithubImport::Representation::PullRequestReview) } + end + + describe '#importer_class' do + it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::PullRequests::ReviewImporter) } + end + + describe '#object_type' do + it { expect(subject.object_type).to eq(:pull_request_review) } + end +end diff --git a/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb b/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb index 3a8b585fa77..abba6cd7734 100644 --- a/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb +++ b/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::RefreshImportJidWorker do +RSpec.describe Gitlab::GithubImport::RefreshImportJidWorker, feature_category: :importers do let(:worker) { described_class.new } describe '.perform_in_the_future' do diff --git a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb index 5f60dfc8ca1..e517f30ee2c 100644 --- a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::FinishImportWorker do +RSpec.describe Gitlab::GithubImport::Stage::FinishImportWorker, feature_category: :importers do let(:project) { create(:project) } let(:worker) { described_class.new } 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 index ecfece735af..2945bcbe641 100644 --- a/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_attachments_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportAttachmentsWorker, feature_category: :importers do subject(:worker) { described_class.new } let_it_be(:project) { create(:project) } diff --git a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb index 7b2218b1725..1ad027a007a 100644 --- a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportBaseDataWorker, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:import_state) { create(:import_state, project: project) } diff --git a/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb new file mode 100644 index 00000000000..33ecf848997 --- /dev/null +++ b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb @@ -0,0 +1,90 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::GithubImport::Stage::ImportCollaboratorsWorker, feature_category: :importers do + let_it_be(:project) { create(:project) } + let_it_be(:import_state) { create(:import_state, project: project) } + let(:settings) { Gitlab::GithubImport::Settings.new(project) } + let(:stage_enabled) { true } + + let(:worker) { described_class.new } + let(:importer) { instance_double(Gitlab::GithubImport::Importer::CollaboratorsImporter) } + let(:client) { instance_double(Gitlab::GithubImport::Client) } + + describe '#import' do + let(:push_rights_granted) { true } + + before do + settings.write({ collaborators_import: stage_enabled }) + allow(client).to receive(:repository).with(project.import_source) + .and_return({ permissions: { push: push_rights_granted } }) + end + + context 'when user has push access for this repo' do + it 'imports all collaborators' do + waiter = Gitlab::JobWaiter.new(2, '123') + + expect(Gitlab::GithubImport::Importer::CollaboratorsImporter) + .to receive(:new) + .with(project, client) + .and_return(importer) + expect(importer).to receive(:execute).and_return(waiter) + + expect(import_state).to receive(:refresh_jid_expiration) + + expect(Gitlab::GithubImport::AdvanceStageWorker) + .to receive(:perform_async) + .with(project.id, { '123' => 2 }, :pull_requests_merged_by) + + worker.import(client, project) + end + end + + context 'when user do not have push access for this repo' do + let(:push_rights_granted) { false } + + it 'skips stage' do + expect(Gitlab::GithubImport::Importer::CollaboratorsImporter).not_to receive(:new) + + expect(Gitlab::GithubImport::AdvanceStageWorker) + .to receive(:perform_async) + .with(project.id, {}, :pull_requests_merged_by) + + worker.import(client, project) + end + end + + context 'when stage is disabled' do + let(:stage_enabled) { false } + + it 'skips collaborators import and calls next stage' do + expect(Gitlab::GithubImport::Importer::CollaboratorsImporter).not_to receive(:new) + + expect(Gitlab::GithubImport::AdvanceStageWorker) + .to receive(:perform_async) + .with(project.id, {}, :pull_requests_merged_by) + + worker.import(client, project) + end + end + + it 'raises an error' do + exception = StandardError.new('_some_error_') + + expect_next_instance_of(Gitlab::GithubImport::Importer::CollaboratorsImporter) do |importer| + expect(importer).to receive(:execute).and_raise(exception) + end + expect(Gitlab::Import::ImportFailureService).to receive(:track) + .with( + project_id: project.id, + exception: exception, + error_source: described_class.name, + fail_import: true, + metrics: true + ).and_call_original + + expect { worker.import(client, project) }.to raise_error(StandardError) + end + end +end 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 index 199d1b9a3ca..c70ee0250e8 100644 --- 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportIssueEventsWorker, feature_category: :importers do subject(:worker) { described_class.new } let(:project) { create(:project) } 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 beef0864715..872201ece93 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker, feature_category: :importers do let(:project) { create(:project) } let(:worker) { described_class.new } diff --git a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb index 103d55890c4..2449c0505f5 100644 --- a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportLfsObjectsWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportLfsObjectsWorker, feature_category: :importers do let(:project) { create(:project) } let(:worker) { described_class.new } 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 dbcf2083ec1..8c0004c0f3f 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportNotesWorker, feature_category: :importers do let(:project) { create(:project) } let(:worker) { described_class.new } 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 index 0770af524a1..f848293a3b2 100644 --- 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:import_state) { create(:import_state, project: project) } diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb index 5d6dcdc10ee..0debabda0cc 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker, feature_category: :importers do let(:project) { create(:project) } let(:import_state) { create(:import_state, project: project) } let(:worker) { described_class.new } @@ -13,7 +13,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker do client = double(:client) waiter = Gitlab::JobWaiter.new(2, '123') - expect(Gitlab::GithubImport::Importer::PullRequestsMergedByImporter) + expect(Gitlab::GithubImport::Importer::PullRequests::AllMergedByImporter) .to receive(:new) .with(project, client) .and_return(importer) diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb index 151de9bdffc..41c0b29df7c 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewRequestsWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewRequestsWorker, feature_category: :importers do subject(:worker) { described_class.new } let(:project) { instance_double(Project, id: 1, import_state: import_state) } diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb index 18a70273219..b1141c7f324 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker, feature_category: :importers do let(:project) { create(:project) } let(:import_state) { create(:import_state, project: project) } let(:worker) { described_class.new } @@ -14,7 +14,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker do waiter = Gitlab::JobWaiter.new(2, '123') - expect(Gitlab::GithubImport::Importer::PullRequestsReviewsImporter) + expect(Gitlab::GithubImport::Importer::PullRequests::ReviewsImporter) .to receive(:new) .with(project, client) .and_return(importer) diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb index b18b5ce64d1..6ebf93730eb 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:import_state) { create(:import_state, project: project) } @@ -28,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) - .with(project.id, { '123' => 2 }, :pull_requests_merged_by) + .with(project.id, { '123' => 2 }, :collaborators) worker.import(client, project) end diff --git a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb index 24fca3b7c73..94d8155d371 100644 --- a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do +RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker, feature_category: :importers do let_it_be(:project) { create(:project, :import_started) } let(:worker) { described_class.new } @@ -33,7 +33,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do :issues, project.import_source, options ).and_return([{ number: 5 }].each) - expect(Issue).to receive(:track_project_iid!).with(project, 5) + expect(Issue).to receive(:track_namespace_iid!).with(project.project_namespace, 5) expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) .to receive(:perform_async) @@ -54,7 +54,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do expect(InternalId).to receive(:exists?).and_return(false) expect(client).to receive(:each_object).with(:issues, project.import_source, options).and_return([nil].each) - expect(Issue).not_to receive(:track_project_iid!) + expect(Issue).not_to receive(:track_namespace_iid!) expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) .to receive(:perform_async) @@ -74,7 +74,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do expect(InternalId).to receive(:exists?).and_return(true) expect(client).not_to receive(:each_object) - expect(Issue).not_to receive(:track_project_iid!) + expect(Issue).not_to receive(:track_namespace_iid!) expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) .to receive(:perform_async) @@ -96,7 +96,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do expect(InternalId).to receive(:exists?).and_return(false) expect(client).to receive(:each_object).and_return([nil].each) - expect(Issue).not_to receive(:track_project_iid!) + expect(Issue).not_to receive(:track_namespace_iid!) expect(Gitlab::Import::ImportFailureService).to receive(:track) .with( diff --git a/spec/workers/gitlab/import/stuck_import_job_spec.rb b/spec/workers/gitlab/import/stuck_import_job_spec.rb index 3a1463e98a0..52721168143 100644 --- a/spec/workers/gitlab/import/stuck_import_job_spec.rb +++ b/spec/workers/gitlab/import/stuck_import_job_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Import::StuckImportJob do +RSpec.describe Gitlab::Import::StuckImportJob, feature_category: :importers do let_it_be(:project) { create(:project, :import_started, import_source: 'foo/bar') } let(:worker) do diff --git a/spec/workers/gitlab/import/stuck_project_import_jobs_worker_spec.rb b/spec/workers/gitlab/import/stuck_project_import_jobs_worker_spec.rb index d12d5a605a7..9994896d3c8 100644 --- a/spec/workers/gitlab/import/stuck_project_import_jobs_worker_spec.rb +++ b/spec/workers/gitlab/import/stuck_project_import_jobs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Import::StuckProjectImportJobsWorker do +RSpec.describe Gitlab::Import::StuckProjectImportJobsWorker, feature_category: :importers do let(:worker) { described_class.new } describe 'with scheduled import_status' do diff --git a/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb b/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb index 0244e69b7b6..5209395923f 100644 --- a/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::JiraImport::ImportIssueWorker do +RSpec.describe Gitlab::JiraImport::ImportIssueWorker, feature_category: :importers do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:jira_issue_label_1) { create(:label, project: project) } diff --git a/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb index 23a764bd972..d1bf71a2095 100644 --- a/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::JiraImport::Stage::FinishImportWorker do +RSpec.describe Gitlab::JiraImport::Stage::FinishImportWorker, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:worker) { described_class.new } diff --git a/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb index 28da93b8d00..c594182bf75 100644 --- a/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_attachments_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::JiraImport::Stage::ImportAttachmentsWorker do +RSpec.describe Gitlab::JiraImport::Stage::ImportAttachmentsWorker, feature_category: :importers do let_it_be(:project) { create(:project, import_type: 'jira') } describe 'modules' do diff --git a/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb index 2b08a592164..594f9618770 100644 --- a/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_issues_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::JiraImport::Stage::ImportIssuesWorker do +RSpec.describe Gitlab::JiraImport::Stage::ImportIssuesWorker, feature_category: :importers do include JiraIntegrationHelpers let_it_be(:user) { create(:user) } diff --git a/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb index d15f2caba19..d9c2407a423 100644 --- a/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_labels_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::JiraImport::Stage::ImportLabelsWorker do +RSpec.describe Gitlab::JiraImport::Stage::ImportLabelsWorker, feature_category: :importers do include JiraIntegrationHelpers let_it_be(:user) { create(:user) } diff --git a/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb index 2502bbf1df4..41216356033 100644 --- a/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/import_notes_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::JiraImport::Stage::ImportNotesWorker do +RSpec.describe Gitlab::JiraImport::Stage::ImportNotesWorker, feature_category: :importers do let_it_be(:project) { create(:project, import_type: 'jira') } describe 'modules' do diff --git a/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb b/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb index e440884553f..ea0291b1c44 100644 --- a/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stage/start_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::JiraImport::Stage::StartImportWorker do +RSpec.describe Gitlab::JiraImport::Stage::StartImportWorker, feature_category: :importers do let_it_be(:project) { create(:project, import_type: 'jira') } let_it_be(:jid) { '12345678' } diff --git a/spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb b/spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb index 92754513988..0f9f9b70c3e 100644 --- a/spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/stuck_jira_import_jobs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Gitlab::JiraImport::StuckJiraImportJobsWorker do +RSpec.describe ::Gitlab::JiraImport::StuckJiraImportJobsWorker, feature_category: :importers do let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } diff --git a/spec/workers/gitlab/phabricator_import/base_worker_spec.rb b/spec/workers/gitlab/phabricator_import/base_worker_spec.rb deleted file mode 100644 index 18fa484aa7a..00000000000 --- a/spec/workers/gitlab/phabricator_import/base_worker_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true -require 'spec_helper' - -RSpec.describe Gitlab::PhabricatorImport::BaseWorker do - let(:subclass) do - # Creating an anonymous class for a worker is complicated, as we generate the - # queue name from the class name. - Gitlab::PhabricatorImport::ImportTasksWorker - end - - describe '.schedule' do - let(:arguments) { %w[project_id the_next_page] } - - it 'schedules the job' do - expect(subclass).to receive(:perform_async).with(*arguments) - - subclass.schedule(*arguments) - end - - it 'counts the scheduled job', :clean_gitlab_redis_shared_state do - state = Gitlab::PhabricatorImport::WorkerState.new('project_id') - - allow(subclass).to receive(:remove_job) # otherwise the job is removed before we saw it - - expect { subclass.schedule(*arguments) }.to change { state.running_count }.by(1) - end - end - - describe '#perform' do - let(:project) { create(:project, :import_started, import_url: "https://a.phab.instance") } - let(:worker) { subclass.new } - let(:state) { Gitlab::PhabricatorImport::WorkerState.new(project.id) } - - before do - allow(worker).to receive(:import) - end - - it 'does not break for a non-existing project' do - expect { worker.perform('not a thing') }.not_to raise_error - end - - it 'does not do anything when the import is not in progress' do - project = create(:project, :import_failed) - - expect(worker).not_to receive(:import) - - worker.perform(project.id) - end - - it 'calls import for the project' do - expect(worker).to receive(:import).with(project, 'other_arg') - - worker.perform(project.id, 'other_arg') - end - - it 'marks the project as imported if there was only one job running' do - worker.perform(project.id) - - expect(project.import_state.reload).to be_finished - end - - it 'does not mark the job as finished when there are more scheduled jobs' do - 2.times { state.add_job } - - worker.perform(project.id) - - expect(project.import_state.reload).to be_in_progress - end - - it 'decrements the job counter' do - expect { worker.perform(project.id) }.to change { state.running_count }.by(-1) - end - end -end diff --git a/spec/workers/gitlab/phabricator_import/import_tasks_worker_spec.rb b/spec/workers/gitlab/phabricator_import/import_tasks_worker_spec.rb deleted file mode 100644 index 221b6202166..00000000000 --- a/spec/workers/gitlab/phabricator_import/import_tasks_worker_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true -require 'spec_helper' - -RSpec.describe Gitlab::PhabricatorImport::ImportTasksWorker do - describe '#perform' do - it 'calls the correct importer' do - project = create(:project, :import_started, import_url: "https://the.phab.ulr") - fake_importer = instance_double(Gitlab::PhabricatorImport::Issues::Importer) - - expect(Gitlab::PhabricatorImport::Issues::Importer).to receive(:new).with(project).and_return(fake_importer) - expect(fake_importer).to receive(:execute) - - described_class.new.perform(project.id) - end - end -end diff --git a/spec/workers/gitlab_performance_bar_stats_worker_spec.rb b/spec/workers/gitlab_performance_bar_stats_worker_spec.rb index 3638add1524..45fb58826ba 100644 --- a/spec/workers/gitlab_performance_bar_stats_worker_spec.rb +++ b/spec/workers/gitlab_performance_bar_stats_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GitlabPerformanceBarStatsWorker do +RSpec.describe GitlabPerformanceBarStatsWorker, feature_category: :metrics do include ExclusiveLeaseHelpers subject(:worker) { described_class.new } diff --git a/spec/workers/gitlab_service_ping_worker_spec.rb b/spec/workers/gitlab_service_ping_worker_spec.rb index f17847a7b33..1d16e8c3496 100644 --- a/spec/workers/gitlab_service_ping_worker_spec.rb +++ b/spec/workers/gitlab_service_ping_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do +RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state, feature_category: :service_ping do let(:payload) { { recorded_at: Time.current.rfc3339 } } before do @@ -14,15 +14,13 @@ RSpec.describe GitlabServicePingWorker, :clean_gitlab_redis_shared_state do allow(subject).to receive(:sleep) end - it 'does not run for GitLab.com when triggered from cron' do - allow(Gitlab).to receive(:com?).and_return(true) + it 'does not run for SaaS when triggered from cron', :saas do 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) + it 'runs for SaaS when triggered manually', :saas do expect(ServicePing::SubmitService).to receive(:new) subject.perform('triggered_from_cron' => false) diff --git a/spec/workers/gitlab_shell_worker_spec.rb b/spec/workers/gitlab_shell_worker_spec.rb index 838f2ef4ba4..9fff4489667 100644 --- a/spec/workers/gitlab_shell_worker_spec.rb +++ b/spec/workers/gitlab_shell_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GitlabShellWorker, :sidekiq_inline do +RSpec.describe GitlabShellWorker, :sidekiq_inline, feature_category: :source_code_management do describe '#perform' do Gitlab::Shell::PERMITTED_ACTIONS.each do |action| describe "with the #{action} action" 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 index 5d595a3679b..7aea40807e8 100644 --- a/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb +++ b/spec/workers/google_cloud/create_cloudsql_instance_worker_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'google/apis/sqladmin_v1beta4' -RSpec.describe GoogleCloud::CreateCloudsqlInstanceWorker do +RSpec.describe GoogleCloud::CreateCloudsqlInstanceWorker, feature_category: :shared do let(:random_user) { create(:user) } let(:project) { create(:project) } let(:worker_options) do diff --git a/spec/workers/group_destroy_worker_spec.rb b/spec/workers/group_destroy_worker_spec.rb index 82ae9010a24..fba4573718a 100644 --- a/spec/workers/group_destroy_worker_spec.rb +++ b/spec/workers/group_destroy_worker_spec.rb @@ -2,20 +2,29 @@ require 'spec_helper' -RSpec.describe GroupDestroyWorker do - let(:group) { create(:group) } - let!(:project) { create(:project, namespace: group) } - let(:user) { create(:user) } +RSpec.describe GroupDestroyWorker, feature_category: :subgroups do + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, namespace: group) } + let_it_be(:user) { create(:user) } before do group.add_owner(user) end - subject { described_class.new } + subject(:worker) { described_class.new } + + include_examples 'an idempotent worker' do + let(:job_args) { [group.id, user.id] } + + it 'does not change groups when run twice' do + expect { worker.perform(group.id, user.id) }.to change { Group.count }.by(-1) + expect { worker.perform(group.id, user.id) }.not_to change { Group.count } + end + end describe "#perform" do - it "deletes the project" do - subject.perform(group.id, user.id) + it "deletes the group and associated projects" do + worker.perform(group.id, user.id) expect(Group.all).not_to include(group) expect(Project.all).not_to include(project) diff --git a/spec/workers/group_export_worker_spec.rb b/spec/workers/group_export_worker_spec.rb index 4e58e3886a4..54f9c38a506 100644 --- a/spec/workers/group_export_worker_spec.rb +++ b/spec/workers/group_export_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GroupExportWorker do +RSpec.describe GroupExportWorker, feature_category: :importers do let!(:user) { create(:user) } let!(:group) { create(:group) } diff --git a/spec/workers/group_import_worker_spec.rb b/spec/workers/group_import_worker_spec.rb index 5171de7086b..9aa6aaec24c 100644 --- a/spec/workers/group_import_worker_spec.rb +++ b/spec/workers/group_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe GroupImportWorker do +RSpec.describe GroupImportWorker, feature_category: :importers do let(:user) { create(:user) } let(:group) { create(:group) } diff --git a/spec/workers/groups/update_statistics_worker_spec.rb b/spec/workers/groups/update_statistics_worker_spec.rb index 7fc166ed300..f47606f0580 100644 --- a/spec/workers/groups/update_statistics_worker_spec.rb +++ b/spec/workers/groups/update_statistics_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Groups::UpdateStatisticsWorker do +RSpec.describe Groups::UpdateStatisticsWorker, feature_category: :source_code_management do let_it_be(:group) { create(:group) } let(:statistics) { %w(wiki_size) } 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 index 9d202b9452f..aa1ca698095 100644 --- 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Groups::UpdateTwoFactorRequirementForMembersWorker do +RSpec.describe Groups::UpdateTwoFactorRequirementForMembersWorker, feature_category: :system_access do let_it_be(:group) { create(:group) } let(:worker) { described_class.new } diff --git a/spec/workers/hashed_storage/migrator_worker_spec.rb b/spec/workers/hashed_storage/migrator_worker_spec.rb index e014297756e..f188928cf92 100644 --- a/spec/workers/hashed_storage/migrator_worker_spec.rb +++ b/spec/workers/hashed_storage/migrator_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe HashedStorage::MigratorWorker do +RSpec.describe HashedStorage::MigratorWorker, feature_category: :source_code_management do subject(:worker) { described_class.new } let(:projects) { create_list(:project, 2, :legacy_storage, :empty_repo) } diff --git a/spec/workers/hashed_storage/project_migrate_worker_spec.rb b/spec/workers/hashed_storage/project_migrate_worker_spec.rb index fd460888932..84592e85eaa 100644 --- a/spec/workers/hashed_storage/project_migrate_worker_spec.rb +++ b/spec/workers/hashed_storage/project_migrate_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe HashedStorage::ProjectMigrateWorker, :clean_gitlab_redis_shared_state do +RSpec.describe HashedStorage::ProjectMigrateWorker, :clean_gitlab_redis_shared_state, feature_category: :source_code_management do include ExclusiveLeaseHelpers let(:migration_service) { ::Projects::HashedStorage::MigrationService } diff --git a/spec/workers/hashed_storage/project_rollback_worker_spec.rb b/spec/workers/hashed_storage/project_rollback_worker_spec.rb index fc89ac728b1..f27b5e4b9ce 100644 --- a/spec/workers/hashed_storage/project_rollback_worker_spec.rb +++ b/spec/workers/hashed_storage/project_rollback_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe HashedStorage::ProjectRollbackWorker, :clean_gitlab_redis_shared_state do +RSpec.describe HashedStorage::ProjectRollbackWorker, :clean_gitlab_redis_shared_state, feature_category: :source_code_management do include ExclusiveLeaseHelpers describe '#perform' do diff --git a/spec/workers/hashed_storage/rollbacker_worker_spec.rb b/spec/workers/hashed_storage/rollbacker_worker_spec.rb index 46cca068273..af8957d9b96 100644 --- a/spec/workers/hashed_storage/rollbacker_worker_spec.rb +++ b/spec/workers/hashed_storage/rollbacker_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe HashedStorage::RollbackerWorker do +RSpec.describe HashedStorage::RollbackerWorker, feature_category: :source_code_management do subject(:worker) { described_class.new } let(:projects) { create_list(:project, 2, :empty_repo) } diff --git a/spec/workers/import_issues_csv_worker_spec.rb b/spec/workers/import_issues_csv_worker_spec.rb index 919ab2b1adf..7f38119d499 100644 --- a/spec/workers/import_issues_csv_worker_spec.rb +++ b/spec/workers/import_issues_csv_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ImportIssuesCsvWorker do +RSpec.describe ImportIssuesCsvWorker, feature_category: :team_planning do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } diff --git a/spec/workers/incident_management/add_severity_system_note_worker_spec.rb b/spec/workers/incident_management/add_severity_system_note_worker_spec.rb index 4d6e6610a92..cd19c5694b5 100644 --- a/spec/workers/incident_management/add_severity_system_note_worker_spec.rb +++ b/spec/workers/incident_management/add_severity_system_note_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe IncidentManagement::AddSeveritySystemNoteWorker do +RSpec.describe IncidentManagement::AddSeveritySystemNoteWorker, feature_category: :incident_management do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:incident) { create(:incident, project: project) } diff --git a/spec/workers/incident_management/close_incident_worker_spec.rb b/spec/workers/incident_management/close_incident_worker_spec.rb index 145ee780573..3c2e69a4675 100644 --- a/spec/workers/incident_management/close_incident_worker_spec.rb +++ b/spec/workers/incident_management/close_incident_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe IncidentManagement::CloseIncidentWorker do +RSpec.describe IncidentManagement::CloseIncidentWorker, feature_category: :incident_management do subject(:worker) { described_class.new } describe '#perform' do @@ -36,7 +36,7 @@ RSpec.describe IncidentManagement::CloseIncidentWorker do context 'when issue type is not incident' do before do - issue.update!(issue_type: :issue) + issue.update!(issue_type: :issue, work_item_type: WorkItems::Type.default_by_type(:issue)) end it_behaves_like 'does not call the close issue service' diff --git a/spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb b/spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb index b81f1a575b5..f537acfaa05 100644 --- a/spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb +++ b/spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe IncidentManagement::PagerDuty::ProcessIncidentWorker do +RSpec.describe IncidentManagement::PagerDuty::ProcessIncidentWorker, feature_category: :incident_management do let_it_be(:project) { create(:project) } let_it_be(:incident_management_setting) { create(:project_incident_management_setting, project: project, pagerduty_active: true) } diff --git a/spec/workers/incident_management/process_alert_worker_v2_spec.rb b/spec/workers/incident_management/process_alert_worker_v2_spec.rb index 6cde8b758fa..476b6f04942 100644 --- a/spec/workers/incident_management/process_alert_worker_v2_spec.rb +++ b/spec/workers/incident_management/process_alert_worker_v2_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe IncidentManagement::ProcessAlertWorkerV2 do +RSpec.describe IncidentManagement::ProcessAlertWorkerV2, feature_category: :incident_management do let_it_be(:project) { create(:project) } let_it_be(:settings) { create(:project_incident_management_setting, project: project, create_issue: true) } diff --git a/spec/workers/integrations/create_external_cross_reference_worker_spec.rb b/spec/workers/integrations/create_external_cross_reference_worker_spec.rb index 8e586b90905..ee974fe2b28 100644 --- a/spec/workers/integrations/create_external_cross_reference_worker_spec.rb +++ b/spec/workers/integrations/create_external_cross_reference_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::CreateExternalCrossReferenceWorker do +RSpec.describe Integrations::CreateExternalCrossReferenceWorker, feature_category: :integrations do include AfterNextHelpers using RSpec::Parameterized::TableSyntax diff --git a/spec/workers/integrations/execute_worker_spec.rb b/spec/workers/integrations/execute_worker_spec.rb index 0e585e3006c..717e3c65820 100644 --- a/spec/workers/integrations/execute_worker_spec.rb +++ b/spec/workers/integrations/execute_worker_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Integrations::ExecuteWorker, '#perform' do +RSpec.describe Integrations::ExecuteWorker, '#perform', feature_category: :integrations do let_it_be(:integration) { create(:jira_integration) } let(:worker) { described_class.new } diff --git a/spec/workers/integrations/irker_worker_spec.rb b/spec/workers/integrations/irker_worker_spec.rb index 3b7b9af72fd..9866415c99e 100644 --- a/spec/workers/integrations/irker_worker_spec.rb +++ b/spec/workers/integrations/irker_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Integrations::IrkerWorker, '#perform' do +RSpec.describe Integrations::IrkerWorker, '#perform', feature_category: :integrations do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } let_it_be(:push_data) { HashWithIndifferentAccess.new(Gitlab::DataBuilder::Push.build_sample(project, user)) } @@ -88,10 +88,11 @@ RSpec.describe Integrations::IrkerWorker, '#perform' do context 'with new commits to existing branch' do it 'sends a correct message with a compare url' do - compare_url = Gitlab::Routing.url_helpers - .project_compare_url(project, - from: Commit.truncate_sha(push_data[:before]), - to: Commit.truncate_sha(push_data[:after])) + compare_url = Gitlab::Routing.url_helpers.project_compare_url( + project, + from: Commit.truncate_sha(push_data[:before]), + to: Commit.truncate_sha(push_data[:after]) + ) message = "pushed #{push_data['total_commits_count']} " \ "new commits to master: #{compare_url}" @@ -104,7 +105,7 @@ RSpec.describe Integrations::IrkerWorker, '#perform' do end def wrap_message(text) - message = "[#{project.path}] #{push_data['user_name']} #{text}" + message = "[#{project.name}] #{push_data['user_name']} #{text}" to_send = { to: channels, privmsg: message } Gitlab::Json.dump(to_send) diff --git a/spec/workers/integrations/slack_event_worker_spec.rb b/spec/workers/integrations/slack_event_worker_spec.rb new file mode 100644 index 00000000000..6754801a2bd --- /dev/null +++ b/spec/workers/integrations/slack_event_worker_spec.rb @@ -0,0 +1,129 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Integrations::SlackEventWorker, :clean_gitlab_redis_shared_state, feature_category: :integrations do + describe '.event?' do + subject { described_class.event?(event) } + + context 'when event is known' do + let(:event) { 'app_home_opened' } + + it { is_expected.to eq(true) } + end + + context 'when event is not known' do + let(:event) { 'foo' } + + it { is_expected.to eq(false) } + end + end + + describe '#perform' do + let(:worker) { described_class.new } + let(:event) { 'app_home_opened' } + let(:service_class) { ::Integrations::SlackEvents::AppHomeOpenedService } + + let(:args) do + { + slack_event: event, + params: params + } + end + + let(:params) do + { + team_id: "T0123A456BC", + event: { user: "U0123ABCDEF" }, + event_id: "Ev03SA75UJKB" + } + end + + shared_examples 'logs extra metadata on done' do + specify do + expect(worker).to receive(:log_extra_metadata_on_done).with(:slack_event, event) + expect(worker).to receive(:log_extra_metadata_on_done).with(:slack_user_id, 'U0123ABCDEF') + expect(worker).to receive(:log_extra_metadata_on_done).with(:slack_workspace_id, 'T0123A456BC') + + worker.perform(args) + end + end + + it 'executes the correct service' do + expect_next_instance_of(service_class, params) do |service| + expect(service).to receive(:execute).and_return(ServiceResponse.success) + end + + worker.perform(args) + end + + it_behaves_like 'logs extra metadata on done' + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [args] } + end + + it 'ensures idempotency when called twice by only executing service once' do + expect_next_instances_of(service_class, 1, params) do |service| + expect(service).to receive(:execute).and_return(ServiceResponse.success) + end + + worker.perform(args) + worker.perform(args) + end + + it 'executes service twice if service returned an error' do + expect_next_instances_of(service_class, 2, params) do |service| + expect(service).to receive(:execute).and_return(ServiceResponse.error(message: 'foo')) + end + + worker.perform(args) + worker.perform(args) + end + + it 'executes service twice if service raised an error' do + expect_next_instances_of(service_class, 2, params) do |service| + expect(service).to receive(:execute).and_raise(ArgumentError) + end + + expect { worker.perform(args) }.to raise_error(ArgumentError) + expect { worker.perform(args) }.to raise_error(ArgumentError) + end + + it 'executes service twice when event_id is different' do + second_params = params.dup + second_args = args.dup + second_params[:event_id] = 'foo' + second_args[:params] = second_params + + expect_next_instances_of(service_class, 1, params) do |service| + expect(service).to receive(:execute).and_return(ServiceResponse.success) + end + + expect_next_instances_of(service_class, 1, second_params) do |service| + expect(service).to receive(:execute).and_return(ServiceResponse.success) + end + + worker.perform(args) + worker.perform(second_args) + end + + context 'when event is not known' do + let(:event) { 'foo' } + + it 'does not execute the service class' do + expect(service_class).not_to receive(:new) + + worker.perform(args) + end + + it 'logs an error' do + expect(Sidekiq.logger).to receive(:error).with({ message: 'Unknown slack_event', slack_event: event }) + + worker.perform(args) + end + + it_behaves_like 'logs extra metadata on done' + end + end +end diff --git a/spec/workers/invalid_gpg_signature_update_worker_spec.rb b/spec/workers/invalid_gpg_signature_update_worker_spec.rb index 25c48b55cbb..81a15e79579 100644 --- a/spec/workers/invalid_gpg_signature_update_worker_spec.rb +++ b/spec/workers/invalid_gpg_signature_update_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe InvalidGpgSignatureUpdateWorker do +RSpec.describe InvalidGpgSignatureUpdateWorker, feature_category: :source_code_management do context 'when GpgKey is found' do it 'calls NotificationService.new.run' do gpg_key = create(:gpg_key) diff --git a/spec/workers/issuable/label_links_destroy_worker_spec.rb b/spec/workers/issuable/label_links_destroy_worker_spec.rb index a838f1c8017..d993c6cb22f 100644 --- a/spec/workers/issuable/label_links_destroy_worker_spec.rb +++ b/spec/workers/issuable/label_links_destroy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Issuable::LabelLinksDestroyWorker do +RSpec.describe Issuable::LabelLinksDestroyWorker, feature_category: :team_planning do let(:job_args) { [1, 'MergeRequest'] } let(:service) { double } diff --git a/spec/workers/issuable_export_csv_worker_spec.rb b/spec/workers/issuable_export_csv_worker_spec.rb index a5172d916b6..e54466b3641 100644 --- a/spec/workers/issuable_export_csv_worker_spec.rb +++ b/spec/workers/issuable_export_csv_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe IssuableExportCsvWorker do +RSpec.describe IssuableExportCsvWorker, feature_category: :team_planning do let(:user) { create(:user) } let(:project) { create(:project, creator: user) } let(:params) { {} } @@ -22,6 +22,10 @@ RSpec.describe IssuableExportCsvWorker do subject end + it 'defines the loggable_arguments' do + expect(described_class.loggable_arguments).to match_array([0, 1, 2, 3]) + end + it 'removes sort parameter' do expect(IssuesFinder).to receive(:new).with(anything, hash_not_including(:sort)).and_call_original @@ -50,6 +54,19 @@ RSpec.describe IssuableExportCsvWorker do end end + shared_examples 'export with selected fields' do + let(:selected_fields) { %w[Title Description'] } + + it 'calls the export service with selected fields' do + params[:selected_fields] = selected_fields + + expect(export_service) + .to receive(:new).with(anything, project, selected_fields).once.and_call_original + + subject + end + end + context 'when issuable type is MergeRequest' do let(:issuable_type) { :merge_request } @@ -58,7 +75,7 @@ RSpec.describe IssuableExportCsvWorker do end it 'calls the MR export service' do - expect(MergeRequests::ExportCsvService).to receive(:new).with(anything, project).once.and_call_original + expect(MergeRequests::ExportCsvService).to receive(:new).with(anything, project, []).once.and_call_original subject end @@ -68,6 +85,34 @@ RSpec.describe IssuableExportCsvWorker do subject end + + it_behaves_like 'export with selected fields' do + let(:export_service) { MergeRequests::ExportCsvService } + end + end + + context 'for type WorkItem' do + let(:issuable_type) { :work_item } + + it 'emails a CSV' do + expect { subject }.to change { ActionMailer::Base.deliveries.size }.by(1) + end + + it 'calls the work item export service' do + expect(WorkItems::ExportCsvService).to receive(:new).with(anything, project, []).once.and_call_original + + subject + end + + it 'calls the WorkItemsFinder' do + expect(WorkItems::WorkItemsFinder).to receive(:new).once.and_call_original + + subject + end + + it_behaves_like 'export with selected fields' do + let(:export_service) { WorkItems::ExportCsvService } + end end context 'when issuable type is User' do diff --git a/spec/workers/issuables/clear_groups_issue_counter_worker_spec.rb b/spec/workers/issuables/clear_groups_issue_counter_worker_spec.rb index ac430f42e7a..e8f39388328 100644 --- a/spec/workers/issuables/clear_groups_issue_counter_worker_spec.rb +++ b/spec/workers/issuables/clear_groups_issue_counter_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Issuables::ClearGroupsIssueCounterWorker do +RSpec.describe Issuables::ClearGroupsIssueCounterWorker, feature_category: :team_planning do describe '#perform' do let_it_be(:user) { create(:user) } let_it_be(:parent_group) { create(:group) } diff --git a/spec/workers/issue_due_scheduler_worker_spec.rb b/spec/workers/issue_due_scheduler_worker_spec.rb index aecff4a3d93..8988dc86168 100644 --- a/spec/workers/issue_due_scheduler_worker_spec.rb +++ b/spec/workers/issue_due_scheduler_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe IssueDueSchedulerWorker do +RSpec.describe IssueDueSchedulerWorker, feature_category: :team_planning do describe '#perform' do it 'schedules one MailScheduler::IssueDueWorker per project with open issues due tomorrow' do project1 = create(:project) diff --git a/spec/workers/issues/close_worker_spec.rb b/spec/workers/issues/close_worker_spec.rb index 3902618ae03..488be7eb067 100644 --- a/spec/workers/issues/close_worker_spec.rb +++ b/spec/workers/issues/close_worker_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Issues::CloseWorker do +RSpec.describe Issues::CloseWorker, feature_category: :team_planning do describe "#perform" do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public, :repository) } diff --git a/spec/workers/issues/placement_worker_spec.rb b/spec/workers/issues/placement_worker_spec.rb index 33fa0b31b72..710b3d07938 100644 --- a/spec/workers/issues/placement_worker_spec.rb +++ b/spec/workers/issues/placement_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Issues::PlacementWorker do +RSpec.describe Issues::PlacementWorker, feature_category: :team_planning do describe '#perform' do let_it_be(:time) { Time.now.utc } let_it_be(:group) { create(:group) } diff --git a/spec/workers/issues/rebalancing_worker_spec.rb b/spec/workers/issues/rebalancing_worker_spec.rb index e1c0b348a4f..e0dccf0c56e 100644 --- a/spec/workers/issues/rebalancing_worker_spec.rb +++ b/spec/workers/issues/rebalancing_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Issues::RebalancingWorker do +RSpec.describe Issues::RebalancingWorker, feature_category: :team_planning do describe '#perform' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, group: group) } diff --git a/spec/workers/issues/reschedule_stuck_issue_rebalances_worker_spec.rb b/spec/workers/issues/reschedule_stuck_issue_rebalances_worker_spec.rb index 6723c425f34..fa23ffe92f1 100644 --- a/spec/workers/issues/reschedule_stuck_issue_rebalances_worker_spec.rb +++ b/spec/workers/issues/reschedule_stuck_issue_rebalances_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Issues::RescheduleStuckIssueRebalancesWorker, :clean_gitlab_redis_shared_state do +RSpec.describe Issues::RescheduleStuckIssueRebalancesWorker, :clean_gitlab_redis_shared_state, feature_category: :team_planning do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, group: group) } diff --git a/spec/workers/jira_connect/forward_event_worker_spec.rb b/spec/workers/jira_connect/forward_event_worker_spec.rb index d3db07b8cb4..1be59d846f2 100644 --- a/spec/workers/jira_connect/forward_event_worker_spec.rb +++ b/spec/workers/jira_connect/forward_event_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe JiraConnect::ForwardEventWorker do +RSpec.describe JiraConnect::ForwardEventWorker, feature_category: :integrations do describe '#perform' do let!(:jira_connect_installation) { create(:jira_connect_installation, instance_url: self_managed_url, client_key: client_key, shared_secret: shared_secret) } let(:base_path) { '/-/jira_connect' } diff --git a/spec/workers/jira_connect/retry_request_worker_spec.rb b/spec/workers/jira_connect/retry_request_worker_spec.rb index 7a93e5fe41d..e96a050da13 100644 --- a/spec/workers/jira_connect/retry_request_worker_spec.rb +++ b/spec/workers/jira_connect/retry_request_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe JiraConnect::RetryRequestWorker do +RSpec.describe JiraConnect::RetryRequestWorker, feature_category: :integrations do describe '#perform' do let(:jwt) { 'some-jwt' } let(:event_url) { 'https://example.com/somewhere' } diff --git a/spec/workers/jira_connect/sync_branch_worker_spec.rb b/spec/workers/jira_connect/sync_branch_worker_spec.rb index 349ccd10694..1c2661ad0e5 100644 --- a/spec/workers/jira_connect/sync_branch_worker_spec.rb +++ b/spec/workers/jira_connect/sync_branch_worker_spec.rb @@ -2,12 +2,10 @@ require 'spec_helper' -RSpec.describe JiraConnect::SyncBranchWorker do +RSpec.describe JiraConnect::SyncBranchWorker, feature_category: :integrations do include AfterNextHelpers - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed describe '#perform' do let_it_be(:group) { create(:group) } diff --git a/spec/workers/jira_connect/sync_builds_worker_spec.rb b/spec/workers/jira_connect/sync_builds_worker_spec.rb index 9be0cccae2b..8c694fe33bd 100644 --- a/spec/workers/jira_connect/sync_builds_worker_spec.rb +++ b/spec/workers/jira_connect/sync_builds_worker_spec.rb @@ -2,12 +2,10 @@ require 'spec_helper' -RSpec.describe ::JiraConnect::SyncBuildsWorker do +RSpec.describe ::JiraConnect::SyncBuildsWorker, feature_category: :integrations do include AfterNextHelpers - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed describe '#perform' do let_it_be(:pipeline) { create(:ci_pipeline) } diff --git a/spec/workers/jira_connect/sync_deployments_worker_spec.rb b/spec/workers/jira_connect/sync_deployments_worker_spec.rb index 86ba11ebe9c..39609f331d0 100644 --- a/spec/workers/jira_connect/sync_deployments_worker_spec.rb +++ b/spec/workers/jira_connect/sync_deployments_worker_spec.rb @@ -2,12 +2,10 @@ require 'spec_helper' -RSpec.describe ::JiraConnect::SyncDeploymentsWorker do +RSpec.describe ::JiraConnect::SyncDeploymentsWorker, feature_category: :integrations do include AfterNextHelpers - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed describe '#perform' do let_it_be(:deployment) { create(:deployment) } diff --git a/spec/workers/jira_connect/sync_feature_flags_worker_spec.rb b/spec/workers/jira_connect/sync_feature_flags_worker_spec.rb index 6763aefcbec..cc3867d26c1 100644 --- a/spec/workers/jira_connect/sync_feature_flags_worker_spec.rb +++ b/spec/workers/jira_connect/sync_feature_flags_worker_spec.rb @@ -2,12 +2,10 @@ require 'spec_helper' -RSpec.describe ::JiraConnect::SyncFeatureFlagsWorker do +RSpec.describe ::JiraConnect::SyncFeatureFlagsWorker, feature_category: :integrations do include AfterNextHelpers - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed describe '#perform' do let_it_be(:feature_flag) { create(:operations_feature_flag) } diff --git a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb index 65976566b22..6b6f7610f07 100644 --- a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb +++ b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb @@ -2,12 +2,10 @@ require 'spec_helper' -RSpec.describe JiraConnect::SyncMergeRequestWorker do +RSpec.describe JiraConnect::SyncMergeRequestWorker, feature_category: :integrations do include AfterNextHelpers - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed describe '#perform' do let_it_be(:group) { create(:group) } @@ -24,7 +22,7 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do it 'calls JiraConnect::SyncService#execute' do expect_next(JiraConnect::SyncService).to receive(:execute) - .with(merge_requests: [merge_request], update_sequence_id: update_sequence_id) + .with(merge_requests: [merge_request], branches: [have_attributes(name: 'master')], update_sequence_id: update_sequence_id) perform end @@ -38,5 +36,32 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do perform end end + + shared_examples 'does not send any branch data' do + it 'calls JiraConnect::SyncService correctly with nil branches' do + expect_next(JiraConnect::SyncService).to receive(:execute) + .with(merge_requests: [merge_request], branches: nil, update_sequence_id: update_sequence_id) + + perform + end + end + + context 'when the merge request is closed' do + before do + merge_request.close! + end + + it_behaves_like 'does not send any branch data' + end + + context 'when source branch cannot be found' do + before do + allow_next_found_instance_of(MergeRequest) do |mr| + allow(mr).to receive(:source_branch).and_return('non-existant-branch') + end + end + + it_behaves_like 'does not send any branch data' + end end end diff --git a/spec/workers/jira_connect/sync_project_worker_spec.rb b/spec/workers/jira_connect/sync_project_worker_spec.rb index d172bde2400..b617508bb3a 100644 --- a/spec/workers/jira_connect/sync_project_worker_spec.rb +++ b/spec/workers/jira_connect/sync_project_worker_spec.rb @@ -2,20 +2,19 @@ require 'spec_helper' -RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep do +RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep, feature_category: :integrations do include AfterNextHelpers - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed describe '#perform' do - let_it_be(:project) { create_default(:project).freeze } + let_it_be(:project) { create_default(:project, :repository).freeze } let!(:mr_with_jira_title) { create(:merge_request, :unique_branches, title: 'TEST-123') } let!(:mr_with_jira_description) { create(:merge_request, :unique_branches, description: 'TEST-323') } let!(:mr_with_other_title) { create(:merge_request, :unique_branches) } let!(:jira_subscription) { create(:jira_connect_subscription, namespace: project.namespace) } + let(:jira_referencing_branch_name) { 'TEST-123_my-feature-branch' } let(:jira_connect_sync_service) { JiraConnect::SyncService.new(project) } let(:job_args) { [project.id, update_sequence_id] } @@ -27,6 +26,7 @@ RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep do Atlassian::JiraConnect::Serializers::RepositoryEntity.represent( project, merge_requests: [mr_with_jira_description, mr_with_jira_title], + branches: [project.repository.find_branch(jira_referencing_branch_name)], update_sequence_id: update_sequence_id ) ] @@ -58,23 +58,57 @@ RSpec.describe JiraConnect::SyncProjectWorker, factory_default: :keep do expect { perform(project.id, update_sequence_id) }.not_to exceed_query_limit(control_count) end - it 'sends the request with custom update_sequence_id' do - allow_next(Atlassian::JiraConnect::Client).to receive(:post) - .with(request_path, request_body) + context 'with branches to sync' do + context 'on a single branch' do + it 'sends the request with custom update_sequence_id' do + project.repository.create_branch(jira_referencing_branch_name) - perform(project.id, update_sequence_id) + allow_next(Atlassian::JiraConnect::Client).to receive(:post) + .with(request_path, request_body) + + perform(project.id, update_sequence_id) + end + end + + context 'on multiple branches' do + after do + project.repository.rm_branch(project.owner, 'TEST-2_my-feature-branch') + project.repository.rm_branch(project.owner, 'TEST-3_my-feature-branch') + project.repository.rm_branch(project.owner, 'TEST-4_my-feature-branch') + end + + it 'does not requests a lot from Gitaly', :request_store do + # NOTE: Gitaly N+1 calls when processing stats and diffs on commits. + # This should be reduced as we work on reducing Gitaly calls. + # See https://gitlab.com/gitlab-org/gitlab/-/issues/354370 + described_class.new.perform(project.id, update_sequence_id) + + project.repository.create_branch('TEST-2_my-feature-branch') + project.repository.create_branch('TEST-3_my-feature-branch') + project.repository.create_branch('TEST-4_my-feature-branch') + + expect { described_class.new.perform(project.id, update_sequence_id) } + .to change { Gitlab::GitalyClient.get_request_count }.by(13) + end + end end - context 'when the number of merge requests to sync is higher than the limit' do + context 'when the number of items to sync is higher than the limit' do let!(:most_recent_merge_request) { create(:merge_request, :unique_branches, description: 'TEST-323', title: 'TEST-123') } before do - stub_const("#{described_class}::MERGE_REQUEST_LIMIT", 1) + stub_const("#{described_class}::MAX_RECORDS_LIMIT", 1) + + project.repository.create_branch('TEST-321_new-branch') end - it 'syncs only the most recent merge requests within the limit' do + it 'syncs only the most recent merge requests and branches within the limit' do expect(jira_connect_sync_service).to receive(:execute) - .with(merge_requests: [most_recent_merge_request], update_sequence_id: update_sequence_id) + .with( + merge_requests: [most_recent_merge_request], + branches: [have_attributes(name: jira_referencing_branch_name)], + update_sequence_id: update_sequence_id + ) perform(project.id, update_sequence_id) end diff --git a/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb b/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb index 09d58a1189e..e49b4707eb3 100644 --- a/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb +++ b/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe LooseForeignKeys::CleanupWorker do +RSpec.describe LooseForeignKeys::CleanupWorker, feature_category: :cell do include MigrationsHelpers using RSpec::Parameterized::TableSyntax diff --git a/spec/workers/mail_scheduler/issue_due_worker_spec.rb b/spec/workers/mail_scheduler/issue_due_worker_spec.rb index c03cc0bda61..9bdfcd7ca49 100644 --- a/spec/workers/mail_scheduler/issue_due_worker_spec.rb +++ b/spec/workers/mail_scheduler/issue_due_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MailScheduler::IssueDueWorker do +RSpec.describe MailScheduler::IssueDueWorker, feature_category: :team_planning do describe '#perform' do let(:worker) { described_class.new } let(:project) { create(:project) } diff --git a/spec/workers/mail_scheduler/notification_service_worker_spec.rb b/spec/workers/mail_scheduler/notification_service_worker_spec.rb index 482d99a43c2..5ba7a0c555f 100644 --- a/spec/workers/mail_scheduler/notification_service_worker_spec.rb +++ b/spec/workers/mail_scheduler/notification_service_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MailScheduler::NotificationServiceWorker do +RSpec.describe MailScheduler::NotificationServiceWorker, feature_category: :team_planning do let(:worker) { described_class.new } let(:method) { 'new_key' } diff --git a/spec/workers/member_invitation_reminder_emails_worker_spec.rb b/spec/workers/member_invitation_reminder_emails_worker_spec.rb index bb4ff466584..4c6295285ea 100644 --- a/spec/workers/member_invitation_reminder_emails_worker_spec.rb +++ b/spec/workers/member_invitation_reminder_emails_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MemberInvitationReminderEmailsWorker do +RSpec.describe MemberInvitationReminderEmailsWorker, feature_category: :subgroups do describe '#perform' do subject { described_class.new.perform } diff --git a/spec/workers/members_destroyer/unassign_issuables_worker_spec.rb b/spec/workers/members_destroyer/unassign_issuables_worker_spec.rb index 2a325be1225..51fca67ae99 100644 --- a/spec/workers/members_destroyer/unassign_issuables_worker_spec.rb +++ b/spec/workers/members_destroyer/unassign_issuables_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MembersDestroyer::UnassignIssuablesWorker do +RSpec.describe MembersDestroyer::UnassignIssuablesWorker, feature_category: :user_management do let_it_be(:group) { create(:group, :private) } let_it_be(:user, reload: true) { create(:user) } diff --git a/spec/workers/merge_request_cleanup_refs_worker_spec.rb b/spec/workers/merge_request_cleanup_refs_worker_spec.rb index 1de927a81e4..a2df31037be 100644 --- a/spec/workers/merge_request_cleanup_refs_worker_spec.rb +++ b/spec/workers/merge_request_cleanup_refs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequestCleanupRefsWorker do +RSpec.describe MergeRequestCleanupRefsWorker, feature_category: :code_review_workflow do let(:worker) { described_class.new } describe '#perform_work' do @@ -30,12 +30,12 @@ RSpec.describe MergeRequestCleanupRefsWorker do expect(cleanup_schedule.completed_at).to be_nil end - context "and cleanup schedule has already failed #{described_class::FAILURE_THRESHOLD} times" do - let(:failed_count) { described_class::FAILURE_THRESHOLD } + context "and cleanup schedule has already failed #{WebHooks::AutoDisabling::FAILURE_THRESHOLD} times" do + let(:failed_count) { WebHooks::AutoDisabling::FAILURE_THRESHOLD } it 'marks the cleanup schedule as failed and track the failure' do expect(cleanup_schedule.reload).to be_failed - expect(cleanup_schedule.failed_count).to eq(described_class::FAILURE_THRESHOLD + 1) + expect(cleanup_schedule.failed_count).to eq(failed_count + 1) expect(cleanup_schedule.completed_at).to be_nil end end diff --git a/spec/workers/merge_request_mergeability_check_worker_spec.rb b/spec/workers/merge_request_mergeability_check_worker_spec.rb index 32debcf9651..fd959803006 100644 --- a/spec/workers/merge_request_mergeability_check_worker_spec.rb +++ b/spec/workers/merge_request_mergeability_check_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequestMergeabilityCheckWorker do +RSpec.describe MergeRequestMergeabilityCheckWorker, feature_category: :code_review_workflow do subject { described_class.new } describe '#perform' do diff --git a/spec/workers/merge_requests/close_issue_worker_spec.rb b/spec/workers/merge_requests/close_issue_worker_spec.rb index 72fb3be7470..0facd34e790 100644 --- a/spec/workers/merge_requests/close_issue_worker_spec.rb +++ b/spec/workers/merge_requests/close_issue_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::CloseIssueWorker do +RSpec.describe MergeRequests::CloseIssueWorker, feature_category: :code_review_workflow do subject(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/merge_requests/create_approval_event_worker_spec.rb b/spec/workers/merge_requests/create_approval_event_worker_spec.rb index 8389949ecc9..a9a46420fd5 100644 --- a/spec/workers/merge_requests/create_approval_event_worker_spec.rb +++ b/spec/workers/merge_requests/create_approval_event_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::CreateApprovalEventWorker do +RSpec.describe MergeRequests::CreateApprovalEventWorker, feature_category: :code_review_workflow do let!(:user) { create(:user) } let!(:project) { create(:project) } let!(:merge_request) { create(:merge_request, source_project: project) } diff --git a/spec/workers/merge_requests/create_approval_note_worker_spec.rb b/spec/workers/merge_requests/create_approval_note_worker_spec.rb index f58d38599fc..1a9e15c18f0 100644 --- a/spec/workers/merge_requests/create_approval_note_worker_spec.rb +++ b/spec/workers/merge_requests/create_approval_note_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::CreateApprovalNoteWorker do +RSpec.describe MergeRequests::CreateApprovalNoteWorker, feature_category: :code_review_workflow do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:merge_request) { create(:merge_request, source_project: project) } diff --git a/spec/workers/merge_requests/delete_source_branch_worker_spec.rb b/spec/workers/merge_requests/delete_source_branch_worker_spec.rb index e17ad02e272..57f8cfbfb83 100644 --- a/spec/workers/merge_requests/delete_source_branch_worker_spec.rb +++ b/spec/workers/merge_requests/delete_source_branch_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::DeleteSourceBranchWorker do +RSpec.describe MergeRequests::DeleteSourceBranchWorker, feature_category: :source_code_management do let_it_be(:user) { create(:user) } let_it_be(:merge_request) { create(:merge_request, author: user) } @@ -12,8 +12,11 @@ RSpec.describe MergeRequests::DeleteSourceBranchWorker do describe '#perform' do before do allow_next_instance_of(::Projects::DeleteBranchWorker) do |instance| - allow(instance).to receive(:perform).with(merge_request.source_project.id, user.id, - merge_request.source_branch) + allow(instance).to receive(:perform).with( + merge_request.source_project.id, + user.id, + merge_request.source_branch + ) end end @@ -36,8 +39,11 @@ RSpec.describe MergeRequests::DeleteSourceBranchWorker do context 'with existing user and merge request' do it 'calls delete branch worker' do expect_next_instance_of(::Projects::DeleteBranchWorker) do |instance| - expect(instance).to receive(:perform).with(merge_request.source_project.id, user.id, - merge_request.source_branch) + expect(instance).to receive(:perform).with( + merge_request.source_project.id, + user.id, + merge_request.source_branch + ) end worker.perform(merge_request.id, sha, user.id) diff --git a/spec/workers/merge_requests/execute_approval_hooks_worker_spec.rb b/spec/workers/merge_requests/execute_approval_hooks_worker_spec.rb index 0130ef63f50..13c97f8fe49 100644 --- a/spec/workers/merge_requests/execute_approval_hooks_worker_spec.rb +++ b/spec/workers/merge_requests/execute_approval_hooks_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::ExecuteApprovalHooksWorker do +RSpec.describe MergeRequests::ExecuteApprovalHooksWorker, feature_category: :source_code_management do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:merge_request) { create(:merge_request, source_project: project) } diff --git a/spec/workers/merge_requests/handle_assignees_change_worker_spec.rb b/spec/workers/merge_requests/handle_assignees_change_worker_spec.rb index 4b45f3562d6..f776c6408ed 100644 --- a/spec/workers/merge_requests/handle_assignees_change_worker_spec.rb +++ b/spec/workers/merge_requests/handle_assignees_change_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::HandleAssigneesChangeWorker do +RSpec.describe MergeRequests::HandleAssigneesChangeWorker, feature_category: :code_review_workflow do include AfterNextHelpers let_it_be(:merge_request) { create(:merge_request) } diff --git a/spec/workers/merge_requests/resolve_todos_after_approval_worker_spec.rb b/spec/workers/merge_requests/resolve_todos_after_approval_worker_spec.rb index f8316a8ff05..39443d48ff6 100644 --- a/spec/workers/merge_requests/resolve_todos_after_approval_worker_spec.rb +++ b/spec/workers/merge_requests/resolve_todos_after_approval_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::ResolveTodosAfterApprovalWorker do +RSpec.describe MergeRequests::ResolveTodosAfterApprovalWorker, feature_category: :code_review_workflow do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:merge_request) { create(:merge_request, source_project: project) } diff --git a/spec/workers/merge_requests/resolve_todos_worker_spec.rb b/spec/workers/merge_requests/resolve_todos_worker_spec.rb index 223b8b6803c..1164a1c1ddd 100644 --- a/spec/workers/merge_requests/resolve_todos_worker_spec.rb +++ b/spec/workers/merge_requests/resolve_todos_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::ResolveTodosWorker do +RSpec.describe MergeRequests::ResolveTodosWorker, feature_category: :code_review_workflow do include AfterNextHelpers let_it_be(:merge_request) { create(:merge_request) } diff --git a/spec/workers/merge_requests/set_reviewer_reviewed_worker_spec.rb b/spec/workers/merge_requests/set_reviewer_reviewed_worker_spec.rb new file mode 100644 index 00000000000..942cf8e87e9 --- /dev/null +++ b/spec/workers/merge_requests/set_reviewer_reviewed_worker_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MergeRequests::SetReviewerReviewedWorker, feature_category: :source_code_management do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:merge_request) { create(:merge_request, source_project: project) } + + let(:data) { { current_user_id: user.id, merge_request_id: merge_request.id } } + let(:approved_event) { MergeRequests::ApprovedEvent.new(data: data) } + + it_behaves_like 'subscribes to event' do + let(:event) { approved_event } + end + + it 'calls MergeRequests::MarkReviewerReviewedService' do + expect_next_instance_of( + MergeRequests::MarkReviewerReviewedService, + project: project, current_user: user + ) do |service| + expect(service).to receive(:execute).with(merge_request) + end + + consume_event(subscriber: described_class, event: approved_event) + end + + shared_examples 'when object does not exist' do + it 'logs and does not call MergeRequests::MarkReviewerReviewedService' do + expect(Sidekiq.logger).to receive(:info).with(hash_including(log_payload)) + expect(MergeRequests::MarkReviewerReviewedService).not_to receive(:new) + + expect { consume_event(subscriber: described_class, event: approved_event) } + .not_to raise_exception + end + end + + context 'when the user does not exist' do + before do + user.destroy! + end + + it_behaves_like 'when object does not exist' do + let(:log_payload) { { 'message' => 'Current user not found.', 'current_user_id' => user.id } } + end + end + + context 'when the merge request does not exist' do + before do + merge_request.destroy! + end + + it_behaves_like 'when object does not exist' do + let(:log_payload) { { 'message' => 'Merge request not found.', 'merge_request_id' => merge_request.id } } + end + end +end diff --git a/spec/workers/merge_requests/update_head_pipeline_worker_spec.rb b/spec/workers/merge_requests/update_head_pipeline_worker_spec.rb index 3574b8296a4..b65bd4eb1db 100644 --- a/spec/workers/merge_requests/update_head_pipeline_worker_spec.rb +++ b/spec/workers/merge_requests/update_head_pipeline_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeRequests::UpdateHeadPipelineWorker do +RSpec.describe MergeRequests::UpdateHeadPipelineWorker, feature_category: :code_review_workflow do include ProjectForksHelper let_it_be(:project) { create(:project, :repository) } @@ -74,9 +74,12 @@ RSpec.describe MergeRequests::UpdateHeadPipelineWorker do context 'when there is no pipeline for source branch' do it "does not update merge request head pipeline" do - merge_request = create(:merge_request, source_branch: 'feature', - target_branch: "branch_1", - source_project: project) + merge_request = create( + :merge_request, + source_branch: 'feature', + target_branch: "branch_1", + source_project: project + ) subject @@ -96,10 +99,13 @@ RSpec.describe MergeRequests::UpdateHeadPipelineWorker do end it 'updates head pipeline for merge request' do - merge_request = create(:merge_request, source_branch: 'feature', - target_branch: "master", - source_project: project, - target_project: target_project) + merge_request = create( + :merge_request, + source_branch: 'feature', + target_branch: "master", + source_project: project, + target_project: target_project + ) subject @@ -109,9 +115,12 @@ RSpec.describe MergeRequests::UpdateHeadPipelineWorker do context 'when the pipeline is not the latest for the branch' do it 'does not update merge request head pipeline' do - merge_request = create(:merge_request, source_branch: 'master', - target_branch: "branch_1", - source_project: project) + merge_request = create( + :merge_request, + source_branch: 'master', + target_branch: "branch_1", + source_project: project + ) create(:ci_pipeline, project: pipeline.project, ref: pipeline.ref) @@ -127,9 +136,12 @@ RSpec.describe MergeRequests::UpdateHeadPipelineWorker do end it 'updates merge request head pipeline reference' do - merge_request = create(:merge_request, source_branch: 'master', - target_branch: 'feature', - source_project: project) + merge_request = create( + :merge_request, + source_branch: 'master', + target_branch: 'feature', + source_project: project + ) subject diff --git a/spec/workers/merge_worker_spec.rb b/spec/workers/merge_worker_spec.rb index 0268bc2388f..9c6a6564df6 100644 --- a/spec/workers/merge_worker_spec.rb +++ b/spec/workers/merge_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MergeWorker do +RSpec.describe MergeWorker, feature_category: :source_code_management do describe "remove source branch" do let!(:merge_request) { create(:merge_request, source_branch: "markdown") } let!(:source_project) { merge_request.source_project } diff --git a/spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb b/spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb index 491ea64cff1..c7e2bbc2ad9 100644 --- a/spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb +++ b/spec/workers/metrics/dashboard/prune_old_annotations_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Metrics::Dashboard::PruneOldAnnotationsWorker do +RSpec.describe Metrics::Dashboard::PruneOldAnnotationsWorker, feature_category: :metrics do let_it_be(:now) { DateTime.parse('2020-06-02T00:12:00Z') } let_it_be(:two_weeks_old_annotation) { create(:metrics_dashboard_annotation, starting_at: now.advance(weeks: -2)) } let_it_be(:one_day_old_annotation) { create(:metrics_dashboard_annotation, starting_at: now.advance(days: -1)) } diff --git a/spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb b/spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb index e0a5a8fd448..75866a4eca2 100644 --- a/spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb +++ b/spec/workers/metrics/dashboard/schedule_annotations_prune_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Metrics::Dashboard::ScheduleAnnotationsPruneWorker do +RSpec.describe Metrics::Dashboard::ScheduleAnnotationsPruneWorker, feature_category: :metrics do describe '#perform' do it 'schedules annotations prune job with default cut off date' do expect(Metrics::Dashboard::PruneOldAnnotationsWorker).to receive(:perform_async) diff --git a/spec/workers/metrics/dashboard/sync_dashboards_worker_spec.rb b/spec/workers/metrics/dashboard/sync_dashboards_worker_spec.rb index 4b670a753e7..f7d67b2064e 100644 --- a/spec/workers/metrics/dashboard/sync_dashboards_worker_spec.rb +++ b/spec/workers/metrics/dashboard/sync_dashboards_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Metrics::Dashboard::SyncDashboardsWorker do +RSpec.describe Metrics::Dashboard::SyncDashboardsWorker, feature_category: :metrics do include MetricsDashboardHelpers subject(:worker) { described_class.new } diff --git a/spec/workers/metrics/global_metrics_update_worker_spec.rb b/spec/workers/metrics/global_metrics_update_worker_spec.rb new file mode 100644 index 00000000000..d5bfbcc928a --- /dev/null +++ b/spec/workers/metrics/global_metrics_update_worker_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Metrics::GlobalMetricsUpdateWorker, feature_category: :metrics do + subject { described_class.new } + + describe '#perform' do + let(:service) { ::Metrics::GlobalMetricsUpdateService.new } + + it 'delegates to ::Metrics::GlobalMetricsUpdateService' do + expect(::Metrics::GlobalMetricsUpdateService).to receive(:new).and_return(service) + expect(service).to receive(:execute) + + subject.perform + end + + context 'for an idempotent worker' do + include_examples 'an idempotent worker' do + it 'exports metrics' do + allow(Gitlab).to receive(:maintenance_mode?).and_return(true).at_least(1).time + + perform_multiple + + expect(service.maintenance_mode_metric.get).to eq(1) + end + end + end + end +end diff --git a/spec/workers/migrate_external_diffs_worker_spec.rb b/spec/workers/migrate_external_diffs_worker_spec.rb index 36669b4e694..cb5e3ff3651 100644 --- a/spec/workers/migrate_external_diffs_worker_spec.rb +++ b/spec/workers/migrate_external_diffs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe MigrateExternalDiffsWorker do +RSpec.describe MigrateExternalDiffsWorker, feature_category: :code_review_workflow do let(:worker) { described_class.new } let(:diff) { create(:merge_request).merge_request_diff } diff --git a/spec/workers/ml/experiment_tracking/associate_ml_candidate_to_package_worker_spec.rb b/spec/workers/ml/experiment_tracking/associate_ml_candidate_to_package_worker_spec.rb new file mode 100644 index 00000000000..5e1742b3298 --- /dev/null +++ b/spec/workers/ml/experiment_tracking/associate_ml_candidate_to_package_worker_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ml::ExperimentTracking::AssociateMlCandidateToPackageWorker, feature_category: :mlops do + describe '.handle_event' do + let_it_be(:candidate) { create(:ml_candidates) } + let_it_be(:package) do + create( + :generic_package, + project: candidate.project, + name: candidate.package_name, + version: candidate.package_version + ) + end + + let(:package_version) { package.version } + let(:project_id) { package.project_id } + let(:data) do + { + project_id: project_id, + id: package.id, + name: package.name, + version: package_version, + package_type: package.package_type + } + end + + let(:package_created_event) { Packages::PackageCreatedEvent.new(data: data) } + + it_behaves_like 'subscribes to event' do + let(:event) { package_created_event } + end + + context 'when package name matches ml_experiment_{id}' do + before do + consume_event(subscriber: described_class, event: package_created_event) + end + + context 'when candidate with iid exists' do + it 'associates candidate to package' do + expect(candidate.reload.package).to eq(package) + end + end + + context 'when no candidate with iid exists' do + let(:package_version) { non_existing_record_iid.to_s } + + it 'does not associate candidate' do + expect(candidate.reload.package).to be_nil + end + end + + context 'when candidate with iid exists but in a different project' do + let(:project_id) { non_existing_record_id } + + it 'does not associate candidate' do + expect(candidate.reload.package).to be_nil + end + end + end + + context 'when package is deleted before event is called' do + before do + package.delete + end + + it 'does not associate candidate' do + consume_event(subscriber: described_class, event: package_created_event) + + expect(candidate.reload.package_id).to be_nil + end + end + end + + describe '#handles_event?' do + using RSpec::Parameterized::TableSyntax + + let(:event) do + Packages::PackageCreatedEvent.new( + data: { + project_id: 1, + id: 1, + name: package_name, + version: '', + package_type: package_type + } + ) + end + + subject { described_class.handles_event?(event) } + + where(:package_name, :package_type, :handles_event) do + 'ml_experiment_1234' | 'generic' | true + 'ml_experiment_1234' | 'maven' | false + '1234' | 'generic' | false + 'ml_experiment_' | 'generic' | false + 'blah' | 'generic' | false + end + + with_them do + it { is_expected.to eq(handles_event) } + end + end +end diff --git a/spec/workers/namespaces/in_product_marketing_emails_worker_spec.rb b/spec/workers/namespaces/in_product_marketing_emails_worker_spec.rb index 2e7b6356692..237b5081bb1 100644 --- a/spec/workers/namespaces/in_product_marketing_emails_worker_spec.rb +++ b/spec/workers/namespaces/in_product_marketing_emails_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform', unless: Gitlab.ee? do +RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform', unless: Gitlab.ee?, feature_category: :experimentation_activation do # Running this in EE would call the overridden method, which can't be tested in CE. # The EE code is covered in a separate EE spec. diff --git a/spec/workers/namespaces/process_sync_events_worker_spec.rb b/spec/workers/namespaces/process_sync_events_worker_spec.rb index 9f389089609..a5afb5d5cbf 100644 --- a/spec/workers/namespaces/process_sync_events_worker_spec.rb +++ b/spec/workers/namespaces/process_sync_events_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Namespaces::ProcessSyncEventsWorker do +RSpec.describe Namespaces::ProcessSyncEventsWorker, feature_category: :cell do let!(:group1) { create(:group) } let!(:group2) { create(:group) } let!(:group3) { create(:group) } @@ -20,8 +20,8 @@ RSpec.describe Namespaces::ProcessSyncEventsWorker 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 }) + it 'has the option to reschedule once if deduplicated and a TTL of 1 minute' do + expect(described_class.get_deduplication_options).to include({ if_deduplicated: :reschedule_once, ttl: 1.minute }) end it 'expect the job to enqueue itself again if there was more items to be processed', :sidekiq_inline do diff --git a/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb b/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb index d8c60932d92..9f0ea366726 100644 --- a/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb +++ b/spec/workers/namespaces/prune_aggregation_schedules_worker_spec.rb @@ -2,11 +2,10 @@ require 'spec_helper' -RSpec.describe Namespaces::PruneAggregationSchedulesWorker, '#perform', :clean_gitlab_redis_shared_state do +RSpec.describe Namespaces::PruneAggregationSchedulesWorker, '#perform', :clean_gitlab_redis_shared_state, feature_category: :source_code_management do include ExclusiveLeaseHelpers let(:namespaces) { create_list(:namespace, 5, :with_aggregation_schedule) } - let(:timeout) { Namespace::AggregationSchedule.default_lease_timeout } subject(:worker) { described_class.new } @@ -19,7 +18,7 @@ RSpec.describe Namespaces::PruneAggregationSchedulesWorker, '#perform', :clean_g namespaces.each do |namespace| lease_key = "namespace:namespaces_root_statistics:#{namespace.id}" - stub_exclusive_lease(lease_key, timeout: timeout) + stub_exclusive_lease(lease_key, timeout: namespace.aggregation_schedule.default_lease_timeout) end end diff --git a/spec/workers/namespaces/root_statistics_worker_spec.rb b/spec/workers/namespaces/root_statistics_worker_spec.rb index e047c94816f..2224d94cd9d 100644 --- a/spec/workers/namespaces/root_statistics_worker_spec.rb +++ b/spec/workers/namespaces/root_statistics_worker_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' -RSpec.describe Namespaces::RootStatisticsWorker, '#perform' do - let(:group) { create(:group, :with_aggregation_schedule) } +RSpec.describe Namespaces::RootStatisticsWorker, '#perform', feature_category: :source_code_management do + let_it_be(:group) { create(:group, :with_aggregation_schedule) } subject(:worker) { described_class.new } @@ -79,10 +79,6 @@ RSpec.describe Namespaces::RootStatisticsWorker, '#perform' do let(:job_args) { [group.id] } it 'deletes one aggregation schedule' do - # Make sure the group and it's aggregation schedule are created before - # counting - group - expect { worker.perform(*job_args) } .to change { Namespace::AggregationSchedule.count }.by(-1) expect { worker.perform(*job_args) } @@ -90,9 +86,7 @@ RSpec.describe Namespaces::RootStatisticsWorker, '#perform' do end end - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :sticky + it_behaves_like 'worker with data consistency', described_class, data_consistency: :sticky it 'has the `until_executed` deduplicate strategy' do expect(described_class.get_deduplicate_strategy).to eq(:until_executed) diff --git a/spec/workers/namespaces/schedule_aggregation_worker_spec.rb b/spec/workers/namespaces/schedule_aggregation_worker_spec.rb index 62f9be501cc..7d0746a4bb0 100644 --- a/spec/workers/namespaces/schedule_aggregation_worker_spec.rb +++ b/spec/workers/namespaces/schedule_aggregation_worker_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' -RSpec.describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_shared_state do - let(:group) { create(:group) } +RSpec.describe Namespaces::ScheduleAggregationWorker, '#perform', :clean_gitlab_redis_shared_state, feature_category: :source_code_management do + let_it_be(:group) { create(:group) } subject(:worker) { described_class.new } diff --git a/spec/workers/namespaces/update_root_statistics_worker_spec.rb b/spec/workers/namespaces/update_root_statistics_worker_spec.rb index f2f633a39ca..85fd68094ce 100644 --- a/spec/workers/namespaces/update_root_statistics_worker_spec.rb +++ b/spec/workers/namespaces/update_root_statistics_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Namespaces::UpdateRootStatisticsWorker do +RSpec.describe Namespaces::UpdateRootStatisticsWorker, feature_category: :source_code_management do let(:namespace_id) { 123 } let(:event) do diff --git a/spec/workers/new_issue_worker_spec.rb b/spec/workers/new_issue_worker_spec.rb index b9053b10419..540296374ef 100644 --- a/spec/workers/new_issue_worker_spec.rb +++ b/spec/workers/new_issue_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe NewIssueWorker do +RSpec.describe NewIssueWorker, feature_category: :team_planning do include AfterNextHelpers describe '#perform' do diff --git a/spec/workers/new_merge_request_worker_spec.rb b/spec/workers/new_merge_request_worker_spec.rb index a8e1c3f4bf1..58f6792f9a0 100644 --- a/spec/workers/new_merge_request_worker_spec.rb +++ b/spec/workers/new_merge_request_worker_spec.rb @@ -107,18 +107,6 @@ RSpec.describe NewMergeRequestWorker, feature_category: :code_review_workflow do stub_feature_flags(add_prepared_state_to_mr: true) end - context 'when the merge request is prepared' do - before do - merge_request.update!(prepared_at: Time.current) - end - - it 'does not call the create service' do - expect(MergeRequests::AfterCreateService).not_to receive(:new) - - worker.perform(merge_request.id, user.id) - end - end - context 'when the merge request is not prepared' do it 'calls the create service' do expect_next_instance_of(MergeRequests::AfterCreateService, project: merge_request.target_project, current_user: user) do |service| diff --git a/spec/workers/new_note_worker_spec.rb b/spec/workers/new_note_worker_spec.rb index 7ba3fe94254..651b5742854 100644 --- a/spec/workers/new_note_worker_spec.rb +++ b/spec/workers/new_note_worker_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe NewNoteWorker do +RSpec.describe NewNoteWorker, feature_category: :team_planning do context 'when Note found' do let(:note) { create(:note) } diff --git a/spec/workers/object_pool/create_worker_spec.rb b/spec/workers/object_pool/create_worker_spec.rb index 4ec409bdf47..573cb3413f5 100644 --- a/spec/workers/object_pool/create_worker_spec.rb +++ b/spec/workers/object_pool/create_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ObjectPool::CreateWorker do +RSpec.describe ObjectPool::CreateWorker, feature_category: :shared do let(:pool) { create(:pool_repository, :scheduled) } subject { described_class.new } diff --git a/spec/workers/object_pool/destroy_worker_spec.rb b/spec/workers/object_pool/destroy_worker_spec.rb index 130a666a42e..7db3404ed36 100644 --- a/spec/workers/object_pool/destroy_worker_spec.rb +++ b/spec/workers/object_pool/destroy_worker_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe ObjectPool::DestroyWorker do +RSpec.describe ObjectPool::DestroyWorker, feature_category: :shared do describe '#perform' do context 'when no pool is in the database' do it "doesn't raise an error" do @@ -16,9 +16,13 @@ RSpec.describe ObjectPool::DestroyWorker do subject { described_class.new } it 'requests Gitaly to remove the object pool' do - expect(Gitlab::GitalyClient).to receive(:call) - .with(pool.shard_name, :object_pool_service, :delete_object_pool, - Object, timeout: Gitlab::GitalyClient.long_timeout) + expect(Gitlab::GitalyClient).to receive(:call).with( + pool.shard_name, + :object_pool_service, + :delete_object_pool, + Object, + timeout: Gitlab::GitalyClient.long_timeout + ) subject.perform(pool.id) end diff --git a/spec/workers/object_pool/join_worker_spec.rb b/spec/workers/object_pool/join_worker_spec.rb index 335c45e14e0..e0173cad53b 100644 --- a/spec/workers/object_pool/join_worker_spec.rb +++ b/spec/workers/object_pool/join_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ObjectPool::JoinWorker do +RSpec.describe ObjectPool::JoinWorker, feature_category: :shared do let(:pool) { create(:pool_repository, :ready) } let(:project) { pool.source_project } let(:repository) { project.repository } diff --git a/spec/workers/onboarding/issue_created_worker_spec.rb b/spec/workers/onboarding/issue_created_worker_spec.rb index 70a0156d444..d12f51ceff6 100644 --- a/spec/workers/onboarding/issue_created_worker_spec.rb +++ b/spec/workers/onboarding/issue_created_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Onboarding::IssueCreatedWorker, '#perform' do +RSpec.describe Onboarding::IssueCreatedWorker, '#perform', feature_category: :onboarding do let_it_be(:issue) { create(:issue) } let(:namespace) { issue.project.namespace } diff --git a/spec/workers/onboarding/pipeline_created_worker_spec.rb b/spec/workers/onboarding/pipeline_created_worker_spec.rb index 75bdea28eef..e6dc0f9b689 100644 --- a/spec/workers/onboarding/pipeline_created_worker_spec.rb +++ b/spec/workers/onboarding/pipeline_created_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Onboarding::PipelineCreatedWorker, '#perform' do +RSpec.describe Onboarding::PipelineCreatedWorker, '#perform', feature_category: :onboarding do let_it_be(:ci_pipeline) { create(:ci_pipeline) } it_behaves_like 'records an onboarding progress action', :pipeline_created do diff --git a/spec/workers/onboarding/progress_worker_spec.rb b/spec/workers/onboarding/progress_worker_spec.rb index bbf4875069e..da760c23367 100644 --- a/spec/workers/onboarding/progress_worker_spec.rb +++ b/spec/workers/onboarding/progress_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Onboarding::ProgressWorker, '#perform' do +RSpec.describe Onboarding::ProgressWorker, '#perform', feature_category: :onboarding do let_it_be(:namespace) { create(:namespace) } let_it_be(:action) { 'git_pull' } diff --git a/spec/workers/onboarding/user_added_worker_spec.rb b/spec/workers/onboarding/user_added_worker_spec.rb index 6dbd875c93b..d32bd5ee19c 100644 --- a/spec/workers/onboarding/user_added_worker_spec.rb +++ b/spec/workers/onboarding/user_added_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Onboarding::UserAddedWorker, '#perform' do +RSpec.describe Onboarding::UserAddedWorker, '#perform', feature_category: :onboarding do let_it_be(:namespace) { create(:group) } subject { described_class.new.perform(namespace.id) } diff --git a/spec/workers/packages/cleanup/delete_orphaned_dependencies_worker_spec.rb b/spec/workers/packages/cleanup/delete_orphaned_dependencies_worker_spec.rb new file mode 100644 index 00000000000..ffa7767075e --- /dev/null +++ b/spec/workers/packages/cleanup/delete_orphaned_dependencies_worker_spec.rb @@ -0,0 +1,118 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Cleanup::DeleteOrphanedDependenciesWorker, feature_category: :package_registry do + let(:worker) { described_class.new } + + it { is_expected.to include_module(CronjobQueue) } + it { expect(described_class.idempotent?).to be_truthy } + + describe '#perform', :clean_gitlab_redis_shared_state do + let_it_be(:orphaned_dependencies) { create_list(:packages_dependency, 2) } + let_it_be(:linked_dependency) do + create(:packages_dependency).tap do |dependency| + create(:packages_dependency_link, dependency: dependency) + end + end + + subject { worker.perform } + + it 'deletes only orphaned dependencies' do + expect { subject }.to change { Packages::Dependency.count }.by(-2) + expect(Packages::Dependency.all).to contain_exactly(linked_dependency) + end + + it 'executes 3 queries' do + queries = ActiveRecord::QueryRecorder.new { subject } + + # 1. (each_batch lower bound) SELECT packages_dependencies.id FROM packages_dependencies + # WHERE packages_dependencies.id >= 0 + # ORDER BY packages_dependencies.id ASC LIMIT 1; + # 2. (each_batch upper bound) SELECT packages_dependencies.id FROM packages_dependencies + # WHERE packages_dependencies.id >= 0 + # AND packages_dependencies.id >= 1 ORDER BY packages_dependencies.id ASC + # LIMIT 1 OFFSET 100; + # 3. (delete query) DELETE FROM packages_dependencies WHERE packages_dependencies.id >= 0 + # AND packages_dependencies.id >= 1 + # AND (NOT EXISTS ( + # SELECT 1 FROM packages_dependency_links + # WHERE packages_dependency_links.dependency_id = packages_dependencies.id + # )); + expect(queries.count).to eq(3) + end + + context 'when the worker is running for more than the max time' do + before do + allow(worker).to receive(:over_time?).and_return(true) + end + + it 'sets the last processed dependency id in redis cache' do + subject + + Gitlab::Redis::SharedState.with do |redis| + expect(redis.get('last_processed_packages_dependency_id').to_i).to eq(Packages::Dependency.last.id) + end + end + end + + context 'when the worker reaches the maximum number of batches' do + before do + stub_const('Packages::Cleanup::DeleteOrphanedDependenciesWorker::MAX_BATCHES', 1) + end + + it 'iterates over only 1 batch' do + expect { subject }.to change { Packages::Dependency.count }.by(-2) + end + + it 'sets the last processed dependency id in redis cache' do + subject + + Gitlab::Redis::SharedState.with do |redis| + expect(redis.get('last_processed_packages_dependency_id').to_i).to eq(Packages::Dependency.last.id) + end + end + end + + context 'when the worker finishes processing in less than the max time' do + before do + Gitlab::Redis::SharedState.with do |redis| + redis.set('last_processed_packages_dependency_id', orphaned_dependencies.first.id) + end + end + + it 'clears the last processed last_processed_packages_dependency_id from redis cache' do + Gitlab::Redis::SharedState.with do |redis| + expect { subject } + .to change { redis.get('last_processed_packages_dependency_id') }.to(nil) + end + end + end + + context 'when logging extra metadata' do + before do + stub_const('Packages::Cleanup::DeleteOrphanedDependenciesWorker::MAX_BATCHES', 1) + end + + it 'logs the last proccessed id & the deleted rows count', :aggregate_failures do + expect(worker).to receive(:log_extra_metadata_on_done).with( + :last_processed_packages_dependency_id, + Packages::Dependency.last.id + ) + expect(worker).to receive(:log_extra_metadata_on_done).with(:deleted_rows_count, 2) + + subject + end + end + + context 'when the FF is disabled' do + before do + stub_feature_flags(packages_delete_orphaned_dependencies_worker: false) + end + + it 'does not execute the worker' do + expect { subject }.not_to change { Packages::Dependency.count } + end + end + end +end diff --git a/spec/workers/packages/cleanup/execute_policy_worker_spec.rb b/spec/workers/packages/cleanup/execute_policy_worker_spec.rb index 6325a82ed3d..fc3ed1f3a05 100644 --- a/spec/workers/packages/cleanup/execute_policy_worker_spec.rb +++ b/spec/workers/packages/cleanup/execute_policy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::Cleanup::ExecutePolicyWorker do +RSpec.describe Packages::Cleanup::ExecutePolicyWorker, feature_category: :package_registry do let(:worker) { described_class.new } describe '#perform_work' do diff --git a/spec/workers/packages/cleanup_package_file_worker_spec.rb b/spec/workers/packages/cleanup_package_file_worker_spec.rb index 95cf65c18c5..6e42565abbc 100644 --- a/spec/workers/packages/cleanup_package_file_worker_spec.rb +++ b/spec/workers/packages/cleanup_package_file_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::CleanupPackageFileWorker do +RSpec.describe Packages::CleanupPackageFileWorker, feature_category: :package_registry do let_it_be_with_reload(:package) { create(:package) } let(:worker) { described_class.new } diff --git a/spec/workers/packages/cleanup_package_registry_worker_spec.rb b/spec/workers/packages/cleanup_package_registry_worker_spec.rb index e12f2198f66..f70103070ef 100644 --- a/spec/workers/packages/cleanup_package_registry_worker_spec.rb +++ b/spec/workers/packages/cleanup_package_registry_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::CleanupPackageRegistryWorker do +RSpec.describe Packages::CleanupPackageRegistryWorker, feature_category: :package_registry 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) } diff --git a/spec/workers/packages/composer/cache_cleanup_worker_spec.rb b/spec/workers/packages/composer/cache_cleanup_worker_spec.rb index 39eac4e4ae1..67d4ce36437 100644 --- a/spec/workers/packages/composer/cache_cleanup_worker_spec.rb +++ b/spec/workers/packages/composer/cache_cleanup_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::Composer::CacheCleanupWorker, type: :worker do +RSpec.describe Packages::Composer::CacheCleanupWorker, type: :worker, feature_category: :package_registry do describe '#perform' do let_it_be(:group) { create(:group) } diff --git a/spec/workers/packages/composer/cache_update_worker_spec.rb b/spec/workers/packages/composer/cache_update_worker_spec.rb index 6c17d49e986..cc3047895d4 100644 --- a/spec/workers/packages/composer/cache_update_worker_spec.rb +++ b/spec/workers/packages/composer/cache_update_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::Composer::CacheUpdateWorker, type: :worker do +RSpec.describe Packages::Composer::CacheUpdateWorker, type: :worker, feature_category: :package_registry do describe '#perform' do let_it_be(:package_name) { 'sample-project' } let_it_be(:json) { { 'name' => package_name } } diff --git a/spec/workers/packages/debian/cleanup_dangling_package_files_worker_spec.rb b/spec/workers/packages/debian/cleanup_dangling_package_files_worker_spec.rb new file mode 100644 index 00000000000..b6373dbda95 --- /dev/null +++ b/spec/workers/packages/debian/cleanup_dangling_package_files_worker_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Debian::CleanupDanglingPackageFilesWorker, type: :worker, + feature_category: :package_registry do + describe '#perform' do + let_it_be_with_reload(:distribution) { create(:debian_project_distribution, :with_file, codename: 'unstable') } + let_it_be(:incoming) { create(:debian_incoming, project: distribution.project) } + let_it_be(:package) { create(:debian_package, project: distribution.project) } + + subject { described_class.new.perform } + + context 'when debian_packages flag is disabled' do + before do + stub_feature_flags(debian_packages: false) + end + + it 'does nothing' do + expect(::Packages::MarkPackageFilesForDestructionService).not_to receive(:new) + + subject + end + end + + context 'with mocked service returning success' do + it 'calls MarkPackageFilesForDestructionService' do + expect(Gitlab::ErrorTracking).not_to receive(:log_exception) + expect_next_instance_of(::Packages::MarkPackageFilesForDestructionService) do |service| + expect(service).to receive(:execute) + .with(batch_deadline: an_instance_of(ActiveSupport::TimeWithZone)) + .and_return(ServiceResponse.success) + end + + subject + end + end + + context 'with mocked service returning error' do + it 'ignore error' do + expect(Gitlab::ErrorTracking).not_to receive(:log_exception) + expect_next_instance_of(::Packages::MarkPackageFilesForDestructionService) do |service| + expect(service).to receive(:execute) + .with(batch_deadline: an_instance_of(ActiveSupport::TimeWithZone)) + .and_return(ServiceResponse.error(message: 'Custom error')) + end + + subject + end + end + + context 'when the service raises an error' do + it 'logs exception' do + expect(Gitlab::ErrorTracking).to receive(:log_exception).with( + instance_of(ArgumentError) + ) + expect_next_instance_of(::Packages::MarkPackageFilesForDestructionService) do |service| + expect(service).to receive(:execute) + .and_raise(ArgumentError, 'foobar') + end + + subject + end + end + + context 'with valid parameters' do + it_behaves_like 'an idempotent worker' do + before do + incoming.package_files.first.debian_file_metadatum.update! updated_at: 1.day.ago + incoming.package_files.second.update! updated_at: 1.day.ago, status: :error + end + + it 'mark dangling package files as pending destruction', :aggregate_failures do + expect(Gitlab::ErrorTracking).not_to receive(:log_exception) + + # Using subject inside this block will process the job multiple times + expect { subject } + .to not_change { distribution.project.package_files.count } + .and change { distribution.project.package_files.pending_destruction.count }.from(0).to(1) + .and not_change { distribution.project.packages.count } + end + end + end + end +end diff --git a/spec/workers/packages/debian/generate_distribution_worker_spec.rb b/spec/workers/packages/debian/generate_distribution_worker_spec.rb index c4e974ec8eb..acdfcc5275f 100644 --- a/spec/workers/packages/debian/generate_distribution_worker_spec.rb +++ b/spec/workers/packages/debian/generate_distribution_worker_spec.rb @@ -4,13 +4,13 @@ require 'spec_helper' RSpec.describe Packages::Debian::GenerateDistributionWorker, type: :worker, feature_category: :package_registry do describe '#perform' do - let(:container_type) { distribution.container_type } + let(:container_type_as_string) { container_type.to_s } let(:distribution_id) { distribution.id } - subject { described_class.new.perform(container_type, distribution_id) } + subject { described_class.new.perform(container_type_as_string, distribution_id) } - let(:subject2) { described_class.new.perform(container_type, distribution_id) } - let(:subject3) { described_class.new.perform(container_type, distribution_id) } + let(:subject2) { described_class.new.perform(container_type_as_string, distribution_id) } + let(:subject3) { described_class.new.perform(container_type_as_string, distribution_id) } include_context 'with published Debian package' @@ -54,7 +54,7 @@ RSpec.describe Packages::Debian::GenerateDistributionWorker, type: :worker, feat context 'with valid parameters' do it_behaves_like 'an idempotent worker' do - let(:job_args) { [container_type, distribution_id] } + let(:job_args) { [container_type_as_string, distribution_id] } it_behaves_like 'Generate Debian Distribution and component files' end diff --git a/spec/workers/packages/debian/process_changes_worker_spec.rb b/spec/workers/packages/debian/process_changes_worker_spec.rb index b96b75e93b9..ddd608e768c 100644 --- a/spec/workers/packages/debian/process_changes_worker_spec.rb +++ b/spec/workers/packages/debian/process_changes_worker_spec.rb @@ -88,7 +88,7 @@ RSpec.describe Packages::Debian::ProcessChangesWorker, type: :worker, feature_ca expect { subject } .to not_change { Packages::Package.count } .and change { Packages::PackageFile.count }.by(-1) - .and change { incoming.package_files.count }.from(7).to(6) + .and change { incoming.package_files.count }.from(8).to(7) end end @@ -104,7 +104,7 @@ RSpec.describe Packages::Debian::ProcessChangesWorker, type: :worker, feature_ca expect { subject } .to not_change { Packages::Package.count } .and change { Packages::PackageFile.count }.by(-1) - .and change { incoming.package_files.count }.from(7).to(6) + .and change { incoming.package_files.count }.from(8).to(7) expect { package_file.reload }.to raise_error(ActiveRecord::RecordNotFound) end @@ -120,7 +120,7 @@ RSpec.describe Packages::Debian::ProcessChangesWorker, type: :worker, feature_ca expect { subject } .to change { Packages::Package.count }.from(1).to(2) .and not_change { Packages::PackageFile.count } - .and change { incoming.package_files.count }.from(7).to(0) + .and change { incoming.package_files.count }.from(8).to(0) .and change { package_file&.debian_file_metadatum&.reload&.file_type }.from('unknown').to('changes') created_package = Packages::Package.last diff --git a/spec/workers/packages/debian/process_package_file_worker_spec.rb b/spec/workers/packages/debian/process_package_file_worker_spec.rb index 239ee8e1035..6010f4eac27 100644 --- a/spec/workers/packages/debian/process_package_file_worker_spec.rb +++ b/spec/workers/packages/debian/process_package_file_worker_spec.rb @@ -31,6 +31,7 @@ RSpec.describe Packages::Debian::ProcessPackageFileWorker, type: :worker, featur where(:case_name, :expected_file_type, :file_name, :component_name) do 'with a deb' | 'deb' | 'libsample0_1.2.3~alpha2_amd64.deb' | 'main' 'with an udeb' | 'udeb' | 'sample-udeb_1.2.3~alpha2_amd64.udeb' | 'contrib' + 'with a ddeb' | 'ddeb' | 'sample-ddeb_1.2.3~alpha2_amd64.ddeb' | 'main' end with_them do @@ -63,6 +64,7 @@ RSpec.describe Packages::Debian::ProcessPackageFileWorker, type: :worker, featur .to not_change(Packages::Package, :count) .and not_change { Packages::PackageFile.count } .and not_change { package.package_files.count } + .and change { package_file.reload.status }.to('error') .and change { package.reload.status }.from('processing').to('error') end end diff --git a/spec/workers/packages/go/sync_packages_worker_spec.rb b/spec/workers/packages/go/sync_packages_worker_spec.rb index 5eeef1f7c08..5fdb7a242f6 100644 --- a/spec/workers/packages/go/sync_packages_worker_spec.rb +++ b/spec/workers/packages/go/sync_packages_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::Go::SyncPackagesWorker, type: :worker do +RSpec.describe Packages::Go::SyncPackagesWorker, type: :worker, feature_category: :package_registry do include_context 'basic Go module' before do diff --git a/spec/workers/packages/helm/extraction_worker_spec.rb b/spec/workers/packages/helm/extraction_worker_spec.rb index 70a090d6989..a764c2ad939 100644 --- a/spec/workers/packages/helm/extraction_worker_spec.rb +++ b/spec/workers/packages/helm/extraction_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::Helm::ExtractionWorker, type: :worker do +RSpec.describe Packages::Helm::ExtractionWorker, type: :worker, feature_category: :package_registry do describe '#perform' do let_it_be(:package) { create(:helm_package, without_package_files: true, status: 'processing') } diff --git a/spec/workers/packages/mark_package_files_for_destruction_worker_spec.rb b/spec/workers/packages/mark_package_files_for_destruction_worker_spec.rb index 15d9e4c347b..29fbf17d49a 100644 --- a/spec/workers/packages/mark_package_files_for_destruction_worker_spec.rb +++ b/spec/workers/packages/mark_package_files_for_destruction_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::MarkPackageFilesForDestructionWorker, :aggregate_failures do +RSpec.describe Packages::MarkPackageFilesForDestructionWorker, :aggregate_failures, feature_category: :package_registry do describe '#perform' do let_it_be(:package) { create(:package) } let_it_be(:package_files) { create_list(:package_file, 3, package: package) } diff --git a/spec/workers/packages/npm/deprecate_package_worker_spec.rb b/spec/workers/packages/npm/deprecate_package_worker_spec.rb new file mode 100644 index 00000000000..100a8a3af73 --- /dev/null +++ b/spec/workers/packages/npm/deprecate_package_worker_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Npm::DeprecatePackageWorker, feature_category: :package_registry do + describe '#perform' do + let_it_be(:project) { create(:project) } + let(:worker) { described_class.new } + let(:params) do + { + package_name: 'package_name', + versions: { + '1.0.1' => { + name: 'package_name', + deprecated: 'This version is deprecated' + } + } + } + end + + include_examples 'an idempotent worker' do + let(:job_args) { [project.id, params] } + + it 'calls the deprecation service' do + expect(::Packages::Npm::DeprecatePackageService).to receive(:new).with(project, params) do + double.tap do |service| + expect(service).to receive(:execute) + end + end + + worker.perform(*job_args) + end + end + end +end diff --git a/spec/workers/packages/nuget/extraction_worker_spec.rb b/spec/workers/packages/nuget/extraction_worker_spec.rb index 5186c037dc5..c1d42d556c2 100644 --- a/spec/workers/packages/nuget/extraction_worker_spec.rb +++ b/spec/workers/packages/nuget/extraction_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker do +RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker, feature_category: :package_registry do describe '#perform' do let!(:package) { create(:nuget_package) } let(:package_file) { package.package_files.first } @@ -73,13 +73,15 @@ RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker do ] invalid_names.each do |invalid_name| - before do - allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service| - allow(service).to receive(:package_name).and_return(invalid_name) + context "with #{invalid_name}" do + before do + allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service| + allow(service).to receive(:package_name).and_return(invalid_name) + end end - end - it_behaves_like 'handling the metadata error' + it_behaves_like 'handling the metadata error' + end end end @@ -87,20 +89,21 @@ RSpec.describe Packages::Nuget::ExtractionWorker, type: :worker do invalid_versions = [ '', '555', - '1.2', '1./2.3', '../../../../../1.2.3', '%2e%2e%2f1.2.3' ] invalid_versions.each do |invalid_version| - before do - allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service| - allow(service).to receive(:package_version).and_return(invalid_version) + context "with #{invalid_version}" do + before do + allow_next_instance_of(::Packages::Nuget::UpdatePackageFromMetadataService) do |service| + allow(service).to receive(:package_version).and_return(invalid_version) + end end - end - it_behaves_like 'handling the metadata error' + it_behaves_like 'handling the metadata error' + end end end diff --git a/spec/workers/packages/rubygems/extraction_worker_spec.rb b/spec/workers/packages/rubygems/extraction_worker_spec.rb index 0e67f3ac62e..8ad4c2e6447 100644 --- a/spec/workers/packages/rubygems/extraction_worker_spec.rb +++ b/spec/workers/packages/rubygems/extraction_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Packages::Rubygems::ExtractionWorker, type: :worker do +RSpec.describe Packages::Rubygems::ExtractionWorker, type: :worker, feature_category: :package_registry do describe '#perform' do let_it_be(:package) { create(:rubygems_package, :processing) } diff --git a/spec/workers/pages_domain_removal_cron_worker_spec.rb b/spec/workers/pages_domain_removal_cron_worker_spec.rb index f152d019de6..eb9f87bd831 100644 --- a/spec/workers/pages_domain_removal_cron_worker_spec.rb +++ b/spec/workers/pages_domain_removal_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PagesDomainRemovalCronWorker do +RSpec.describe PagesDomainRemovalCronWorker, feature_category: :pages do subject(:worker) { described_class.new } describe '#perform' do 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 70ffef5342e..5711b7787ea 100644 --- a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb +++ b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PagesDomainSslRenewalCronWorker do +RSpec.describe PagesDomainSslRenewalCronWorker, feature_category: :pages do include LetsEncryptHelpers subject(:worker) { described_class.new } diff --git a/spec/workers/pages_domain_ssl_renewal_worker_spec.rb b/spec/workers/pages_domain_ssl_renewal_worker_spec.rb index f8149b23a08..daaa939ecfe 100644 --- a/spec/workers/pages_domain_ssl_renewal_worker_spec.rb +++ b/spec/workers/pages_domain_ssl_renewal_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PagesDomainSslRenewalWorker do +RSpec.describe PagesDomainSslRenewalWorker, feature_category: :pages do include LetsEncryptHelpers subject(:worker) { described_class.new } diff --git a/spec/workers/pages_domain_verification_cron_worker_spec.rb b/spec/workers/pages_domain_verification_cron_worker_spec.rb index 01eaf984c90..be30e45fc94 100644 --- a/spec/workers/pages_domain_verification_cron_worker_spec.rb +++ b/spec/workers/pages_domain_verification_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PagesDomainVerificationCronWorker do +RSpec.describe PagesDomainVerificationCronWorker, feature_category: :pages do subject(:worker) { described_class.new } describe '#perform', :sidekiq do diff --git a/spec/workers/pages_domain_verification_worker_spec.rb b/spec/workers/pages_domain_verification_worker_spec.rb index 6d2f9ee2f8d..08f383c954f 100644 --- a/spec/workers/pages_domain_verification_worker_spec.rb +++ b/spec/workers/pages_domain_verification_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PagesDomainVerificationWorker do +RSpec.describe PagesDomainVerificationWorker, feature_category: :pages do subject(:worker) { described_class.new } let(:domain) { create(:pages_domain) } diff --git a/spec/workers/pages_worker_spec.rb b/spec/workers/pages_worker_spec.rb index f0d29037fa4..74da4707205 100644 --- a/spec/workers/pages_worker_spec.rb +++ b/spec/workers/pages_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PagesWorker, :sidekiq_inline do +RSpec.describe PagesWorker, :sidekiq_inline, feature_category: :pages do let_it_be(:ci_build) { create(:ci_build) } context 'when called with the deploy action' do diff --git a/spec/workers/partition_creation_worker_spec.rb b/spec/workers/partition_creation_worker_spec.rb index 5d15870b7f6..ab525fd5ce2 100644 --- a/spec/workers/partition_creation_worker_spec.rb +++ b/spec/workers/partition_creation_worker_spec.rb @@ -2,7 +2,7 @@ # require 'spec_helper' -RSpec.describe PartitionCreationWorker do +RSpec.describe PartitionCreationWorker, feature_category: :database do subject { described_class.new.perform } let(:management_worker) { double } diff --git a/spec/workers/personal_access_tokens/expired_notification_worker_spec.rb b/spec/workers/personal_access_tokens/expired_notification_worker_spec.rb index 7c3c48b3f80..7a3491b49d6 100644 --- a/spec/workers/personal_access_tokens/expired_notification_worker_spec.rb +++ b/spec/workers/personal_access_tokens/expired_notification_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PersonalAccessTokens::ExpiredNotificationWorker, type: :worker do +RSpec.describe PersonalAccessTokens::ExpiredNotificationWorker, type: :worker, feature_category: :system_access do subject(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/personal_access_tokens/expiring_worker_spec.rb b/spec/workers/personal_access_tokens/expiring_worker_spec.rb index 7fa777b911a..01ce4e85fe2 100644 --- a/spec/workers/personal_access_tokens/expiring_worker_spec.rb +++ b/spec/workers/personal_access_tokens/expiring_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PersonalAccessTokens::ExpiringWorker, type: :worker do +RSpec.describe PersonalAccessTokens::ExpiringWorker, type: :worker, feature_category: :system_access do subject(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/pipeline_hooks_worker_spec.rb b/spec/workers/pipeline_hooks_worker_spec.rb index 5d28b1e129a..7a85038d946 100644 --- a/spec/workers/pipeline_hooks_worker_spec.rb +++ b/spec/workers/pipeline_hooks_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PipelineHooksWorker do +RSpec.describe PipelineHooksWorker, feature_category: :continuous_integration do describe '#perform' do context 'when pipeline exists' do let(:pipeline) { create(:ci_pipeline) } @@ -37,7 +37,5 @@ RSpec.describe PipelineHooksWorker do end end - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed end diff --git a/spec/workers/pipeline_metrics_worker_spec.rb b/spec/workers/pipeline_metrics_worker_spec.rb index c73b84e26a6..7bd98f8f55d 100644 --- a/spec/workers/pipeline_metrics_worker_spec.rb +++ b/spec/workers/pipeline_metrics_worker_spec.rb @@ -2,23 +2,23 @@ require 'spec_helper' -RSpec.describe PipelineMetricsWorker do +RSpec.describe PipelineMetricsWorker, feature_category: :continuous_integration do let(:project) { create(:project, :repository) } let!(:merge_request) do - create(:merge_request, source_project: project, - source_branch: pipeline.ref, - head_pipeline: pipeline) + create(:merge_request, source_project: project, source_branch: pipeline.ref, head_pipeline: pipeline) end let(:pipeline) do - create(:ci_empty_pipeline, - status: status, - project: project, - ref: 'master', - sha: project.repository.commit('master').id, - started_at: 1.hour.ago, - finished_at: Time.current) + create( + :ci_empty_pipeline, + status: status, + project: project, + ref: 'master', + sha: project.repository.commit('master').id, + started_at: 1.hour.ago, + finished_at: Time.current + ) end let(:status) { 'pending' } diff --git a/spec/workers/pipeline_notification_worker_spec.rb b/spec/workers/pipeline_notification_worker_spec.rb index 672debd0501..05d0186e873 100644 --- a/spec/workers/pipeline_notification_worker_spec.rb +++ b/spec/workers/pipeline_notification_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PipelineNotificationWorker, :mailer do +RSpec.describe PipelineNotificationWorker, :mailer, feature_category: :continuous_integration do let_it_be(:pipeline) { create(:ci_pipeline) } describe '#execute' do diff --git a/spec/workers/pipeline_process_worker_spec.rb b/spec/workers/pipeline_process_worker_spec.rb index 6e95b7a4753..6ee91b4579d 100644 --- a/spec/workers/pipeline_process_worker_spec.rb +++ b/spec/workers/pipeline_process_worker_spec.rb @@ -2,9 +2,17 @@ require 'spec_helper' -RSpec.describe PipelineProcessWorker do +RSpec.describe PipelineProcessWorker, feature_category: :continuous_integration do let_it_be(:pipeline) { create(:ci_pipeline) } + it 'has the `until_executed` deduplicate strategy' do + expect(described_class.get_deduplicate_strategy).to eq(:until_executed) + end + + it 'has the option to reschedule once if deduplicated and a TTL of 1 minute' do + expect(described_class.get_deduplication_options).to include({ if_deduplicated: :reschedule_once, ttl: 1.minute }) + end + include_examples 'an idempotent worker' do let(:pipeline) { create(:ci_pipeline, :created) } let(:job_args) { [pipeline.id] } diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index 210987555c9..bd1bfc46d53 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PostReceive do +RSpec.describe PostReceive, feature_category: :source_code_management do include AfterNextHelpers let(:changes) do @@ -280,7 +280,6 @@ RSpec.describe PostReceive do let(:category) { described_class.name } let(:namespace) { project.namespace } let(:user) { project.creator } - let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } let(:label) { 'counts.source_code_pushes' } let(:property) { 'source_code_pushes' } let(:context) { [Gitlab::Tracking::ServicePingContext.new(data_source: :redis, key_path: label).to_h] } diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index 143809e8f2a..c95119b0d02 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ProcessCommitWorker do +RSpec.describe ProcessCommitWorker, feature_category: :source_code_management do let(:worker) { described_class.new } let(:user) { create(:user) } let(:project) { create(:project, :public, :repository) } @@ -82,11 +82,13 @@ RSpec.describe ProcessCommitWorker do context 'when commit is a merge request merge commit to the default branch' do let(:merge_request) do - create(:merge_request, - description: "Closes #{issue.to_reference}", - source_branch: 'feature-merged', - target_branch: 'master', - source_project: project) + create( + :merge_request, + description: "Closes #{issue.to_reference}", + source_branch: 'feature-merged', + target_branch: 'master', + source_project: project + ) end let(:commit) do diff --git a/spec/workers/project_cache_worker_spec.rb b/spec/workers/project_cache_worker_spec.rb index 3c807ef9ffd..4d468897599 100644 --- a/spec/workers/project_cache_worker_spec.rb +++ b/spec/workers/project_cache_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ProjectCacheWorker do +RSpec.describe ProjectCacheWorker, feature_category: :source_code_management do include ExclusiveLeaseHelpers let_it_be(:project) { create(:project, :repository) } @@ -13,10 +13,6 @@ RSpec.describe ProjectCacheWorker do let(:statistics) { [] } describe '#perform' do - before do - stub_exclusive_lease(lease_key, timeout: lease_timeout) - end - context 'with a non-existing project' do it 'does nothing' do expect(worker).not_to receive(:update_statistics) @@ -37,11 +33,6 @@ RSpec.describe ProjectCacheWorker do end context 'with an existing project' do - before do - lease_key = "namespace:namespaces_root_statistics:#{project.namespace_id}" - stub_exclusive_lease_taken(lease_key, timeout: Namespace::AggregationSchedule.default_lease_timeout) - end - it 'refreshes the method caches' do expect_any_instance_of(Repository).to receive(:refresh_method_caches) .with(%i(readme)) diff --git a/spec/workers/project_destroy_worker_spec.rb b/spec/workers/project_destroy_worker_spec.rb index 25508928bbf..d699393d7a0 100644 --- a/spec/workers/project_destroy_worker_spec.rb +++ b/spec/workers/project_destroy_worker_spec.rb @@ -2,15 +2,26 @@ require 'spec_helper' -RSpec.describe ProjectDestroyWorker do - let(:project) { create(:project, :repository, pending_delete: true) } - let!(:repository) { project.repository.raw } +RSpec.describe ProjectDestroyWorker, feature_category: :source_code_management do + let_it_be(:project) { create(:project, :repository, pending_delete: true) } + let_it_be(:repository) { project.repository.raw } - subject { described_class.new } + let(:user) { project.first_owner } + + subject(:worker) { described_class.new } + + include_examples 'an idempotent worker' do + let(:job_args) { [project.id, user.id, {}] } + + it 'does not change projects when run twice' do + expect { worker.perform(project.id, user.id, {}) }.to change { Project.count }.by(-1) + expect { worker.perform(project.id, user.id, {}) }.not_to change { Project.count } + end + end describe '#perform' do it 'deletes the project' do - subject.perform(project.id, project.first_owner.id, {}) + worker.perform(project.id, user.id, {}) expect(Project.all).not_to include(project) expect(repository).not_to exist @@ -18,13 +29,13 @@ RSpec.describe ProjectDestroyWorker do it 'does not raise error when project could not be found' do expect do - subject.perform(-1, project.first_owner.id, {}) + worker.perform(-1, user.id, {}) end.not_to raise_error end it 'does not raise error when user could not be found' do expect do - subject.perform(project.id, -1, {}) + worker.perform(project.id, -1, {}) end.not_to raise_error end end diff --git a/spec/workers/project_export_worker_spec.rb b/spec/workers/project_export_worker_spec.rb index dd0a921059d..eaf1536da63 100644 --- a/spec/workers/project_export_worker_spec.rb +++ b/spec/workers/project_export_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ProjectExportWorker do +RSpec.describe ProjectExportWorker, feature_category: :importers do it_behaves_like 'export worker' context 'exporters duration measuring' do diff --git a/spec/workers/projects/after_import_worker_spec.rb b/spec/workers/projects/after_import_worker_spec.rb index 85d15c89b0a..5af4f49d6e0 100644 --- a/spec/workers/projects/after_import_worker_spec.rb +++ b/spec/workers/projects/after_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::AfterImportWorker do +RSpec.describe Projects::AfterImportWorker, feature_category: :importers do subject { worker.perform(project.id) } let(:worker) { described_class.new } diff --git a/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb b/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb index 932ba29f806..1379b6785eb 100644 --- a/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb +++ b/spec/workers/projects/finalize_project_statistics_refresh_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::FinalizeProjectStatisticsRefreshWorker do +RSpec.describe Projects::FinalizeProjectStatisticsRefreshWorker, feature_category: :projects do let_it_be(:record) { create(:project_build_artifacts_size_refresh, :finalizing) } describe '#perform' do diff --git a/spec/workers/projects/import_export/create_relation_exports_worker_spec.rb b/spec/workers/projects/import_export/create_relation_exports_worker_spec.rb new file mode 100644 index 00000000000..2ff91150fda --- /dev/null +++ b/spec/workers/projects/import_export/create_relation_exports_worker_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::ImportExport::CreateRelationExportsWorker, feature_category: :importers do + let_it_be(:user) { build_stubbed(:user) } + let_it_be(:project) { create(:project) } + + let(:after_export_strategy) { {} } + let(:job_args) { [user.id, project.id, after_export_strategy] } + + before do + allow_next_instance_of(described_class) do |job| + allow(job).to receive(:jid) { SecureRandom.hex(8) } + end + end + + it_behaves_like 'an idempotent worker' + + context 'when job is re-enqueued after an interuption and same JID is used' do + before do + allow_next_instance_of(described_class) do |job| + allow(job).to receive(:jid).and_return(1234) + end + end + + it_behaves_like 'an idempotent worker' + + it 'does not start the export process twice' do + project.export_jobs.create!(jid: 1234, status_event: :start) + + expect { described_class.new.perform(user.id, project.id, after_export_strategy) } + .to change { Projects::ImportExport::WaitRelationExportsWorker.jobs.size }.by(0) + end + end + + it 'creates a export_job and sets the status to `started`' do + described_class.new.perform(user.id, project.id, after_export_strategy) + + export_job = project.export_jobs.last + expect(export_job.started?).to eq(true) + end + + it 'creates relation export records and enqueues a worker for each relation to be exported' do + allow(Projects::ImportExport::RelationExport).to receive(:relation_names_list).and_return(%w[relation_1 relation_2]) + + expect { described_class.new.perform(user.id, project.id, after_export_strategy) } + .to change { Projects::ImportExport::RelationExportWorker.jobs.size }.by(2) + + relation_exports = project.export_jobs.last.relation_exports + expect(relation_exports.collect(&:relation)).to match_array(%w[relation_1 relation_2]) + end + + it 'enqueues a WaitRelationExportsWorker' do + allow(Projects::ImportExport::WaitRelationExportsWorker).to receive(:perform_in) + + described_class.new.perform(user.id, project.id, after_export_strategy) + + export_job = project.export_jobs.last + expect(Projects::ImportExport::WaitRelationExportsWorker).to have_received(:perform_in).with( + described_class::INITIAL_DELAY, + export_job.id, + user.id, + after_export_strategy + ) + end +end diff --git a/spec/workers/projects/import_export/relation_export_worker_spec.rb b/spec/workers/projects/import_export/relation_export_worker_spec.rb index 236650fe55b..16ee73040b1 100644 --- a/spec/workers/projects/import_export/relation_export_worker_spec.rb +++ b/spec/workers/projects/import_export/relation_export_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::ImportExport::RelationExportWorker, type: :worker do +RSpec.describe Projects::ImportExport::RelationExportWorker, type: :worker, feature_category: :importers do let(:project_relation_export) { create(:project_relation_export) } let(:job_args) { [project_relation_export.id] } @@ -11,26 +11,61 @@ RSpec.describe Projects::ImportExport::RelationExportWorker, type: :worker do describe '#perform' do subject(:worker) { described_class.new } - context 'when relation export has initial state queued' do - let(:project_relation_export) { create(:project_relation_export) } + context 'when relation export has initial status `queued`' do + it 'exports the relation' do + expect_next_instance_of(Projects::ImportExport::RelationExportService) do |service| + expect(service).to receive(:execute) + end - it 'calls RelationExportService' do + worker.perform(project_relation_export.id) + end + end + + context 'when relation export has status `started`' do + let(:project_relation_export) { create(:project_relation_export, :started) } + + it 'retries the export of the relation' do expect_next_instance_of(Projects::ImportExport::RelationExportService) do |service| expect(service).to receive(:execute) end worker.perform(project_relation_export.id) + + expect(project_relation_export.reload.queued?).to eq(true) end end - context 'when relation export does not have queued state' do - let(:project_relation_export) { create(:project_relation_export, status_event: :start) } + context 'when relation export does not have status `queued` or `started`' do + let(:project_relation_export) { create(:project_relation_export, :finished) } - it 'does not call RelationExportService' do + it 'does not export the relation' do expect(Projects::ImportExport::RelationExportService).not_to receive(:new) worker.perform(project_relation_export.id) end end end + + describe '.sidekiq_retries_exhausted' do + let(:job) { { 'args' => [project_relation_export.id], 'error_message' => 'Error message' } } + + it 'sets relation export status to `failed`' do + described_class.sidekiq_retries_exhausted_block.call(job) + + expect(project_relation_export.reload.failed?).to eq(true) + end + + it 'logs the error message' do + expect_next_instance_of(Gitlab::Export::Logger) do |logger| + expect(logger).to receive(:error).with( + hash_including( + message: 'Project relation export failed', + export_error: 'Error message' + ) + ) + end + + described_class.sidekiq_retries_exhausted_block.call(job) + end + end end diff --git a/spec/workers/projects/import_export/wait_relation_exports_worker_spec.rb b/spec/workers/projects/import_export/wait_relation_exports_worker_spec.rb new file mode 100644 index 00000000000..52394b8998e --- /dev/null +++ b/spec/workers/projects/import_export/wait_relation_exports_worker_spec.rb @@ -0,0 +1,123 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::ImportExport::WaitRelationExportsWorker, feature_category: :importers do + let_it_be(:user) { create(:user) } + let_it_be(:project_export_job) { create(:project_export_job, :started) } + + let(:after_export_strategy) { {} } + let(:job_args) { [project_export_job.id, user.id, after_export_strategy] } + + def create_relation_export(trait, relation, export_error = nil) + create(:project_relation_export, trait, + { project_export_job: project_export_job, relation: relation, export_error: export_error } + ) + end + + before do + allow_next_instance_of(described_class) do |job| + allow(job).to receive(:jid) { SecureRandom.hex(8) } + end + end + + context 'when export job status is not `started`' do + it 'does not perform any operation and finishes the worker' do + finished_export_job = create(:project_export_job, :finished) + + expect { described_class.new.perform(finished_export_job.id, user.id, after_export_strategy) } + .to change { Projects::ImportExport::ParallelProjectExportWorker.jobs.size }.by(0) + .and change { described_class.jobs.size }.by(0) + end + end + + context 'when there are relation exports with status `queued`' do + before do + create_relation_export(:finished, 'labels') + create_relation_export(:started, 'milestones') + create_relation_export(:queued, 'merge_requests') + end + + it 'does not enqueue ParallelProjectExportWorker and re-enqueue WaitRelationExportsWorker' do + expect { described_class.new.perform(*job_args) } + .to change { Projects::ImportExport::ParallelProjectExportWorker.jobs.size }.by(0) + .and change { described_class.jobs.size }.by(1) + end + end + + context 'when there are relation exports with status `started`' do + let(:started_relation_export) { create_relation_export(:started, 'releases') } + + before do + create_relation_export(:finished, 'labels') + create_relation_export(:queued, 'merge_requests') + end + + context 'when the Sidekiq Job exporting the relation is still running' do + it "does not change relation export's status and re-enqueue WaitRelationExportsWorker" do + allow(Gitlab::SidekiqStatus).to receive(:running?).with(started_relation_export.jid).and_return(true) + + expect { described_class.new.perform(*job_args) } + .to change { described_class.jobs.size }.by(1) + + expect(started_relation_export.reload.started?).to eq(true) + end + end + + context 'when the Sidekiq Job exporting the relation is still is no longer running' do + it "set the relation export's status to `failed`" do + allow(Gitlab::SidekiqStatus).to receive(:running?).with(started_relation_export.jid).and_return(false) + + expect { described_class.new.perform(*job_args) } + .to change { described_class.jobs.size }.by(1) + + expect(started_relation_export.reload.failed?).to eq(true) + end + end + end + + context 'when all relation exports have status `finished`' do + before do + create_relation_export(:finished, 'labels') + create_relation_export(:finished, 'issues') + end + + it 'enqueues ParallelProjectExportWorker and does not reenqueue WaitRelationExportsWorker' do + expect { described_class.new.perform(*job_args) } + .to change { Projects::ImportExport::ParallelProjectExportWorker.jobs.size }.by(1) + .and change { described_class.jobs.size }.by(0) + end + + it_behaves_like 'an idempotent worker' + end + + context 'when at least one relation export has status `failed` and the rest have status `finished` or `failed`' do + before do + create_relation_export(:finished, 'labels') + create_relation_export(:failed, 'issues', 'Failed to export issues') + create_relation_export(:failed, 'releases', 'Failed to export releases') + end + + it_behaves_like 'an idempotent worker' do + it 'notifies the failed exports to the user' do + expect_next_instance_of(NotificationService) do |notification_service| + expect(notification_service).to receive(:project_not_exported) + .with( + project_export_job.project, + user, + array_including(['Failed to export issues', 'Failed to export releases']) + ) + .once + end + + described_class.new.perform(*job_args) + end + end + + it 'does not enqueue ParallelProjectExportWorker and re-enqueue WaitRelationExportsWorker' do + expect { described_class.new.perform(*job_args) } + .to change { Projects::ImportExport::ParallelProjectExportWorker.jobs.size }.by(0) + .and change { described_class.jobs.size }.by(0) + 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 f3c6434dc85..68af5e61e3b 100644 --- a/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb +++ b/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::InactiveProjectsDeletionCronWorker do +RSpec.describe Projects::InactiveProjectsDeletionCronWorker, feature_category: :compliance_management do include ProjectHelpers shared_examples 'worker is running for more than 4 minutes' do @@ -92,8 +92,11 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do 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) + 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 @@ -104,8 +107,11 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do 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) + 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) @@ -116,8 +122,11 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do 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) + 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) @@ -129,8 +138,9 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do 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 + expect( + redis.hget('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}") + ).to be_nil end end diff --git a/spec/workers/projects/inactive_projects_deletion_notification_worker_spec.rb b/spec/workers/projects/inactive_projects_deletion_notification_worker_spec.rb index 3ddfec0d346..2ac2b5d0795 100644 --- a/spec/workers/projects/inactive_projects_deletion_notification_worker_spec.rb +++ b/spec/workers/projects/inactive_projects_deletion_notification_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::InactiveProjectsDeletionNotificationWorker do +RSpec.describe Projects::InactiveProjectsDeletionNotificationWorker, feature_category: :compliance_management do describe "#perform" do subject(:worker) { described_class.new } @@ -22,14 +22,15 @@ RSpec.describe Projects::InactiveProjectsDeletionNotificationWorker do worker.perform(project.id, deletion_date) Gitlab::Redis::SharedState.with do |redis| - expect(redis.hget('inactive_projects_deletion_warning_email_notified', - "project:#{project.id}")).to eq(Date.current.to_s) + expect( + redis.hget('inactive_projects_deletion_warning_email_notified', "project:#{project.id}") + ).to eq(Date.current.to_s) end end it 'rescues and logs the exception if project does not exist' do - expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(ActiveRecord::RecordNotFound), - { project_id: non_existing_project_id }) + expect(Gitlab::ErrorTracking).to receive(:log_exception) + .with(instance_of(ActiveRecord::RecordNotFound), { project_id: non_existing_project_id }) worker.perform(non_existing_project_id, deletion_date) end diff --git a/spec/workers/projects/post_creation_worker_spec.rb b/spec/workers/projects/post_creation_worker_spec.rb index b702eed9ea4..2c50a07cf48 100644 --- a/spec/workers/projects/post_creation_worker_spec.rb +++ b/spec/workers/projects/post_creation_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::PostCreationWorker do +RSpec.describe Projects::PostCreationWorker, feature_category: :source_code_management do let_it_be(:user) { create :user } let(:worker) { described_class.new } diff --git a/spec/workers/projects/process_sync_events_worker_spec.rb b/spec/workers/projects/process_sync_events_worker_spec.rb index a10a4797b2c..7047d8e8653 100644 --- a/spec/workers/projects/process_sync_events_worker_spec.rb +++ b/spec/workers/projects/process_sync_events_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::ProcessSyncEventsWorker do +RSpec.describe Projects::ProcessSyncEventsWorker, feature_category: :cell do let!(:group) { create(:group) } let!(:project) { create(:project) } @@ -14,8 +14,8 @@ RSpec.describe Projects::ProcessSyncEventsWorker 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 }) + it 'has the option to reschedule once if deduplicated and a TTL of 1 minute' do + expect(described_class.get_deduplication_options).to include({ if_deduplicated: :reschedule_once, ttl: 1.minute }) end describe '#perform' do diff --git a/spec/workers/projects/record_target_platforms_worker_spec.rb b/spec/workers/projects/record_target_platforms_worker_spec.rb index 01852f252b7..0e106fe32f9 100644 --- a/spec/workers/projects/record_target_platforms_worker_spec.rb +++ b/spec/workers/projects/record_target_platforms_worker_spec.rb @@ -2,16 +2,16 @@ require 'spec_helper' -RSpec.describe Projects::RecordTargetPlatformsWorker do +RSpec.describe Projects::RecordTargetPlatformsWorker, feature_category: :projects do include ExclusiveLeaseHelpers let_it_be(:swift) { create(:programming_language, name: 'Swift') } let_it_be(:objective_c) { create(:programming_language, name: 'Objective-C') } - let_it_be(:java) { create(:programming_language, name: 'Java') } - let_it_be(:kotlin) { create(:programming_language, name: 'Kotlin') } let_it_be(:project) { create(:project, :repository, detected_repository_languages: true) } let(:worker) { described_class.new } + let(:service_result) { %w(ios osx watchos) } + let(:service_double) { instance_double(Projects::RecordTargetPlatformsService, execute: service_result) } let(:lease_key) { "#{described_class.name.underscore}:#{project.id}" } let(:lease_timeout) { described_class::LEASE_TIMEOUT } @@ -49,68 +49,19 @@ RSpec.describe Projects::RecordTargetPlatformsWorker do end end - def create_language(language) - create(:repository_language, project: project, programming_language: language) - end - - context 'when project uses programming language for Apple platform' do - let(:service_result) { %w(ios osx watchos) } - - context 'when project uses Swift programming language' do - before do - create_language(swift) - end - - it_behaves_like 'performs detection', Projects::AppleTargetPlatformDetectorService - end + context 'when project uses Swift programming language' do + let!(:repository_language) { create(:repository_language, project: project, programming_language: swift) } - context 'when project uses Objective-C programming language' do - before do - create_language(objective_c) - end - - it_behaves_like 'performs detection', Projects::AppleTargetPlatformDetectorService - end + include_examples 'performs detection', Projects::AppleTargetPlatformDetectorService end - context 'when project uses programming language for Android platform' do - let(:feature_enabled) { true } - let(:service_result) { %w(android) } - - before do - stub_feature_flags(detect_android_projects: feature_enabled) - end + context 'when project uses Objective-C programming language' do + let!(:repository_language) { create(:repository_language, project: project, programming_language: objective_c) } - context 'when project uses Java' do - before do - create_language(java) - end - - it_behaves_like 'performs detection', Projects::AndroidTargetPlatformDetectorService - - context 'when feature flag is disabled' do - let(:feature_enabled) { false } - - it_behaves_like 'does nothing' - end - end - - context 'when project uses Kotlin' do - before do - create_language(kotlin) - end - - it_behaves_like 'performs detection', Projects::AndroidTargetPlatformDetectorService - - context 'when feature flag is disabled' do - let(:feature_enabled) { false } - - it_behaves_like 'does nothing' - end - end + include_examples 'performs detection', Projects::AppleTargetPlatformDetectorService end - context 'when the project does not use programming languages for Apple or Android platforms' do + context 'when the project does not contain programming languages for Apple platforms' do it_behaves_like 'does nothing' 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 99627ff1ad2..f2b7e75fa10 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsWorker do +RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsWorker, feature_category: :build_artifacts do let(:worker) { described_class.new } describe '#perform_work' do diff --git a/spec/workers/projects/schedule_bulk_repository_shard_moves_worker_spec.rb b/spec/workers/projects/schedule_bulk_repository_shard_moves_worker_spec.rb index 7eff8e4dcd7..1d328280389 100644 --- a/spec/workers/projects/schedule_bulk_repository_shard_moves_worker_spec.rb +++ b/spec/workers/projects/schedule_bulk_repository_shard_moves_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::ScheduleBulkRepositoryShardMovesWorker do +RSpec.describe Projects::ScheduleBulkRepositoryShardMovesWorker, feature_category: :gitaly do it_behaves_like 'schedules bulk repository shard moves' do let_it_be_with_reload(:container) { create(:project, :repository) } diff --git a/spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb b/spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb index b5775f37678..b2111b2efb0 100644 --- a/spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb +++ b/spec/workers/projects/schedule_refresh_build_artifacts_size_statistics_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::ScheduleRefreshBuildArtifactsSizeStatisticsWorker do +RSpec.describe Projects::ScheduleRefreshBuildArtifactsSizeStatisticsWorker, feature_category: :build_artifacts do subject(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/projects/update_repository_storage_worker_spec.rb b/spec/workers/projects/update_repository_storage_worker_spec.rb index 7570d706325..91445c2bbf6 100644 --- a/spec/workers/projects/update_repository_storage_worker_spec.rb +++ b/spec/workers/projects/update_repository_storage_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::UpdateRepositoryStorageWorker do +RSpec.describe Projects::UpdateRepositoryStorageWorker, feature_category: :source_code_management do subject { described_class.new } it_behaves_like 'an update storage move worker' do diff --git a/spec/workers/propagate_integration_group_worker_spec.rb b/spec/workers/propagate_integration_group_worker_spec.rb index 60442438a1d..0d797d22137 100644 --- a/spec/workers/propagate_integration_group_worker_spec.rb +++ b/spec/workers/propagate_integration_group_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PropagateIntegrationGroupWorker do +RSpec.describe PropagateIntegrationGroupWorker, feature_category: :integrations do describe '#perform' do let_it_be(:group) { create(:group) } let_it_be(:another_group) { create(:group) } diff --git a/spec/workers/propagate_integration_inherit_descendant_worker_spec.rb b/spec/workers/propagate_integration_inherit_descendant_worker_spec.rb index c9a7bfaa8b6..d69dd45a209 100644 --- a/spec/workers/propagate_integration_inherit_descendant_worker_spec.rb +++ b/spec/workers/propagate_integration_inherit_descendant_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PropagateIntegrationInheritDescendantWorker do +RSpec.describe PropagateIntegrationInheritDescendantWorker, feature_category: :integrations do let_it_be(:group) { create(:group) } let_it_be(:subgroup) { create(:group, parent: group) } let_it_be(:group_integration) { create(:redmine_integration, :group, group: group) } diff --git a/spec/workers/propagate_integration_inherit_worker_spec.rb b/spec/workers/propagate_integration_inherit_worker_spec.rb index dd5d246d7f9..f5535696fd1 100644 --- a/spec/workers/propagate_integration_inherit_worker_spec.rb +++ b/spec/workers/propagate_integration_inherit_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PropagateIntegrationInheritWorker do +RSpec.describe PropagateIntegrationInheritWorker, feature_category: :integrations do describe '#perform' do let_it_be(:integration) { create(:redmine_integration, :instance) } let_it_be(:integration1) { create(:redmine_integration, inherit_from_id: integration.id) } diff --git a/spec/workers/propagate_integration_worker_spec.rb b/spec/workers/propagate_integration_worker_spec.rb index 030caefb833..90134b5cd64 100644 --- a/spec/workers/propagate_integration_worker_spec.rb +++ b/spec/workers/propagate_integration_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PropagateIntegrationWorker do +RSpec.describe PropagateIntegrationWorker, feature_category: :integrations do describe '#perform' do let(:project) { create(:project) } let(:integration) do diff --git a/spec/workers/prune_old_events_worker_spec.rb b/spec/workers/prune_old_events_worker_spec.rb index c1ba9128475..8046fff2cf3 100644 --- a/spec/workers/prune_old_events_worker_spec.rb +++ b/spec/workers/prune_old_events_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PruneOldEventsWorker do +RSpec.describe PruneOldEventsWorker, feature_category: :user_profile do describe '#perform' do let(:user) { create(:user) } @@ -30,5 +30,17 @@ RSpec.describe PruneOldEventsWorker do subject.perform expect(not_expired_3_years_event).to be_present end + + context 'with ops_prune_old_events FF disabled' do + before do + stub_feature_flags(ops_prune_old_events: false) + end + + it 'does not delete' do + subject.perform + + expect(Event.find_by(id: expired_event.id)).to be_present + end + end end end diff --git a/spec/workers/purge_dependency_proxy_cache_worker_spec.rb b/spec/workers/purge_dependency_proxy_cache_worker_spec.rb index 84315fd6ee9..49ef73bad53 100644 --- a/spec/workers/purge_dependency_proxy_cache_worker_spec.rb +++ b/spec/workers/purge_dependency_proxy_cache_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe PurgeDependencyProxyCacheWorker do +RSpec.describe PurgeDependencyProxyCacheWorker, feature_category: :dependency_proxy do let_it_be(:user) { create(:admin) } let_it_be_with_refind(:blob) { create(:dependency_proxy_blob ) } let_it_be_with_reload(:group) { blob.group } diff --git a/spec/workers/reactive_caching_worker_spec.rb b/spec/workers/reactive_caching_worker_spec.rb index 63b26817a7a..4e9d638c1e1 100644 --- a/spec/workers/reactive_caching_worker_spec.rb +++ b/spec/workers/reactive_caching_worker_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -RSpec.describe ReactiveCachingWorker do +RSpec.describe ReactiveCachingWorker, feature_category: :shared do it_behaves_like 'reactive cacheable worker' end diff --git a/spec/workers/rebase_worker_spec.rb b/spec/workers/rebase_worker_spec.rb index 4bdfd7219f2..ee8fd8b7461 100644 --- a/spec/workers/rebase_worker_spec.rb +++ b/spec/workers/rebase_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RebaseWorker, '#perform' do +RSpec.describe RebaseWorker, '#perform', feature_category: :source_code_management do include ProjectForksHelper context 'when rebasing an MR from a fork where upstream has protected branches' do @@ -10,11 +10,13 @@ RSpec.describe RebaseWorker, '#perform' do let(:forked_project) { fork_project(upstream_project, nil, repository: true) } let(:merge_request) do - create(:merge_request, - source_project: forked_project, - source_branch: 'feature_conflict', - target_project: upstream_project, - target_branch: 'master') + create( + :merge_request, + source_project: forked_project, + source_branch: 'feature_conflict', + target_project: upstream_project, + target_branch: 'master' + ) end it 'sets the correct project for running hooks' do diff --git a/spec/workers/releases/create_evidence_worker_spec.rb b/spec/workers/releases/create_evidence_worker_spec.rb index 7e3edcfe44a..8631b154920 100644 --- a/spec/workers/releases/create_evidence_worker_spec.rb +++ b/spec/workers/releases/create_evidence_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Releases::CreateEvidenceWorker do +RSpec.describe Releases::CreateEvidenceWorker, feature_category: :release_evidence do let(:project) { create(:project, :repository) } let(:release) { create(:release, project: project) } let(:pipeline) { create(:ci_empty_pipeline, sha: release.sha, project: project) } diff --git a/spec/workers/releases/manage_evidence_worker_spec.rb b/spec/workers/releases/manage_evidence_worker_spec.rb index 0004a4f4bfb..ca33e28b760 100644 --- a/spec/workers/releases/manage_evidence_worker_spec.rb +++ b/spec/workers/releases/manage_evidence_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Releases::ManageEvidenceWorker do +RSpec.describe Releases::ManageEvidenceWorker, feature_category: :release_evidence do let(:project) { create(:project, :repository) } shared_examples_for 'does not create a new Evidence record' do diff --git a/spec/workers/remote_mirror_notification_worker_spec.rb b/spec/workers/remote_mirror_notification_worker_spec.rb index e415e72645c..e7c32d79457 100644 --- a/spec/workers/remote_mirror_notification_worker_spec.rb +++ b/spec/workers/remote_mirror_notification_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RemoteMirrorNotificationWorker, :mailer do +RSpec.describe RemoteMirrorNotificationWorker, :mailer, feature_category: :source_code_management do let_it_be(:project) { create(:project, :repository, :remote_mirror) } let_it_be(:mirror) { project.remote_mirrors.first } @@ -30,8 +30,10 @@ RSpec.describe RemoteMirrorNotificationWorker, :mailer do end it 'does nothing when a notification has already been sent' do - mirror.update_columns(last_error: "There was a problem fetching", - error_notification_sent: true) + mirror.update_columns( + last_error: "There was a problem fetching", + error_notification_sent: true + ) expect(NotificationService).not_to receive(:new) diff --git a/spec/workers/remove_expired_group_links_worker_spec.rb b/spec/workers/remove_expired_group_links_worker_spec.rb index 7bdf6fc0d59..e08cc3fb5c5 100644 --- a/spec/workers/remove_expired_group_links_worker_spec.rb +++ b/spec/workers/remove_expired_group_links_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RemoveExpiredGroupLinksWorker do +RSpec.describe RemoveExpiredGroupLinksWorker, feature_category: :system_access do describe '#perform' do context 'ProjectGroupLinks' do let!(:expired_project_group_link) { create(:project_group_link, expires_at: 1.hour.ago) } diff --git a/spec/workers/remove_expired_members_worker_spec.rb b/spec/workers/remove_expired_members_worker_spec.rb index 062a9bcfa83..f77a078750d 100644 --- a/spec/workers/remove_expired_members_worker_spec.rb +++ b/spec/workers/remove_expired_members_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RemoveExpiredMembersWorker do +RSpec.describe RemoveExpiredMembersWorker, feature_category: :system_access do let(:worker) { described_class.new } describe '#perform' do @@ -35,8 +35,10 @@ RSpec.describe RemoveExpiredMembersWorker do new_job = Sidekiq::Worker.jobs.last - expect(new_job).to include('meta.project' => expired_project_member.project.full_path, - 'meta.user' => expired_project_member.user.username) + expect(new_job).to include( + 'meta.project' => expired_project_member.project.full_path, + 'meta.user' => expired_project_member.user.username + ) end end @@ -60,8 +62,7 @@ RSpec.describe RemoveExpiredMembersWorker do worker.perform expect( - Users::GhostUserMigration.where(user: expired_project_bot, - initiator_user: nil) + Users::GhostUserMigration.where(user: expired_project_bot, initiator_user: nil) ).to be_exists end end @@ -116,8 +117,10 @@ RSpec.describe RemoveExpiredMembersWorker do new_job = Sidekiq::Worker.jobs.last - expect(new_job).to include('meta.root_namespace' => expired_group_member.group.full_path, - 'meta.user' => expired_group_member.user.username) + expect(new_job).to include( + 'meta.root_namespace' => expired_group_member.group.full_path, + 'meta.user' => expired_group_member.user.username + ) end end diff --git a/spec/workers/remove_unaccepted_member_invites_worker_spec.rb b/spec/workers/remove_unaccepted_member_invites_worker_spec.rb index 96d7cf535ed..5173967c57a 100644 --- a/spec/workers/remove_unaccepted_member_invites_worker_spec.rb +++ b/spec/workers/remove_unaccepted_member_invites_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RemoveUnacceptedMemberInvitesWorker do +RSpec.describe RemoveUnacceptedMemberInvitesWorker, feature_category: :system_access do let(:worker) { described_class.new } describe '#perform' do @@ -13,15 +13,19 @@ RSpec.describe RemoveUnacceptedMemberInvitesWorker do it 'removes unaccepted members', :aggregate_failures do unaccepted_group_invitee = create( - :group_member, invite_token: 't0ken', - invite_email: 'group_invitee@example.com', - user: nil, - created_at: Time.current - 5.days) + :group_member, + invite_token: 't0ken', + invite_email: 'group_invitee@example.com', + user: nil, + created_at: Time.current - 5.days + ) unaccepted_project_invitee = create( - :project_member, invite_token: 't0ken', - invite_email: 'project_invitee@example.com', - user: nil, - created_at: Time.current - 5.days) + :project_member, + invite_token: 't0ken', + invite_email: 'project_invitee@example.com', + user: nil, + created_at: Time.current - 5.days + ) expect { worker.perform }.to change { Member.count }.by(-2) @@ -33,13 +37,17 @@ RSpec.describe RemoveUnacceptedMemberInvitesWorker do context 'invited members still within expiration threshold' do it 'leaves invited members', :aggregate_failures do group_invitee = create( - :group_member, invite_token: 't0ken', - invite_email: 'group_invitee@example.com', - user: nil) + :group_member, + invite_token: 't0ken', + invite_email: 'group_invitee@example.com', + user: nil + ) project_invitee = create( - :project_member, invite_token: 't0ken', - invite_email: 'project_invitee@example.com', - user: nil) + :project_member, + invite_token: 't0ken', + invite_email: 'project_invitee@example.com', + user: nil + ) expect { worker.perform }.not_to change { Member.count } @@ -56,15 +64,19 @@ RSpec.describe RemoveUnacceptedMemberInvitesWorker do it 'leaves accepted members', :aggregate_failures do user = create(:user) accepted_group_invitee = create( - :group_member, invite_token: 't0ken', - invite_email: 'group_invitee@example.com', - user: user, - created_at: Time.current - 5.days) + :group_member, + invite_token: 't0ken', + invite_email: 'group_invitee@example.com', + user: user, + created_at: Time.current - 5.days + ) accepted_project_invitee = create( - :project_member, invite_token: nil, - invite_email: 'project_invitee@example.com', - user: user, - created_at: Time.current - 5.days) + :project_member, + invite_token: nil, + invite_email: 'project_invitee@example.com', + user: user, + created_at: Time.current - 5.days + ) expect { worker.perform }.not_to change { Member.count } diff --git a/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb b/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb index 2562a7bc6fe..e5564834443 100644 --- a/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb +++ b/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RemoveUnreferencedLfsObjectsWorker do +RSpec.describe RemoveUnreferencedLfsObjectsWorker, feature_category: :source_code_management do let(:worker) { described_class.new } describe '#perform' do @@ -13,24 +13,16 @@ RSpec.describe RemoveUnreferencedLfsObjectsWorker do let!(:referenced_lfs_object1) { create(:lfs_object, oid: '3' * 64) } let!(:referenced_lfs_object2) { create(:lfs_object, oid: '4' * 64) } let!(:lfs_objects_project1_1) do - create(:lfs_objects_project, - project: project1, - lfs_object: referenced_lfs_object1 + create(:lfs_objects_project, project: project1, lfs_object: referenced_lfs_object1 ) end let!(:lfs_objects_project2_1) do - create(:lfs_objects_project, - project: project2, - lfs_object: referenced_lfs_object1 - ) + create(:lfs_objects_project, project: project2, lfs_object: referenced_lfs_object1) end let!(:lfs_objects_project1_2) do - create(:lfs_objects_project, - project: project1, - lfs_object: referenced_lfs_object2 - ) + create(:lfs_objects_project, project: project1, lfs_object: referenced_lfs_object2) end it 'removes unreferenced lfs objects' do diff --git a/spec/workers/repository_check/batch_worker_spec.rb b/spec/workers/repository_check/batch_worker_spec.rb index 643b55af573..bb4a4844b9b 100644 --- a/spec/workers/repository_check/batch_worker_spec.rb +++ b/spec/workers/repository_check/batch_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RepositoryCheck::BatchWorker do +RSpec.describe RepositoryCheck::BatchWorker, feature_category: :source_code_management do let(:shard_name) { 'default' } subject { described_class.new } diff --git a/spec/workers/repository_check/clear_worker_spec.rb b/spec/workers/repository_check/clear_worker_spec.rb index b5f09e8a05f..dd11a2705ac 100644 --- a/spec/workers/repository_check/clear_worker_spec.rb +++ b/spec/workers/repository_check/clear_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RepositoryCheck::ClearWorker do +RSpec.describe RepositoryCheck::ClearWorker, feature_category: :source_code_management do it 'clears repository check columns' do project = create(:project) project.update_columns( diff --git a/spec/workers/repository_check/dispatch_worker_spec.rb b/spec/workers/repository_check/dispatch_worker_spec.rb index 829abc7d895..34ecc645675 100644 --- a/spec/workers/repository_check/dispatch_worker_spec.rb +++ b/spec/workers/repository_check/dispatch_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RepositoryCheck::DispatchWorker do +RSpec.describe RepositoryCheck::DispatchWorker, feature_category: :source_code_management do subject { described_class.new } it 'does nothing when repository checks are disabled' do diff --git a/spec/workers/repository_check/single_repository_worker_spec.rb b/spec/workers/repository_check/single_repository_worker_spec.rb index 0a37a296e7a..3e52ce781ee 100644 --- a/spec/workers/repository_check/single_repository_worker_spec.rb +++ b/spec/workers/repository_check/single_repository_worker_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'fileutils' -RSpec.describe RepositoryCheck::SingleRepositoryWorker do +RSpec.describe RepositoryCheck::SingleRepositoryWorker, feature_category: :source_code_management do subject(:worker) { described_class.new } before do diff --git a/spec/workers/repository_cleanup_worker_spec.rb b/spec/workers/repository_cleanup_worker_spec.rb index 2b700b944d2..1e80a48451b 100644 --- a/spec/workers/repository_cleanup_worker_spec.rb +++ b/spec/workers/repository_cleanup_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RepositoryCleanupWorker do +RSpec.describe RepositoryCleanupWorker, feature_category: :source_code_management do let(:project) { create(:project) } let(:user) { create(:user) } diff --git a/spec/workers/repository_fork_worker_spec.rb b/spec/workers/repository_fork_worker_spec.rb index 85dee935001..3a5528b6a04 100644 --- a/spec/workers/repository_fork_worker_spec.rb +++ b/spec/workers/repository_fork_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RepositoryForkWorker do +RSpec.describe RepositoryForkWorker, feature_category: :source_code_management do include ProjectForksHelper describe 'modules' do diff --git a/spec/workers/repository_update_remote_mirror_worker_spec.rb b/spec/workers/repository_update_remote_mirror_worker_spec.rb index ef6a8d76d2c..61b9441ec27 100644 --- a/spec/workers/repository_update_remote_mirror_worker_spec.rb +++ b/spec/workers/repository_update_remote_mirror_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_state do +RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_state, feature_category: :source_code_management do let_it_be(:remote_mirror) { create(:remote_mirror) } let(:scheduled_time) { Time.current - 5.minutes } @@ -57,14 +57,16 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st end it 'retries 3 times for the worker to finish before rescheduling' do - expect(subject).to receive(:in_lock) - .with("#{described_class.name}:#{remote_mirror.id}", - retries: 3, - ttl: remote_mirror.max_runtime, - sleep_sec: described_class::LOCK_WAIT_TIME) - .and_raise(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError) - expect(described_class).to receive(:perform_in) - .with(remote_mirror.backoff_delay, remote_mirror.id, scheduled_time, 0) + expect(subject).to receive(:in_lock).with( + "#{described_class.name}:#{remote_mirror.id}", + retries: 3, + ttl: remote_mirror.max_runtime, + sleep_sec: described_class::LOCK_WAIT_TIME + ).and_raise(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError) + + expect(described_class) + .to receive(:perform_in) + .with(remote_mirror.backoff_delay, remote_mirror.id, scheduled_time, 0) subject.perform(remote_mirror.id, scheduled_time) end diff --git a/spec/workers/run_pipeline_schedule_worker_spec.rb b/spec/workers/run_pipeline_schedule_worker_spec.rb index 75938d3b793..d0e4de1aa98 100644 --- a/spec/workers/run_pipeline_schedule_worker_spec.rb +++ b/spec/workers/run_pipeline_schedule_worker_spec.rb @@ -137,9 +137,11 @@ RSpec.describe RunPipelineScheduleWorker, feature_category: :continuous_integrat expect(Gitlab::ErrorTracking) .to receive(:track_and_raise_for_dev_exception) - .with(ActiveRecord::StatementInvalid, - issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231', - schedule_id: pipeline_schedule.id).once + .with( + ActiveRecord::StatementInvalid, + issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231', + schedule_id: pipeline_schedule.id + ).once end it 'increments Prometheus counter' do diff --git a/spec/workers/schedule_merge_request_cleanup_refs_worker_spec.rb b/spec/workers/schedule_merge_request_cleanup_refs_worker_spec.rb index 49730d9ab8c..b93202fe9b3 100644 --- a/spec/workers/schedule_merge_request_cleanup_refs_worker_spec.rb +++ b/spec/workers/schedule_merge_request_cleanup_refs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ScheduleMergeRequestCleanupRefsWorker do +RSpec.describe ScheduleMergeRequestCleanupRefsWorker, feature_category: :code_review_workflow do subject(:worker) { described_class.new } describe '#perform' do diff --git a/spec/workers/schedule_migrate_external_diffs_worker_spec.rb b/spec/workers/schedule_migrate_external_diffs_worker_spec.rb index 09a0124f6e0..061467a28e0 100644 --- a/spec/workers/schedule_migrate_external_diffs_worker_spec.rb +++ b/spec/workers/schedule_migrate_external_diffs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ScheduleMigrateExternalDiffsWorker do +RSpec.describe ScheduleMigrateExternalDiffsWorker, feature_category: :code_review_workflow do include ExclusiveLeaseHelpers let(:worker) { described_class.new } diff --git a/spec/workers/self_monitoring_project_create_worker_spec.rb b/spec/workers/self_monitoring_project_create_worker_spec.rb deleted file mode 100644 index b618b8ede99..00000000000 --- a/spec/workers/self_monitoring_project_create_worker_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe SelfMonitoringProjectCreateWorker do - describe '#perform' do - let(:service_class) { Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService } - let(:service) { instance_double(service_class) } - - it_behaves_like 'executes service' - end - - describe '.in_progress?', :clean_gitlab_redis_shared_state do - it_behaves_like 'returns in_progress based on Sidekiq::Status' - end -end diff --git a/spec/workers/self_monitoring_project_delete_worker_spec.rb b/spec/workers/self_monitoring_project_delete_worker_spec.rb deleted file mode 100644 index 9a53fe59a40..00000000000 --- a/spec/workers/self_monitoring_project_delete_worker_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe SelfMonitoringProjectDeleteWorker do - let_it_be(:jid) { 'b5b28910d97563e58c2fe55f' } - let_it_be(:data_key) { "self_monitoring_delete_result:#{jid}" } - - describe '#perform' do - let(:service_class) { Gitlab::DatabaseImporters::SelfMonitoring::Project::DeleteService } - let(:service) { instance_double(service_class) } - - it_behaves_like 'executes service' - end - - describe '.status', :clean_gitlab_redis_shared_state do - it_behaves_like 'returns in_progress based on Sidekiq::Status' - end -end diff --git a/spec/workers/service_desk_email_receiver_worker_spec.rb b/spec/workers/service_desk_email_receiver_worker_spec.rb index 60fc951f627..bed66875f34 100644 --- a/spec/workers/service_desk_email_receiver_worker_spec.rb +++ b/spec/workers/service_desk_email_receiver_worker_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe ServiceDeskEmailReceiverWorker, :mailer do +RSpec.describe ServiceDeskEmailReceiverWorker, :mailer, feature_category: :service_desk do describe '#perform' do let(:worker) { described_class.new } let(:email) { fixture_file('emails/service_desk_custom_address.eml') } diff --git a/spec/workers/snippets/schedule_bulk_repository_shard_moves_worker_spec.rb b/spec/workers/snippets/schedule_bulk_repository_shard_moves_worker_spec.rb index be7d8ebe2d3..d31600d9cba 100644 --- a/spec/workers/snippets/schedule_bulk_repository_shard_moves_worker_spec.rb +++ b/spec/workers/snippets/schedule_bulk_repository_shard_moves_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Snippets::ScheduleBulkRepositoryShardMovesWorker do +RSpec.describe Snippets::ScheduleBulkRepositoryShardMovesWorker, feature_category: :gitaly do it_behaves_like 'schedules bulk repository shard moves' do let_it_be_with_reload(:container) { create(:snippet, :repository).tap { |snippet| snippet.create_repository } } diff --git a/spec/workers/snippets/update_repository_storage_worker_spec.rb b/spec/workers/snippets/update_repository_storage_worker_spec.rb index 38e9012e9c5..b26384fc75c 100644 --- a/spec/workers/snippets/update_repository_storage_worker_spec.rb +++ b/spec/workers/snippets/update_repository_storage_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Snippets::UpdateRepositoryStorageWorker do +RSpec.describe Snippets::UpdateRepositoryStorageWorker, feature_category: :source_code_management do subject { described_class.new } it_behaves_like 'an update storage move worker' do diff --git a/spec/workers/ssh_keys/expired_notification_worker_spec.rb b/spec/workers/ssh_keys/expired_notification_worker_spec.rb index 26d9460d73e..f3ba586c21e 100644 --- a/spec/workers/ssh_keys/expired_notification_worker_spec.rb +++ b/spec/workers/ssh_keys/expired_notification_worker_spec.rb @@ -2,12 +2,11 @@ require 'spec_helper' -RSpec.describe SshKeys::ExpiredNotificationWorker, type: :worker do +RSpec.describe SshKeys::ExpiredNotificationWorker, type: :worker, feature_category: :compliance_management do subject(:worker) { described_class.new } 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..f6eaf76b54d 100644 --- a/spec/workers/ssh_keys/expiring_soon_notification_worker_spec.rb +++ b/spec/workers/ssh_keys/expiring_soon_notification_worker_spec.rb @@ -2,12 +2,11 @@ require 'spec_helper' -RSpec.describe SshKeys::ExpiringSoonNotificationWorker, type: :worker do +RSpec.describe SshKeys::ExpiringSoonNotificationWorker, type: :worker, feature_category: :compliance_management do subject(:worker) { described_class.new } 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/ssh_keys/update_last_used_at_worker_spec.rb b/spec/workers/ssh_keys/update_last_used_at_worker_spec.rb new file mode 100644 index 00000000000..33b3b44955d --- /dev/null +++ b/spec/workers/ssh_keys/update_last_used_at_worker_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe SshKeys::UpdateLastUsedAtWorker, type: :worker, feature_category: :source_code_management do + let_it_be(:key) { create(:key) } + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [key.id] } + end + + describe '#perform' do + subject(:worker) { described_class.new } + + it 'updates last_used_at column', :freeze_time do + expect { worker.perform(key.id) }.to change { key.reload.last_used_at }.to(Time.zone.now) + end + + it 'does not update updated_at column' do + expect { worker.perform(key.id) }.not_to change { key.reload.updated_at } + end + end +end diff --git a/spec/workers/stage_update_worker_spec.rb b/spec/workers/stage_update_worker_spec.rb index e50c7183153..bb2f63d3b50 100644 --- a/spec/workers/stage_update_worker_spec.rb +++ b/spec/workers/stage_update_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe StageUpdateWorker do +RSpec.describe StageUpdateWorker, feature_category: :continuous_integration do describe '#perform' do context 'when stage exists' do let(:stage) { create(:ci_stage) } diff --git a/spec/workers/stuck_ci_jobs_worker_spec.rb b/spec/workers/stuck_ci_jobs_worker_spec.rb index 19ff8ec55c2..1c5f54dc55f 100644 --- a/spec/workers/stuck_ci_jobs_worker_spec.rb +++ b/spec/workers/stuck_ci_jobs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe StuckCiJobsWorker do +RSpec.describe StuckCiJobsWorker, feature_category: :continuous_integration do include ExclusiveLeaseHelpers let(:worker) { described_class.new } diff --git a/spec/workers/stuck_export_jobs_worker_spec.rb b/spec/workers/stuck_export_jobs_worker_spec.rb index cbc7adc8e3f..0e300b0077b 100644 --- a/spec/workers/stuck_export_jobs_worker_spec.rb +++ b/spec/workers/stuck_export_jobs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe StuckExportJobsWorker do +RSpec.describe StuckExportJobsWorker, feature_category: :importers do let(:worker) { described_class.new } shared_examples 'project export job detection' do diff --git a/spec/workers/stuck_merge_jobs_worker_spec.rb b/spec/workers/stuck_merge_jobs_worker_spec.rb index bade2e1ca1b..44dc6550cdb 100644 --- a/spec/workers/stuck_merge_jobs_worker_spec.rb +++ b/spec/workers/stuck_merge_jobs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe StuckMergeJobsWorker do +RSpec.describe StuckMergeJobsWorker, feature_category: :code_review_workflow do describe 'perform' do let(:worker) { described_class.new } diff --git a/spec/workers/system_hook_push_worker_spec.rb b/spec/workers/system_hook_push_worker_spec.rb index 43a3f8e3e19..35e44e635cc 100644 --- a/spec/workers/system_hook_push_worker_spec.rb +++ b/spec/workers/system_hook_push_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe SystemHookPushWorker do +RSpec.describe SystemHookPushWorker, feature_category: :source_code_management do include RepoHelpers subject { described_class.new } diff --git a/spec/workers/tasks_to_be_done/create_worker_spec.rb b/spec/workers/tasks_to_be_done/create_worker_spec.rb index c3c3612f9a7..643424ae068 100644 --- a/spec/workers/tasks_to_be_done/create_worker_spec.rb +++ b/spec/workers/tasks_to_be_done/create_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TasksToBeDone::CreateWorker do +RSpec.describe TasksToBeDone::CreateWorker, feature_category: :onboarding do let_it_be(:member_task) { create(:member_task, tasks: MemberTask::TASKS.values) } let_it_be(:current_user) { create(:user) } diff --git a/spec/workers/terraform/states/destroy_worker_spec.rb b/spec/workers/terraform/states/destroy_worker_spec.rb index 02e79373279..7cc20e0ad5d 100644 --- a/spec/workers/terraform/states/destroy_worker_spec.rb +++ b/spec/workers/terraform/states/destroy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Terraform::States::DestroyWorker do +RSpec.describe Terraform::States::DestroyWorker, feature_category: :infrastructure_as_code do let(:state) { create(:terraform_state) } describe '#perform' do diff --git a/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb b/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb index 86202fac1ed..54e2061217f 100644 --- a/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb +++ b/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TodosDestroyer::ConfidentialIssueWorker do +RSpec.describe TodosDestroyer::ConfidentialIssueWorker, feature_category: :team_planning do let(:service) { double } it "calls the Todos::Destroy::ConfidentialIssueService with issue_id parameter" do diff --git a/spec/workers/todos_destroyer/destroyed_designs_worker_spec.rb b/spec/workers/todos_destroyer/destroyed_designs_worker_spec.rb index 113faeb0d2f..b85ea1a5847 100644 --- a/spec/workers/todos_destroyer/destroyed_designs_worker_spec.rb +++ b/spec/workers/todos_destroyer/destroyed_designs_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TodosDestroyer::DestroyedDesignsWorker do +RSpec.describe TodosDestroyer::DestroyedDesignsWorker, feature_category: :team_planning do let(:service) { double } it 'calls the Todos::Destroy::DesignService with design_ids parameter' do diff --git a/spec/workers/todos_destroyer/destroyed_issuable_worker_spec.rb b/spec/workers/todos_destroyer/destroyed_issuable_worker_spec.rb index 6ccad25ad76..72adc7ba0c7 100644 --- a/spec/workers/todos_destroyer/destroyed_issuable_worker_spec.rb +++ b/spec/workers/todos_destroyer/destroyed_issuable_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TodosDestroyer::DestroyedIssuableWorker do +RSpec.describe TodosDestroyer::DestroyedIssuableWorker, feature_category: :team_planning do let(:job_args) { [1, 'MergeRequest'] } it 'calls the Todos::Destroy::DestroyedIssuableService' do diff --git a/spec/workers/todos_destroyer/entity_leave_worker_spec.rb b/spec/workers/todos_destroyer/entity_leave_worker_spec.rb index db3b0252056..d7682ad0e5e 100644 --- a/spec/workers/todos_destroyer/entity_leave_worker_spec.rb +++ b/spec/workers/todos_destroyer/entity_leave_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TodosDestroyer::EntityLeaveWorker do +RSpec.describe TodosDestroyer::EntityLeaveWorker, feature_category: :team_planning do it "calls the Todos::Destroy::EntityLeaveService with the params it was given" do service = double diff --git a/spec/workers/todos_destroyer/group_private_worker_spec.rb b/spec/workers/todos_destroyer/group_private_worker_spec.rb index 4903edd4bbe..4d49a852a3e 100644 --- a/spec/workers/todos_destroyer/group_private_worker_spec.rb +++ b/spec/workers/todos_destroyer/group_private_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TodosDestroyer::GroupPrivateWorker do +RSpec.describe TodosDestroyer::GroupPrivateWorker, feature_category: :team_planning do it "calls the Todos::Destroy::GroupPrivateService with the params it was given" do service = double diff --git a/spec/workers/todos_destroyer/private_features_worker_spec.rb b/spec/workers/todos_destroyer/private_features_worker_spec.rb index 88d9be051d0..834e0fb2201 100644 --- a/spec/workers/todos_destroyer/private_features_worker_spec.rb +++ b/spec/workers/todos_destroyer/private_features_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TodosDestroyer::PrivateFeaturesWorker do +RSpec.describe TodosDestroyer::PrivateFeaturesWorker, feature_category: :team_planning do it "calls the Todos::Destroy::PrivateFeaturesService with the params it was given" do service = double diff --git a/spec/workers/todos_destroyer/project_private_worker_spec.rb b/spec/workers/todos_destroyer/project_private_worker_spec.rb index 4e54fbdb275..2435fcade22 100644 --- a/spec/workers/todos_destroyer/project_private_worker_spec.rb +++ b/spec/workers/todos_destroyer/project_private_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TodosDestroyer::ProjectPrivateWorker do +RSpec.describe TodosDestroyer::ProjectPrivateWorker, feature_category: :team_planning do it "calls the Todos::Destroy::ProjectPrivateService with the params it was given" do service = double diff --git a/spec/workers/trending_projects_worker_spec.rb b/spec/workers/trending_projects_worker_spec.rb index 1f1e312e457..b6acd01f7c4 100644 --- a/spec/workers/trending_projects_worker_spec.rb +++ b/spec/workers/trending_projects_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe TrendingProjectsWorker do +RSpec.describe TrendingProjectsWorker, feature_category: :source_code_management do describe '#perform' do it 'refreshes the trending projects' do expect(TrendingProject).to receive(:refresh!) diff --git a/spec/workers/update_container_registry_info_worker_spec.rb b/spec/workers/update_container_registry_info_worker_spec.rb index ace9e55cbce..a8c501efd51 100644 --- a/spec/workers/update_container_registry_info_worker_spec.rb +++ b/spec/workers/update_container_registry_info_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UpdateContainerRegistryInfoWorker do +RSpec.describe UpdateContainerRegistryInfoWorker, feature_category: :container_registry do describe '#perform' do it 'calls UpdateContainerRegistryInfoService' do expect_next_instance_of(UpdateContainerRegistryInfoService) do |service| diff --git a/spec/workers/update_external_pull_requests_worker_spec.rb b/spec/workers/update_external_pull_requests_worker_spec.rb index cb6a4e2ebf8..254a4b69f3b 100644 --- a/spec/workers/update_external_pull_requests_worker_spec.rb +++ b/spec/workers/update_external_pull_requests_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UpdateExternalPullRequestsWorker do +RSpec.describe UpdateExternalPullRequestsWorker, feature_category: :continuous_integration do describe '#perform' do let_it_be(:project) { create(:project, import_source: 'tanuki/repository') } let_it_be(:user) { create(:user) } diff --git a/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb b/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb index 5ed600e308b..c64a597833d 100644 --- a/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb +++ b/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UpdateHeadPipelineForMergeRequestWorker do +RSpec.describe UpdateHeadPipelineForMergeRequestWorker, feature_category: :continuous_integration do describe '#perform' do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :repository) } @@ -66,11 +66,13 @@ RSpec.describe UpdateHeadPipelineForMergeRequestWorker do context 'when a merge request pipeline exists' do let_it_be(:merge_request_pipeline) do - create(:ci_pipeline, - project: project, - source: :merge_request_event, - sha: latest_sha, - merge_request: merge_request) + create( + :ci_pipeline, + project: project, + source: :merge_request_event, + sha: latest_sha, + merge_request: merge_request + ) end it 'sets the merge request pipeline as the head pipeline' do diff --git a/spec/workers/update_highest_role_worker_spec.rb b/spec/workers/update_highest_role_worker_spec.rb index cd127f26e95..3e4a2f6be36 100644 --- a/spec/workers/update_highest_role_worker_spec.rb +++ b/spec/workers/update_highest_role_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UpdateHighestRoleWorker, :clean_gitlab_redis_shared_state do +RSpec.describe UpdateHighestRoleWorker, :clean_gitlab_redis_shared_state, feature_category: :seat_cost_management do include ExclusiveLeaseHelpers let(:worker) { described_class.new } diff --git a/spec/workers/update_merge_requests_worker_spec.rb b/spec/workers/update_merge_requests_worker_spec.rb index 64fcc2bd388..de164fe352a 100644 --- a/spec/workers/update_merge_requests_worker_spec.rb +++ b/spec/workers/update_merge_requests_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UpdateMergeRequestsWorker do +RSpec.describe UpdateMergeRequestsWorker, feature_category: :code_review_workflow do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } let_it_be(:oldrev) { "123456" } diff --git a/spec/workers/update_project_statistics_worker_spec.rb b/spec/workers/update_project_statistics_worker_spec.rb index 2f356376d7c..c5e6f45a201 100644 --- a/spec/workers/update_project_statistics_worker_spec.rb +++ b/spec/workers/update_project_statistics_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UpdateProjectStatisticsWorker do +RSpec.describe UpdateProjectStatisticsWorker, feature_category: :source_code_management do include ExclusiveLeaseHelpers let(:worker) { described_class.new } diff --git a/spec/workers/upload_checksum_worker_spec.rb b/spec/workers/upload_checksum_worker_spec.rb index 75d7509b6e6..6c47a8e198c 100644 --- a/spec/workers/upload_checksum_worker_spec.rb +++ b/spec/workers/upload_checksum_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UploadChecksumWorker do +RSpec.describe UploadChecksumWorker, feature_category: :geo_replication do describe '#perform' do subject { described_class.new } diff --git a/spec/workers/user_status_cleanup/batch_worker_spec.rb b/spec/workers/user_status_cleanup/batch_worker_spec.rb index 2fd84d0e085..e2ad12672de 100644 --- a/spec/workers/user_status_cleanup/batch_worker_spec.rb +++ b/spec/workers/user_status_cleanup/batch_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe UserStatusCleanup::BatchWorker do +RSpec.describe UserStatusCleanup::BatchWorker, feature_category: :user_profile do include_examples 'an idempotent worker' do subject do perform_multiple([], worker: described_class.new) diff --git a/spec/workers/users/create_statistics_worker_spec.rb b/spec/workers/users/create_statistics_worker_spec.rb index 2118cc42f3a..2c1c7738533 100644 --- a/spec/workers/users/create_statistics_worker_spec.rb +++ b/spec/workers/users/create_statistics_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Users::CreateStatisticsWorker do +RSpec.describe Users::CreateStatisticsWorker, feature_category: :user_profile do describe '#perform' do subject { described_class.new.perform } diff --git a/spec/workers/users/deactivate_dormant_users_worker_spec.rb b/spec/workers/users/deactivate_dormant_users_worker_spec.rb index a8318de669b..fdcbb624562 100644 --- a/spec/workers/users/deactivate_dormant_users_worker_spec.rb +++ b/spec/workers/users/deactivate_dormant_users_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Users::DeactivateDormantUsersWorker do +RSpec.describe Users::DeactivateDormantUsersWorker, feature_category: :seat_cost_management do using RSpec::Parameterized::TableSyntax describe '#perform' do @@ -12,8 +12,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do subject(:worker) { described_class.new } - it 'does not run for GitLab.com' do - expect(Gitlab).to receive(:com?).and_return(true) + it 'does not run for SaaS', :saas do # Now makes a call to current settings to determine period of dormancy worker.perform @@ -36,6 +35,7 @@ RSpec.describe Users::DeactivateDormantUsersWorker do where(:user_type, :expected_state) do :human | 'deactivated' + :human_deprecated | 'deactivated' :support_bot | 'active' :alert_bot | 'active' :visual_review_bot | 'active' @@ -58,11 +58,13 @@ RSpec.describe Users::DeactivateDormantUsersWorker do it 'does not deactivate non-active users' do human_user = create(:user, user_type: :human, state: :blocked, last_activity_on: Gitlab::CurrentSettings.deactivate_dormant_users_period.days.ago.to_date) + human_user2 = create(:user, user_type: :human_deprecated, 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 expect(human_user.reload.state).to eq('blocked') + expect(human_user2.reload.state).to eq('blocked') expect(service_user.reload.state).to eq('blocked') end 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 index 7c585542e30..38ea7c43267 100644 --- 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 @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Users::MigrateRecordsToGhostUserInBatchesWorker do +RSpec.describe Users::MigrateRecordsToGhostUserInBatchesWorker, feature_category: :seat_cost_management do include ExclusiveLeaseHelpers let(:worker) { described_class.new } diff --git a/spec/workers/web_hook_worker_spec.rb b/spec/workers/web_hook_worker_spec.rb index e2ff36975c4..be43b83ec0a 100644 --- a/spec/workers/web_hook_worker_spec.rb +++ b/spec/workers/web_hook_worker_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe WebHookWorker do +RSpec.describe WebHookWorker, feature_category: :integrations do include AfterNextHelpers let_it_be(:project_hook) { create(:project_hook) } @@ -28,8 +28,6 @@ RSpec.describe WebHookWorker do .to change { Gitlab::WebHooks::RecursionDetection::UUID.instance.request_uuid }.to(uuid) end - it_behaves_like 'worker with data consistency', - described_class, - data_consistency: :delayed + it_behaves_like 'worker with data consistency', described_class, data_consistency: :delayed end end diff --git a/spec/workers/web_hooks/log_destroy_worker_spec.rb b/spec/workers/web_hooks/log_destroy_worker_spec.rb index 0c107c05360..8c7d29d559d 100644 --- a/spec/workers/web_hooks/log_destroy_worker_spec.rb +++ b/spec/workers/web_hooks/log_destroy_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe WebHooks::LogDestroyWorker do +RSpec.describe WebHooks::LogDestroyWorker, feature_category: :integrations do include AfterNextHelpers let_it_be(:project) { create(:project) } diff --git a/spec/workers/work_items/import_work_items_csv_worker_spec.rb b/spec/workers/work_items/import_work_items_csv_worker_spec.rb new file mode 100644 index 00000000000..056960fbcf2 --- /dev/null +++ b/spec/workers/work_items/import_work_items_csv_worker_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe WorkItems::ImportWorkItemsCsvWorker, feature_category: :team_planning do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + let(:upload) { create(:upload, :with_file) } + + before_all do + project.add_reporter(user) + end + + subject { described_class.new.perform(user.id, project.id, upload.id) } + + describe '#perform' do + it 'calls #execute on WorkItems::ImportCsvService and destroys upload' do + expect_next_instance_of(WorkItems::ImportCsvService) do |instance| + expect(instance).to receive(:execute).and_return({ success: 5, error_lines: [], parse_error: false }) + end + + subject + + expect { upload.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [user.id, project.id, upload.id] } + end + end + + describe '.sidekiq_retries_exhausted' do + let_it_be(:job) { { 'args' => [user.id, project.id, create(:upload, :with_file).id] } } + + subject(:sidekiq_retries_exhausted) do + described_class.sidekiq_retries_exhausted_block.call(job) + end + + it 'destroys upload' do + expect { sidekiq_retries_exhausted }.to change { Upload.count }.by(-1) + end + end +end diff --git a/spec/workers/x509_certificate_revoke_worker_spec.rb b/spec/workers/x509_certificate_revoke_worker_spec.rb index 392cb52d084..badeff25b34 100644 --- a/spec/workers/x509_certificate_revoke_worker_spec.rb +++ b/spec/workers/x509_certificate_revoke_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe X509CertificateRevokeWorker do +RSpec.describe X509CertificateRevokeWorker, feature_category: :source_code_management do describe '#perform' do context 'with a revoked certificate' do subject { described_class.new } diff --git a/spec/workers/x509_issuer_crl_check_worker_spec.rb b/spec/workers/x509_issuer_crl_check_worker_spec.rb index 5564147d274..55e2e8d335d 100644 --- a/spec/workers/x509_issuer_crl_check_worker_spec.rb +++ b/spec/workers/x509_issuer_crl_check_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe X509IssuerCrlCheckWorker do +RSpec.describe X509IssuerCrlCheckWorker, feature_category: :source_code_management do subject(:worker) { described_class.new } let(:project) { create(:project, :public, :repository) } |