diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-24 15:08:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-24 15:08:03 +0300 |
commit | 054056544fc9a6d65858cac7379733f6a7e8a9a6 (patch) | |
tree | e402b0d93ebfbff24edff8d88cb13dfc096156b2 /spec/workers | |
parent | 0f7c78619549f1f9026300da7955f796c9891f99 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/ci/pipeline_cleanup_ref_worker_spec.rb | 61 | ||||
-rw-r--r-- | spec/workers/every_sidekiq_worker_spec.rb | 1 |
2 files changed, 62 insertions, 0 deletions
diff --git a/spec/workers/ci/pipeline_cleanup_ref_worker_spec.rb b/spec/workers/ci/pipeline_cleanup_ref_worker_spec.rb new file mode 100644 index 00000000000..2913412abcd --- /dev/null +++ b/spec/workers/ci/pipeline_cleanup_ref_worker_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::PipelineCleanupRefWorker, :sidekiq_inline, feature_category: :continuous_integration do + include ExclusiveLeaseHelpers + + let_it_be(:pipeline) { create(:ci_pipeline, :success) } + + let(:worker) { described_class.new } + + subject { worker.perform(pipeline.id) } + + it 'does remove persistent ref' do + expect_next_instance_of(Ci::PersistentRef) do |persistent_ref| + expect(persistent_ref).to receive(:delete).once + end + + subject + end + + context 'when pipeline is still running' do + let_it_be(:pipeline) { create(:ci_pipeline, :running) } + + it 'does not remove persistent ref' do + expect_next_instance_of(Ci::PersistentRef) do |persistent_ref| + expect(persistent_ref).not_to receive(:delete) + end + + subject + end + end + + context 'when pipeline status changes while being locked' do + let_it_be(:pipeline) { create(:ci_pipeline, :success) } + + it 'does not remove persistent ref' do + expect_next_instance_of(Ci::PersistentRef) do |persistent_ref| + expect(persistent_ref).not_to receive(:delete_refs) + end + + expect(worker).to receive(:in_lock).and_wrap_original do |method, *args, &block| + pipeline.run! + + method.call(*args, &block) + end + + subject + end + end + + context 'when max retry attempts reach' do + let(:lease_key) { "#{described_class.name.underscore}/#{pipeline.project_id}" } + let!(:lease) { stub_exclusive_lease_taken(lease_key) } + + it 'does not raise error' do + expect(lease).to receive(:try_obtain).exactly(described_class::LOCK_RETRY + 1).times + expect { subject }.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError) + end + end +end diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb index cf1667cb0ff..19a82b4c13c 100644 --- a/spec/workers/every_sidekiq_worker_spec.rb +++ b/spec/workers/every_sidekiq_worker_spec.rb @@ -165,6 +165,7 @@ RSpec.describe 'Every Sidekiq worker', feature_category: :shared do 'Ci::Llm::GenerateConfigWorker' => 3, 'Ci::PipelineArtifacts::CoverageReportWorker' => 3, 'Ci::PipelineArtifacts::CreateQualityReportWorker' => 3, + 'Ci::PipelineCleanupRefWorker' => 3, 'Ci::PipelineBridgeStatusWorker' => 3, 'Ci::PipelineSuccessUnlockArtifactsWorker' => 3, 'Ci::RefDeleteUnlockArtifactsWorker' => 3, |