diff options
Diffstat (limited to 'spec/workers')
28 files changed, 368 insertions, 105 deletions
diff --git a/spec/workers/deployments/finished_worker_spec.rb b/spec/workers/deployments/finished_worker_spec.rb index 9b4bd78c03a..e1ec2d89e0a 100644 --- a/spec/workers/deployments/finished_worker_spec.rb +++ b/spec/workers/deployments/finished_worker_spec.rb @@ -49,5 +49,29 @@ RSpec.describe Deployments::FinishedWorker do expect(ProjectServiceWorker).not_to have_received(:perform_async) end + + it 'execute webhooks' do + deployment = create(:deployment) + project = deployment.project + web_hook = create(:project_hook, deployment_events: true, project: project) + + expect_next_instance_of(WebHookService, web_hook, an_instance_of(Hash), "deployment_hooks") do |service| + expect(service).to receive(:async_execute) + end + + worker.perform(deployment.id) + end + + it 'does not execute webhooks if feature flag is disabled' do + stub_feature_flags(deployment_webhooks: false) + + deployment = create(:deployment) + project = deployment.project + create(:project_hook, deployment_events: true, project: project) + + expect(WebHookService).not_to receive(:new) + + worker.perform(deployment.id) + end end end diff --git a/spec/workers/flush_counter_increments_worker_spec.rb b/spec/workers/flush_counter_increments_worker_spec.rb new file mode 100644 index 00000000000..14b49b97ac3 --- /dev/null +++ b/spec/workers/flush_counter_increments_worker_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe FlushCounterIncrementsWorker, :counter_attribute do + let(:project_statistics) { create(:project_statistics) } + let(:model) { CounterAttributeModel.find(project_statistics.id) } + + describe '#perform', :redis do + let(:attribute) { model.class.counter_attributes.first } + let(:worker) { described_class.new } + + subject { worker.perform(model.class.name, model.id, attribute) } + + it 'flushes increments to database' do + expect(model.class).to receive(:find_by_id).and_return(model) + expect(model) + .to receive(:flush_increments_to_database!) + .with(attribute) + .and_call_original + + subject + end + + context 'when model class does not exist' do + subject { worker.perform('non-existend-model') } + + it 'does nothing' do + expect(worker).not_to receive(:in_lock) + end + end + + context 'when record does not exist' do + subject { worker.perform(model.class.name, model.id + 100, attribute) } + + it 'does nothing' do + expect(worker).not_to receive(:in_lock) + end + end + end +end diff --git a/spec/workers/git_garbage_collect_worker_spec.rb b/spec/workers/git_garbage_collect_worker_spec.rb index cb6396e2859..223f5aea813 100644 --- a/spec/workers/git_garbage_collect_worker_spec.rb +++ b/spec/workers/git_garbage_collect_worker_spec.rb @@ -7,35 +7,61 @@ require 'spec_helper' RSpec.describe GitGarbageCollectWorker do include GitHelpers - let(:project) { create(:project, :repository) } + let_it_be(:project) { create(:project, :repository) } let(:shell) { Gitlab::Shell.new } let!(:lease_uuid) { SecureRandom.uuid } let!(:lease_key) { "project_housekeeping:#{project.id}" } + let(:params) { [project.id, task, lease_key, lease_uuid] } subject { described_class.new } + shared_examples 'it calls Gitaly' do + specify do + expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(gitaly_task) + .and_return(nil) + + subject.perform(*params) + end + end + + shared_examples 'it updates the project statistics' do + specify do + expect_any_instance_of(Projects::UpdateStatisticsService).to receive(:execute).and_call_original + expect(Projects::UpdateStatisticsService) + .to receive(:new) + .with(project, nil, statistics: [:repository_size, :lfs_objects_size]) + .and_call_original + + subject.perform(*params) + end + end + describe "#perform" do + let(:gitaly_task) { :garbage_collect } + let(:task) { :gc } + context 'with active lease_uuid' do before do allow(subject).to receive(:get_lease_uuid).and_return(lease_uuid) end + it_behaves_like 'it calls Gitaly' + it_behaves_like 'it updates the project statistics' + it "flushes ref caches when the task if 'gc'" do expect(subject).to receive(:renew_lease).with(lease_key, lease_uuid).and_call_original - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:garbage_collect) - .and_return(nil) expect_any_instance_of(Repository).to receive(:after_create_branch).and_call_original expect_any_instance_of(Repository).to receive(:branch_names).and_call_original expect_any_instance_of(Repository).to receive(:has_visible_content?).and_call_original expect_any_instance_of(Gitlab::Git::Repository).to receive(:has_visible_content?).and_call_original - subject.perform(project.id, :gc, lease_key, lease_uuid) + subject.perform(*params) end it 'handles gRPC errors' do expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:garbage_collect).and_raise(GRPC::NotFound) - expect { subject.perform(project.id, :gc, lease_key, lease_uuid) }.to raise_exception(Gitlab::Git::Repository::NoRepository) + expect { subject.perform(*params) }.to raise_exception(Gitlab::Git::Repository::NoRepository) end end @@ -49,11 +75,13 @@ RSpec.describe GitGarbageCollectWorker do expect_any_instance_of(Repository).not_to receive(:branch_names).and_call_original expect_any_instance_of(Repository).not_to receive(:has_visible_content?).and_call_original - subject.perform(project.id, :gc, lease_key, lease_uuid) + subject.perform(*params) end end context 'with no active lease' do + let(:params) { [project.id] } + before do allow(subject).to receive(:get_lease_uuid).and_return(false) end @@ -63,15 +91,17 @@ RSpec.describe GitGarbageCollectWorker do allow(subject).to receive(:try_obtain_lease).and_return(SecureRandom.uuid) end + it_behaves_like 'it calls Gitaly' + it_behaves_like 'it updates the project statistics' + it "flushes ref caches when the task if 'gc'" do - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:garbage_collect) - .and_return(nil) + expect(subject).to receive(:get_lease_uuid).with("git_gc:#{task}:#{project.id}").and_return(false) expect_any_instance_of(Repository).to receive(:after_create_branch).and_call_original expect_any_instance_of(Repository).to receive(:branch_names).and_call_original expect_any_instance_of(Repository).to receive(:has_visible_content?).and_call_original expect_any_instance_of(Gitlab::Git::Repository).to receive(:has_visible_content?).and_call_original - subject.perform(project.id) + subject.perform(*params) end context 'when the repository has joined a pool' do @@ -81,7 +111,57 @@ RSpec.describe GitGarbageCollectWorker do it 'ensures the repositories are linked' do expect_any_instance_of(PoolRepository).to receive(:link_repository).once - subject.perform(project.id) + subject.perform(*params) + end + end + + context 'LFS object garbage collection' do + before do + stub_lfs_setting(enabled: true) + end + + let_it_be(:lfs_reference) { create(:lfs_objects_project, project: project) } + let(:lfs_object) { lfs_reference.lfs_object } + + context 'with cleanup_lfs_during_gc feature flag enabled' do + before do + stub_feature_flags(cleanup_lfs_during_gc: true) + end + + it 'cleans up unreferenced LFS objects' do + expect_next_instance_of(Gitlab::Cleanup::OrphanLfsFileReferences) do |svc| + expect(svc.project).to eq(project) + expect(svc.dry_run).to be_falsy + expect(svc).to receive(:run!).and_call_original + end + + subject.perform(*params) + + expect(project.lfs_objects.reload).not_to include(lfs_object) + end + + it 'does nothing if the database is read-only' do + expect(Gitlab::Database).to receive(:read_only?) { true } + expect_any_instance_of(Gitlab::Cleanup::OrphanLfsFileReferences).not_to receive(:run!) + + subject.perform(*params) + + expect(project.lfs_objects.reload).to include(lfs_object) + end + end + + context 'with cleanup_lfs_during_gc feature flag disabled' do + before do + stub_feature_flags(cleanup_lfs_during_gc: false) + end + + it 'does not clean up unreferenced LFS objects' do + expect_any_instance_of(Gitlab::Cleanup::OrphanLfsFileReferences).not_to receive(:run!) + + subject.perform(*params) + + expect(project.lfs_objects.reload).to include(lfs_object) + end end end end @@ -97,48 +177,55 @@ RSpec.describe GitGarbageCollectWorker do expect_any_instance_of(Repository).not_to receive(:branch_names).and_call_original expect_any_instance_of(Repository).not_to receive(:has_visible_content?).and_call_original - subject.perform(project.id) + subject.perform(*params) end end end context "repack_full" do + let(:task) { :full_repack } + let(:gitaly_task) { :repack_full } + before do expect(subject).to receive(:get_lease_uuid).and_return(lease_uuid) end - it "calls Gitaly" do - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:repack_full) - .and_return(nil) - - subject.perform(project.id, :full_repack, lease_key, lease_uuid) - end + it_behaves_like 'it calls Gitaly' + it_behaves_like 'it updates the project statistics' end context "pack_refs" do + let(:task) { :pack_refs } + let(:gitaly_task) { :pack_refs } + before do expect(subject).to receive(:get_lease_uuid).and_return(lease_uuid) end it "calls Gitaly" do - expect_any_instance_of(Gitlab::GitalyClient::RefService).to receive(:pack_refs) + expect_any_instance_of(Gitlab::GitalyClient::RefService).to receive(task) .and_return(nil) - subject.perform(project.id, :pack_refs, lease_key, lease_uuid) + subject.perform(*params) + end + + it 'does not update the project statistics' do + expect(Projects::UpdateStatisticsService).not_to receive(:new) + + subject.perform(*params) end end context "repack_incremental" do + let(:task) { :incremental_repack } + let(:gitaly_task) { :repack_incremental } + before do expect(subject).to receive(:get_lease_uuid).and_return(lease_uuid) end - it "calls Gitaly" do - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:repack_incremental) - .and_return(nil) - - subject.perform(project.id, :incremental_repack, lease_key, lease_uuid) - end + it_behaves_like 'it calls Gitaly' + it_behaves_like 'it updates the project statistics' end shared_examples 'gc tasks' 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 510c41cba21..d12d5a605a7 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 @@ -10,7 +10,7 @@ RSpec.describe Gitlab::Import::StuckProjectImportJobsWorker do let(:import_state) { create(:project, :import_scheduled).import_state } before do - import_state.update(jid: '123') + import_state.update!(jid: '123') end end end @@ -20,7 +20,7 @@ RSpec.describe Gitlab::Import::StuckProjectImportJobsWorker do let(:import_state) { create(:project, :import_started).import_state } before do - import_state.update(jid: '123') + import_state.update!(jid: '123') end end end 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 4a4ef5700fa..324e8010887 100644 --- a/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/jira_import/import_issue_worker_spec.rb @@ -24,7 +24,8 @@ RSpec.describe Gitlab::JiraImport::ImportIssueWorker do build(:issue, project_id: project.id, title: 'jira issue') .as_json.merge( 'label_ids' => [jira_issue_label_1.id, jira_issue_label_2.id], 'assignee_ids' => assignee_ids - ).compact + ).except('issue_type') + .compact end context 'when any exception raised while inserting to DB' do 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 8271af4db2f..7f1cb8a2076 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 @@ -12,7 +12,7 @@ RSpec.describe ::Gitlab::JiraImport::StuckJiraImportJobsWorker do let(:import_state) { create(:jira_import_state, :scheduled, project: project) } before do - import_state.update(jid: '123') + import_state.update!(jid: '123') end end end @@ -22,7 +22,7 @@ RSpec.describe ::Gitlab::JiraImport::StuckJiraImportJobsWorker do let(:import_state) { create(:jira_import_state, :started, project: project) } before do - import_state.update(jid: '123') + import_state.update!(jid: '123') end end end diff --git a/spec/workers/gitlab_usage_ping_worker_spec.rb b/spec/workers/gitlab_usage_ping_worker_spec.rb index 05d6f2e585b..a180d29fd5f 100644 --- a/spec/workers/gitlab_usage_ping_worker_spec.rb +++ b/spec/workers/gitlab_usage_ping_worker_spec.rb @@ -2,16 +2,42 @@ require 'spec_helper' -RSpec.describe GitlabUsagePingWorker do - subject { described_class.new } +RSpec.describe GitlabUsagePingWorker, :clean_gitlab_redis_shared_state do + before do + allow_next_instance_of(SubmitUsagePingService) { |service| allow(service).to receive(:execute) } + allow(subject).to receive(:sleep) + end it 'delegates to SubmitUsagePingService' do - allow(subject).to receive(:try_obtain_lease).and_return(true) + expect_next_instance_of(SubmitUsagePingService) { |service| expect(service).to receive(:execute) } - expect_next_instance_of(SubmitUsagePingService) do |instance| - expect(instance).to receive(:execute) - end + subject.perform + end + + it "obtains a #{described_class::LEASE_TIMEOUT} second exclusive lease" do + expect(Gitlab::ExclusiveLeaseHelpers::SleepingLock) + .to receive(:new) + .with(described_class::LEASE_KEY, hash_including(timeout: described_class::LEASE_TIMEOUT)) + .and_call_original subject.perform end + + it 'sleeps for between 0 and 60 seconds' do + expect(subject).to receive(:sleep).with(0..60) + + subject.perform + end + + context 'when lease is not obtained' do + before do + Gitlab::ExclusiveLease.new(described_class::LEASE_KEY, timeout: described_class::LEASE_TIMEOUT).try_obtain + end + + it 'does not invoke SubmitUsagePingService' do + allow_next_instance_of(SubmitUsagePingService) { |service| expect(service).not_to receive(:execute) } + + expect { subject.perform }.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError) + end + end end diff --git a/spec/workers/incident_management/process_alert_worker_spec.rb b/spec/workers/incident_management/process_alert_worker_spec.rb index bed6dc59ac7..20ab283b49b 100644 --- a/spec/workers/incident_management/process_alert_worker_spec.rb +++ b/spec/workers/incident_management/process_alert_worker_spec.rb @@ -18,15 +18,15 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do before do allow(Gitlab::AppLogger).to receive(:warn).and_call_original - allow(IncidentManagement::CreateIssueService) - .to receive(:new).with(alert.project, parsed_payload) + allow(AlertManagement::CreateAlertIssueService) + .to receive(:new).with(alert, User.alert_bot) .and_call_original end shared_examples 'creates issue successfully' do it 'creates an issue' do - expect(IncidentManagement::CreateIssueService) - .to receive(:new).with(alert.project, parsed_payload) + expect(AlertManagement::CreateAlertIssueService) + .to receive(:new).with(alert, User.alert_bot) expect { subject }.to change { Issue.count }.by(1) end @@ -58,10 +58,10 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do subject expect(Gitlab::AppLogger).to have_received(:warn).with( - message: 'Cannot link an Issue with Alert', + message: 'Cannot process an Incident', issue_id: created_issue.id, alert_id: alert.id, - alert_errors: { hosts: ['hosts array is over 255 chars'] } + errors: 'Hosts hosts array is over 255 chars' ) end end @@ -80,7 +80,7 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do subject { described_class.new.perform(nil, nil, invalid_alert_id) } it 'does not create issues' do - expect(IncidentManagement::CreateIssueService).not_to receive(:new) + expect(AlertManagement::CreateAlertIssueService).not_to receive(:new) expect { subject }.not_to change { Issue.count } end diff --git a/spec/workers/migrate_external_diffs_worker_spec.rb b/spec/workers/migrate_external_diffs_worker_spec.rb index 86d4680acbe..36669b4e694 100644 --- a/spec/workers/migrate_external_diffs_worker_spec.rb +++ b/spec/workers/migrate_external_diffs_worker_spec.rb @@ -17,7 +17,7 @@ RSpec.describe MigrateExternalDiffsWorker do end it 'does nothing if the diff is missing' do - diff.destroy + diff.destroy! worker.perform(diff.id) end diff --git a/spec/workers/namespaceless_project_destroy_worker_spec.rb b/spec/workers/namespaceless_project_destroy_worker_spec.rb index ef396bc7fbb..618cd9cabe9 100644 --- a/spec/workers/namespaceless_project_destroy_worker_spec.rb +++ b/spec/workers/namespaceless_project_destroy_worker_spec.rb @@ -60,7 +60,7 @@ RSpec.describe NamespacelessProjectDestroyWorker do let!(:parent_project) { create(:project) } let(:project) do namespaceless_project = fork_project(parent_project) - namespaceless_project.save + namespaceless_project.save! namespaceless_project end diff --git a/spec/workers/namespaces/root_statistics_worker_spec.rb b/spec/workers/namespaces/root_statistics_worker_spec.rb index 0c6e3e89973..a97a850bbcf 100644 --- a/spec/workers/namespaces/root_statistics_worker_spec.rb +++ b/spec/workers/namespaces/root_statistics_worker_spec.rb @@ -51,7 +51,7 @@ RSpec.describe Namespaces::RootStatisticsWorker, '#perform' do context 'with no namespace' do before do - group.destroy + group.destroy! end it 'does not execute the refresher service' do @@ -64,7 +64,7 @@ RSpec.describe Namespaces::RootStatisticsWorker, '#perform' do context 'with a namespace with no aggregation scheduled' do before do - group.aggregation_schedule.destroy + group.aggregation_schedule.destroy! end it 'does not execute the refresher service' 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 7c745e51df5..dac8c529984 100644 --- a/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb +++ b/spec/workers/pages_domain_ssl_renewal_cron_worker_spec.rb @@ -18,9 +18,11 @@ RSpec.describe PagesDomainSslRenewalCronWorker do let!(:domain_with_obtained_letsencrypt) do create(:pages_domain, :letsencrypt, project: project, auto_ssl_enabled: true) end + let!(:domain_without_auto_certificate) do create(:pages_domain, :without_certificate, :without_key, project: project, auto_ssl_enabled: true) end + let!(:domain_with_failed_auto_ssl) do create(:pages_domain, :without_certificate, :without_key, project: project, auto_ssl_enabled: true, auto_ssl_failed: true) diff --git a/spec/workers/pages_domain_verification_worker_spec.rb b/spec/workers/pages_domain_verification_worker_spec.rb index 74b9730f7c1..6d2f9ee2f8d 100644 --- a/spec/workers/pages_domain_verification_worker_spec.rb +++ b/spec/workers/pages_domain_verification_worker_spec.rb @@ -16,7 +16,7 @@ RSpec.describe PagesDomainVerificationWorker do end it 'does nothing for a non-existent domain' do - domain.destroy + domain.destroy! expect(VerifyPagesDomainService).not_to receive(:new) diff --git a/spec/workers/pages_update_configuration_worker_spec.rb b/spec/workers/pages_update_configuration_worker_spec.rb new file mode 100644 index 00000000000..890b39b22a5 --- /dev/null +++ b/spec/workers/pages_update_configuration_worker_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true +require "spec_helper" + +RSpec.describe PagesUpdateConfigurationWorker do + describe "#perform" do + let_it_be(:project) { create(:project) } + + it "does not break if the project doesn't exist" do + expect { subject.perform(-1) }.not_to raise_error + end + + it "calls the correct service" do + expect_next_instance_of(Projects::UpdatePagesConfigurationService, project) do |service| + expect(service).to receive(:execute).and_return({}) + end + + subject.perform(project.id) + end + + it "raises an exception if the service returned an error" do + allow_next_instance_of(Projects::UpdatePagesConfigurationService) do |service| + allow(service).to receive(:execute).and_return({ exception: ":boom:" }) + end + + expect { subject.perform(project.id) }.to raise_error(":boom:") + end + + it_behaves_like "an idempotent worker" do + let(:job_args) { [project.id] } + let(:pages_dir) { Dir.mktmpdir } + let(:config_path) { File.join(pages_dir, "config.json") } + + before do + allow(Project).to receive(:find_by_id).with(project.id).and_return(project) + allow(project).to receive(:pages_path).and_return(pages_dir) + + # Make sure _some_ config exists + FileUtils.touch(config_path) + end + + after do + FileUtils.remove_entry(pages_dir) + end + + it "only updates the config file once" do + described_class.new.perform(project.id) + + expect(File.mtime(config_path)).not_to be_nil + expect { subject }.not_to change { File.mtime(config_path) } + end + end + end +end diff --git a/spec/workers/personal_access_tokens/expired_notification_worker_spec.rb b/spec/workers/personal_access_tokens/expired_notification_worker_spec.rb new file mode 100644 index 00000000000..676a419553f --- /dev/null +++ b/spec/workers/personal_access_tokens/expired_notification_worker_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe PersonalAccessTokens::ExpiredNotificationWorker, type: :worker do + subject(:worker) { described_class.new } + + describe '#perform' do + context 'when a token has expired' do + let(:expired_today) { create(:personal_access_token, expires_at: Date.current) } + + context 'when feature is enabled' do + it 'uses notification service to send email to the user' do + expect_next_instance_of(NotificationService) do |notification_service| + expect(notification_service).to receive(:access_token_expired).with(expired_today.user) + end + + worker.perform + end + + it 'updates notified column' do + expect { worker.perform }.to change { expired_today.reload.after_expiry_notification_delivered }.from(false).to(true) + end + end + + context 'when feature is disabled' do + before do + stub_feature_flags(expired_pat_email_notification: false) + end + + it 'does not update notified column' do + expect { worker.perform }.not_to change { expired_today.reload.after_expiry_notification_delivered } + end + + it 'does not trigger email' do + expect { worker.perform }.not_to change { ActionMailer::Base.deliveries.count } + end + end + end + + shared_examples 'expiry notification is not required to be sent for the token' do + it do + expect_next_instance_of(NotificationService) do |notification_service| + expect(notification_service).not_to receive(:access_token_expired).with(token.user) + end + + worker.perform + end + end + + context 'when token has expired in the past' do + let(:token) { create(:personal_access_token, expires_at: Date.yesterday) } + + it_behaves_like 'expiry notification is not required to be sent for the token' + end + + context 'when token is impersonated' do + let(:token) { create(:personal_access_token, expires_at: Date.current, impersonation: true) } + + it_behaves_like 'expiry notification is not required to be sent for the token' + end + + context 'when token is revoked' do + let(:token) { create(:personal_access_token, expires_at: Date.current, revoked: true) } + + it_behaves_like 'expiry notification is not required to be sent for the token' + end + end +end diff --git a/spec/workers/pipeline_process_worker_spec.rb b/spec/workers/pipeline_process_worker_spec.rb index a6e6b505a38..5d45a131095 100644 --- a/spec/workers/pipeline_process_worker_spec.rb +++ b/spec/workers/pipeline_process_worker_spec.rb @@ -12,17 +12,6 @@ RSpec.describe PipelineProcessWorker do described_class.new.perform(pipeline.id) end - - context 'when build_ids are passed' do - let(:build) { create(:ci_build, pipeline: pipeline, name: 'my-build') } - - it 'processes pipeline with a list of builds' do - expect_any_instance_of(Ci::ProcessPipelineService).to receive(:execute) - .with([build.id]) - - described_class.new.perform(pipeline.id, [build.id]) - end - end end context 'when pipeline does not exist' do diff --git a/spec/workers/pipeline_update_worker_spec.rb b/spec/workers/pipeline_update_worker_spec.rb deleted file mode 100644 index c5c1cc0eefd..00000000000 --- a/spec/workers/pipeline_update_worker_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe PipelineUpdateWorker do - describe '#perform' do - context 'when pipeline exists' do - let(:pipeline) { create(:ci_pipeline) } - - it 'updates pipeline status' do - expect_any_instance_of(Ci::Pipeline).to receive(:set_status).with('skipped') - - described_class.new.perform(pipeline.id) - end - - include_examples 'an idempotent worker' do - let(:job_args) { [pipeline.id] } - - it 'sets pipeline status to skipped' do - expect { subject }.to change { pipeline.reload.status }.from('pending').to('skipped') - end - end - end - - context 'when pipeline does not exist' do - it 'does not raise exception' do - expect { described_class.new.perform(123) } - .not_to raise_error - end - end - end -end diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index a33ee6e1da5..7a168bf054e 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -160,7 +160,7 @@ RSpec.describe ProcessCommitWorker do context 'when issue has first_mentioned_in_commit_at earlier than given committed_date' do before do - issue.metrics.update(first_mentioned_in_commit_at: commit.committed_date - 1.day) + issue.metrics.update!(first_mentioned_in_commit_at: commit.committed_date - 1.day) end it "doesn't update issue metrics" do @@ -170,7 +170,7 @@ RSpec.describe ProcessCommitWorker do context 'when issue has first_mentioned_in_commit_at later than given committed_date' do before do - issue.metrics.update(first_mentioned_in_commit_at: commit.committed_date + 1.day) + issue.metrics.update!(first_mentioned_in_commit_at: commit.committed_date + 1.day) end it "doesn't update issue metrics" do diff --git a/spec/workers/propagate_integration_worker_spec.rb b/spec/workers/propagate_integration_worker_spec.rb index a0fdd37b3c0..3fe76f14750 100644 --- a/spec/workers/propagate_integration_worker_spec.rb +++ b/spec/workers/propagate_integration_worker_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe PropagateIntegrationWorker do describe '#perform' do let(:integration) do - PushoverService.create( + PushoverService.create!( template: true, active: true, device: 'MyDevice', diff --git a/spec/workers/propagate_service_template_worker_spec.rb b/spec/workers/propagate_service_template_worker_spec.rb index 4cba313a23f..48151b25d4b 100644 --- a/spec/workers/propagate_service_template_worker_spec.rb +++ b/spec/workers/propagate_service_template_worker_spec.rb @@ -7,7 +7,7 @@ RSpec.describe PropagateServiceTemplateWorker do describe '#perform' do it 'calls the propagate service with the template' do - template = PushoverService.create( + template = PushoverService.create!( template: true, active: true, properties: { diff --git a/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb b/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb index e716d4806d3..f14c2b67f2c 100644 --- a/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb +++ b/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb @@ -18,12 +18,14 @@ RSpec.describe RemoveUnreferencedLfsObjectsWorker do lfs_object: referenced_lfs_object1 ) end + let!(:lfs_objects_project2_1) do create(:lfs_objects_project, project: project2, lfs_object: referenced_lfs_object1 ) end + let!(:lfs_objects_project1_2) do create(:lfs_objects_project, project: project1, @@ -46,7 +48,7 @@ RSpec.describe RemoveUnreferencedLfsObjectsWorker do end it 'removes unreferenced lfs objects after project removal' do - project1.destroy + project1.destroy! worker.perform diff --git a/spec/workers/repository_check/single_repository_worker_spec.rb b/spec/workers/repository_check/single_repository_worker_spec.rb index 28e3f43d374..205d7c08f54 100644 --- a/spec/workers/repository_check/single_repository_worker_spec.rb +++ b/spec/workers/repository_check/single_repository_worker_spec.rb @@ -86,7 +86,7 @@ RSpec.describe RepositoryCheck::SingleRepositoryWorker do end def create_push_event(project) - project.events.create(action: :pushed, author_id: create(:user).id) + project.events.create!(action: :pushed, author_id: create(:user).id) end def break_wiki(project) diff --git a/spec/workers/repository_cleanup_worker_spec.rb b/spec/workers/repository_cleanup_worker_spec.rb index 41bfeabb7f3..f5887d08bd2 100644 --- a/spec/workers/repository_cleanup_worker_spec.rb +++ b/spec/workers/repository_cleanup_worker_spec.rb @@ -25,13 +25,13 @@ RSpec.describe RepositoryCleanupWorker do end it 'raises an error if the project cannot be found' do - project.destroy + project.destroy! expect { worker.perform(project.id, user.id) }.to raise_error(ActiveRecord::RecordNotFound) end it 'raises an error if the user cannot be found' do - user.destroy + user.destroy! expect { worker.perform(project.id, user.id) }.to raise_error(ActiveRecord::RecordNotFound) end diff --git a/spec/workers/repository_import_worker_spec.rb b/spec/workers/repository_import_worker_spec.rb index a2c19debdfd..4a80f4f9da6 100644 --- a/spec/workers/repository_import_worker_spec.rb +++ b/spec/workers/repository_import_worker_spec.rb @@ -49,7 +49,7 @@ RSpec.describe RepositoryImportWorker do it 'hide the credentials that were used in the import URL' do error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } - import_state.update(jid: '123') + import_state.update!(jid: '123') expect_next_instance_of(Projects::ImportService) do |instance| expect(instance).to receive(:execute).and_return({ status: :error, message: error }) end @@ -63,8 +63,8 @@ RSpec.describe RepositoryImportWorker do it 'updates the error on Import/Export' do error = %q{remote: Not Found fatal: repository 'https://user:pass@test.com/root/repoC.git/' not found } - project.update(import_type: 'gitlab_project') - import_state.update(jid: '123') + project.update!(import_type: 'gitlab_project') + import_state.update!(jid: '123') expect_next_instance_of(Projects::ImportService) do |instance| expect(instance).to receive(:execute).and_return({ status: :error, message: error }) end diff --git a/spec/workers/repository_update_remote_mirror_worker_spec.rb b/spec/workers/repository_update_remote_mirror_worker_spec.rb index 37eed57cf2e..c6e667097ec 100644 --- a/spec/workers/repository_update_remote_mirror_worker_spec.rb +++ b/spec/workers/repository_update_remote_mirror_worker_spec.rb @@ -26,7 +26,7 @@ RSpec.describe RepositoryUpdateRemoteMirrorWorker, :clean_gitlab_redis_shared_st end it 'does not do anything if the mirror was already updated' do - remote_mirror.update(last_update_started_at: Time.current, update_status: :finished) + remote_mirror.update!(last_update_started_at: Time.current, update_status: :finished) expect(Projects::UpdateRemoteMirrorService).not_to receive(:new) diff --git a/spec/workers/stuck_ci_jobs_worker_spec.rb b/spec/workers/stuck_ci_jobs_worker_spec.rb index b96d506771d..24d3b6fadf5 100644 --- a/spec/workers/stuck_ci_jobs_worker_spec.rb +++ b/spec/workers/stuck_ci_jobs_worker_spec.rb @@ -132,7 +132,7 @@ RSpec.describe StuckCiJobsWorker do let(:updated_at) { 2.days.ago } before do - job.project.update(pending_delete: true) + job.project.update!(pending_delete: true) end it 'does drop job' do 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 e6f4f415987..5ed600e308b 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 @@ -29,7 +29,7 @@ RSpec.describe UpdateHeadPipelineForMergeRequestWorker do context 'when merge request sha does not equal pipeline sha' do before do - merge_request.merge_request_diff.update(head_commit_sha: Digest::SHA1.hexdigest(SecureRandom.hex)) + merge_request.merge_request_diff.update!(head_commit_sha: Digest::SHA1.hexdigest(SecureRandom.hex)) end it 'does not update head pipeline' do diff --git a/spec/workers/update_highest_role_worker_spec.rb b/spec/workers/update_highest_role_worker_spec.rb index 19512fb0cfc..0c8ee53da9a 100644 --- a/spec/workers/update_highest_role_worker_spec.rb +++ b/spec/workers/update_highest_role_worker_spec.rb @@ -21,6 +21,7 @@ RSpec.describe UpdateHighestRoleWorker, :clean_gitlab_redis_shared_state do user_type: nil } end + let(:user) { create(:user, active_attributes) } subject { worker.perform(user.id) } |