summaryrefslogtreecommitdiff
path: root/spec/services/ci
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-10 23:13:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-10 23:13:44 +0000
commit63f0bc0999ba2c4a7778097aacc6b87efd39e9e6 (patch)
tree6a75a0a171089fae908f43b5ba61ca7c648862b5 /spec/services/ci
parentefdc7889a59a7e5a52f8bacb578de2d40beb5871 (diff)
downloadgitlab-ce-63f0bc0999ba2c4a7778097aacc6b87efd39e9e6.tar.gz
Add latest changes from gitlab-org/security/gitlab@13-8-stable-ee
Diffstat (limited to 'spec/services/ci')
-rw-r--r--spec/services/ci/abort_project_pipelines_service_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/services/ci/abort_project_pipelines_service_spec.rb b/spec/services/ci/abort_project_pipelines_service_spec.rb
new file mode 100644
index 00000000000..9af909ac2ab
--- /dev/null
+++ b/spec/services/ci/abort_project_pipelines_service_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::AbortProjectPipelinesService do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:pipeline) { create(:ci_pipeline, :running, project: project) }
+ let_it_be(:build) { create(:ci_build, :running, pipeline: pipeline) }
+
+ describe '#execute' do
+ it 'cancels all running pipelines and related jobs' do
+ result = described_class.new.execute(project)
+
+ expect(result).to be_success
+ expect(pipeline.reload).to be_canceled
+ expect(build.reload).to be_canceled
+ end
+
+ it 'avoids N+1 queries' do
+ control_count = ActiveRecord::QueryRecorder.new { described_class.new.execute(project) }.count
+
+ pipelines = create_list(:ci_pipeline, 5, :running, project: project)
+ create_list(:ci_build, 5, :running, pipeline: pipelines.first)
+
+ expect { described_class.new.execute(project) }.not_to exceed_query_limit(control_count)
+ end
+ end
+
+ context 'when feature disabled' do
+ before do
+ stub_feature_flags(abort_deleted_project_pipelines: false)
+ end
+
+ it 'does not abort the pipeline' do
+ result = described_class.new.execute(project)
+
+ expect(result).to be(nil)
+ expect(pipeline.reload).to be_running
+ expect(build.reload).to be_running
+ end
+ end
+end