diff options
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index b9e331affb1..ae3725a0b08 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1328,11 +1328,34 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep, feature_category: %w[succeed! drop! cancel! skip! block! delay!].each do |action| context "when the pipeline received #{action} event" do - it 'deletes a persistent ref' do - expect(pipeline.persistent_ref).to receive(:delete).once + it 'deletes a persistent ref asynchronously', :sidekiq_inline do + expect(pipeline.persistent_ref).not_to receive(:delete_refs) + + expect(Ci::PipelineCleanupRefWorker).to receive(:perform_async) + .with(pipeline.id).and_call_original + + expect_next_instance_of(Ci::PersistentRef) do |persistent_ref| + expect(persistent_ref).to receive(:delete_refs) + .with("refs/#{Repository::REF_PIPELINES}/#{pipeline.id}").once + end pipeline.public_send(action) end + + context 'when pipeline_cleanup_ref_worker_async is disabled' do + before do + stub_feature_flags(pipeline_cleanup_ref_worker_async: false) + end + + it 'deletes a persistent ref synchronously' do + expect(Ci::PipelineCleanupRefWorker).not_to receive(:perform_async).with(pipeline.id) + + expect(pipeline.persistent_ref).to receive(:delete_refs).once + .with("refs/#{Repository::REF_PIPELINES}/#{pipeline.id}") + + pipeline.public_send(action) + end + end end end @@ -5323,7 +5346,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep, feature_category: it 'raises an exception' do pipeline.save! - pipeline_id = Ci::Pipeline.where(id: pipeline.id).select(:id).first + pipeline_id = described_class.where(id: pipeline.id).select(:id).first expect { pipeline_id.age_in_minutes }.to raise_error(ArgumentError) end |