Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/ci/cancel_redundant_pipelines_worker_spec.rb')
-rw-r--r--spec/workers/ci/cancel_redundant_pipelines_worker_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/workers/ci/cancel_redundant_pipelines_worker_spec.rb b/spec/workers/ci/cancel_redundant_pipelines_worker_spec.rb
new file mode 100644
index 00000000000..f6639faab10
--- /dev/null
+++ b/spec/workers/ci/cancel_redundant_pipelines_worker_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::CancelRedundantPipelinesWorker, feature_category: :continuous_integration do
+ let_it_be(:project) { create(:project) }
+
+ let(:prev_pipeline) { create(:ci_pipeline, project: project) }
+ let(:pipeline) { create(:ci_pipeline, project: project) }
+
+ describe '#perform' do
+ subject(:perform) { described_class.new.perform(pipeline.id) }
+
+ let(:service) { instance_double('Ci::PipelineCreation::CancelRedundantPipelinesService') }
+
+ it 'calls cancel redundant pipeline service' do
+ expect(Ci::PipelineCreation::CancelRedundantPipelinesService)
+ .to receive(:new)
+ .with(pipeline)
+ .and_return(service)
+
+ expect(service).to receive(:execute)
+
+ perform
+ end
+
+ context 'if pipeline is deleted' do
+ subject(:perform) { described_class.new.perform(non_existing_record_id) }
+
+ it 'does not call redundant pipeline service' do
+ expect(Ci::PipelineCreation::CancelRedundantPipelinesService)
+ .not_to receive(:new)
+
+ perform
+ end
+ end
+
+ describe 'interacting with previous pending pipelines', :sidekiq_inline do
+ before do
+ create(:ci_build, :interruptible, :running, pipeline: prev_pipeline)
+ end
+
+ it_behaves_like 'an idempotent worker', :sidekiq_inline do
+ let(:job_args) { pipeline }
+
+ it 'cancels the previous pending pipeline' do
+ perform
+
+ expect(prev_pipeline.builds.pluck(:status)).to contain_exactly('canceled')
+ end
+ end
+ end
+ end
+end