summaryrefslogtreecommitdiff
path: root/spec/services/ci/create_pipeline_service
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/ci/create_pipeline_service')
-rw-r--r--spec/services/ci/create_pipeline_service/include_spec.rb46
-rw-r--r--spec/services/ci/create_pipeline_service/limit_active_jobs_spec.rb53
-rw-r--r--spec/services/ci/create_pipeline_service/logger_spec.rb1
-rw-r--r--spec/services/ci/create_pipeline_service/rules_spec.rb48
4 files changed, 58 insertions, 90 deletions
diff --git a/spec/services/ci/create_pipeline_service/include_spec.rb b/spec/services/ci/create_pipeline_service/include_spec.rb
index 67d8530525a..3764663fd74 100644
--- a/spec/services/ci/create_pipeline_service/include_spec.rb
+++ b/spec/services/ci/create_pipeline_service/include_spec.rb
@@ -126,51 +126,5 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it_behaves_like 'not including the file'
end
end
-
- context 'with ci_increase_includes_to_250 enabled on root project' do
- let_it_be(:included_project) do
- create(:project, :repository).tap { |p| p.add_developer(user) }
- end
-
- before do
- stub_const('::Gitlab::Ci::Config::External::Context::MAX_INCLUDES', 0)
- stub_const('::Gitlab::Ci::Config::External::Context::TRIAL_MAX_INCLUDES', 3)
-
- stub_feature_flags(ci_increase_includes_to_250: false)
- stub_feature_flags(ci_increase_includes_to_250: project)
-
- allow(Project)
- .to receive(:find_by_full_path)
- .with(included_project.full_path)
- .and_return(included_project)
-
- allow(included_project.repository)
- .to receive(:blob_data_at).with(included_project.commit.id, '.gitlab-ci.yml')
- .and_return(local_config)
-
- allow(included_project.repository)
- .to receive(:blob_data_at).with(included_project.commit.id, file_location)
- .and_return(File.read(Rails.root.join(file_location)))
- end
-
- let(:config) do
- <<~EOY
- include:
- - project: #{included_project.full_path}
- file: .gitlab-ci.yml
- EOY
- end
-
- let(:local_config) do
- <<~EOY
- include: #{file_location}
-
- job:
- script: exit 0
- EOY
- end
-
- it_behaves_like 'including the file'
- end
end
end
diff --git a/spec/services/ci/create_pipeline_service/limit_active_jobs_spec.rb b/spec/services/ci/create_pipeline_service/limit_active_jobs_spec.rb
new file mode 100644
index 00000000000..003d109a27c
--- /dev/null
+++ b/spec/services/ci/create_pipeline_service/limit_active_jobs_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectness do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:user) { project.first_owner }
+ let_it_be(:existing_pipeline) { create(:ci_pipeline, project: project) }
+
+ let(:service) { described_class.new(project, user, ref: 'refs/heads/master') }
+
+ subject(:pipeline) { service.execute(:push).payload }
+
+ before do
+ create_list(:ci_build, 8, pipeline: existing_pipeline)
+ create_list(:ci_bridge, 1, pipeline: existing_pipeline)
+
+ stub_ci_pipeline_yaml_file(<<~YAML)
+ job1:
+ script: echo
+ job3:
+ trigger:
+ project: org/my-project
+ job4:
+ script: echo
+ only: [tags]
+ YAML
+ end
+
+ context 'when project has exceeded the active jobs limit' do
+ before do
+ project.namespace.actual_limits.update!(ci_active_jobs: 10)
+ end
+
+ it 'fails the pipeline before populating it' do
+ expect(pipeline).to be_failed
+ expect(pipeline).to be_job_activity_limit_exceeded
+
+ expect(pipeline.errors.full_messages)
+ .to include("Project exceeded the allowed number of jobs in active pipelines. Retry later.")
+ expect(pipeline.statuses).to be_empty
+ end
+ end
+
+ context 'when project has not exceeded the active jobs limit' do
+ before do
+ project.namespace.actual_limits.update!(ci_active_jobs: 20)
+ end
+
+ it 'creates the pipeline successfully' do
+ expect(pipeline).to be_created
+ end
+ end
+end
diff --git a/spec/services/ci/create_pipeline_service/logger_spec.rb b/spec/services/ci/create_pipeline_service/logger_spec.rb
index 2be23802757..3045f8e92b1 100644
--- a/spec/services/ci/create_pipeline_service/logger_spec.rb
+++ b/spec/services/ci/create_pipeline_service/logger_spec.rb
@@ -20,6 +20,7 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
{
'count' => a_kind_of(Numeric),
'avg' => a_kind_of(Numeric),
+ 'sum' => a_kind_of(Numeric),
'max' => a_kind_of(Numeric),
'min' => a_kind_of(Numeric)
}
diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb
index fc57ca66d3a..c737b8cc329 100644
--- a/spec/services/ci/create_pipeline_service/rules_spec.rb
+++ b/spec/services/ci/create_pipeline_service/rules_spec.rb
@@ -540,19 +540,10 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
let(:compare_to) { 'invalid-branch' }
it 'returns an error' do
- expect(pipeline.errors.full_messages).to eq([
- 'Failed to parse rule for job1: rules:changes:compare_to is not a valid ref'
- ])
- end
-
- context 'when the FF ci_rules_changes_compare is not enabled' do
- before do
- stub_feature_flags(ci_rules_changes_compare: false)
- end
-
- it 'ignores compare_to and changes is always true' do
- expect(build_names).to contain_exactly('job1', 'job2')
- end
+ expect(pipeline.errors.full_messages).to eq(
+ [
+ 'Failed to parse rule for job1: rules:changes:compare_to is not a valid ref'
+ ])
end
end
@@ -563,16 +554,6 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'creates job1 and job2' do
expect(build_names).to contain_exactly('job1', 'job2')
end
-
- context 'when the FF ci_rules_changes_compare is not enabled' do
- before do
- stub_feature_flags(ci_rules_changes_compare: false)
- end
-
- it 'ignores compare_to and changes is always true' do
- expect(build_names).to contain_exactly('job1', 'job2')
- end
- end
end
context 'when the rule does not match' do
@@ -581,16 +562,6 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'does not create job1' do
expect(build_names).to contain_exactly('job2')
end
-
- context 'when the FF ci_rules_changes_compare is not enabled' do
- before do
- stub_feature_flags(ci_rules_changes_compare: false)
- end
-
- it 'ignores compare_to and changes is always true' do
- expect(build_names).to contain_exactly('job1', 'job2')
- end
- end
end
end
end
@@ -616,17 +587,6 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
expect(pipeline).to be_created_successfully
expect(build_names).to contain_exactly('job1')
end
-
- context 'when the FF ci_rules_changes_compare is not enabled' do
- before do
- stub_feature_flags(ci_rules_changes_compare: false)
- end
-
- it 'ignores compare_to and changes is always true' do
- expect(pipeline).to be_created_successfully
- expect(build_names).to contain_exactly('job1')
- end
- end
end
context 'when the rule does not match' do