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/models/ci/pipeline_spec.rb')
-rw-r--r--spec/models/ci/pipeline_spec.rb117
1 files changed, 85 insertions, 32 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 26fc4b140c1..74a476a6422 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -11,6 +11,10 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
let_it_be(:namespace) { create_default(:namespace).freeze }
let_it_be(:project) { create_default(:project, :repository).freeze }
+ it 'paginates 15 pipeleines per page' do
+ expect(described_class.default_per_page).to eq(15)
+ end
+
it_behaves_like 'having unique enum values'
it { is_expected.to belong_to(:project) }
@@ -2768,6 +2772,41 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
expect(control2.count).to eq(control1.count + extra_update_queries + extra_generic_commit_status_validation_queries)
end
end
+
+ context 'when the first try cannot get an exclusive lock' do
+ let(:retries) { 1 }
+
+ subject(:cancel_running) { pipeline.cancel_running(retries: retries) }
+
+ before do
+ build = create(:ci_build, :running, pipeline: pipeline)
+
+ allow(pipeline.cancelable_statuses).to receive(:find_in_batches).and_yield([build])
+
+ call_count = 0
+ allow(build).to receive(:cancel).and_wrap_original do |original, *args|
+ call_count >= retries ? raise(ActiveRecord::StaleObjectError) : original.call(*args)
+
+ call_count += 1
+ end
+ end
+
+ it 'retries again and cancels the build' do
+ cancel_running
+
+ expect(latest_status).to contain_exactly('canceled')
+ end
+
+ context 'when the retries parameter is 0' do
+ let(:retries) { 0 }
+
+ it 'raises error' do
+ expect do
+ cancel_running
+ end.to raise_error(ActiveRecord::StaleObjectError)
+ end
+ end
+ end
end
describe '#retry_failed' do
@@ -2854,7 +2893,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
it 'builds hook data once' do
- create(:pipelines_email_service)
+ create(:pipelines_email_integration)
expect(Gitlab::DataBuilder::Pipeline).to receive(:build).once.and_call_original
@@ -3772,16 +3811,6 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
it 'can generate a codequality report' do
expect(subject).to be_truthy
end
-
- context 'when feature is disabled' do
- before do
- stub_feature_flags(codequality_mr_diff: false)
- end
-
- it 'can not generate a codequality report' do
- expect(subject).to be_falsey
- end
- end
end
end
@@ -4355,16 +4384,14 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
end
- describe '#base_and_ancestors' do
- subject { pipeline.base_and_ancestors(same_project: same_project) }
+ describe '#self_and_upstreams' do
+ subject(:self_and_upstreams) { pipeline.self_and_upstreams }
let_it_be(:pipeline) { create(:ci_pipeline, :created) }
- let(:same_project) { false }
-
context 'when pipeline is not child nor parent' do
it 'returns just the pipeline itself' do
- expect(subject).to contain_exactly(pipeline)
+ expect(self_and_upstreams).to contain_exactly(pipeline)
end
end
@@ -4378,7 +4405,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
it 'returns parent and self' do
- expect(subject).to contain_exactly(parent, pipeline)
+ expect(self_and_upstreams).to contain_exactly(parent, pipeline)
end
end
@@ -4390,7 +4417,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
it 'returns self' do
- expect(subject).to contain_exactly(pipeline)
+ expect(self_and_upstreams).to contain_exactly(pipeline)
end
end
@@ -4406,11 +4433,11 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
it 'returns self, parent and ancestor' do
- expect(subject).to contain_exactly(ancestor, parent, pipeline)
+ expect(self_and_upstreams).to contain_exactly(ancestor, parent, pipeline)
end
end
- context 'when pipeline is a triggered pipeline' do
+ context 'when pipeline is a triggered pipeline from a different project' do
let_it_be(:pipeline) { create(:ci_pipeline, :created) }
let(:upstream) { create(:ci_pipeline, project: create(:project)) }
@@ -4419,18 +4446,41 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
create_source_pipeline(upstream, pipeline)
end
- context 'same_project: false' do
- it 'returns upstream and self' do
- expect(subject).to contain_exactly(pipeline, upstream)
- end
+ it 'returns upstream and self' do
+ expect(self_and_upstreams).to contain_exactly(pipeline, upstream)
end
+ end
+ end
- context 'same_project: true' do
- let(:same_project) { true }
+ describe '#self_and_ancestors' do
+ subject(:self_and_ancestors) { pipeline.self_and_ancestors }
- it 'returns self' do
- expect(subject).to contain_exactly(pipeline)
- end
+ context 'when pipeline is child' do
+ let(:pipeline) { create(:ci_pipeline, :created) }
+ let(:parent) { create(:ci_pipeline) }
+ let(:sibling) { create(:ci_pipeline) }
+
+ before do
+ create_source_pipeline(parent, pipeline)
+ create_source_pipeline(parent, sibling)
+ end
+
+ it 'returns parent and self' do
+ expect(self_and_ancestors).to contain_exactly(parent, pipeline)
+ end
+ end
+
+ context 'when pipeline is a triggered pipeline from a different project' do
+ let_it_be(:pipeline) { create(:ci_pipeline, :created) }
+
+ let(:upstream) { create(:ci_pipeline, project: create(:project)) }
+
+ before do
+ create_source_pipeline(upstream, pipeline)
+ end
+
+ it 'returns only self' do
+ expect(self_and_ancestors).to contain_exactly(pipeline)
end
end
end
@@ -4468,15 +4518,18 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
context 'when the parent pipeline has a dependent upstream pipeline' do
- let!(:upstream_bridge) do
- create_bridge(create(:ci_pipeline, project: create(:project)), parent_pipeline, true)
- end
+ let(:upstream_pipeline) { create(:ci_pipeline, project: create(:project)) }
+ let!(:upstream_bridge) { create_bridge(upstream_pipeline, parent_pipeline, true) }
+
+ let(:upstream_upstream_pipeline) { create(:ci_pipeline, project: create(:project)) }
+ let!(:upstream_upstream_bridge) { create_bridge(upstream_upstream_pipeline, upstream_pipeline, true) }
it 'marks all source bridges as pending' do
reset_bridge
expect(bridge.reload).to be_pending
expect(upstream_bridge.reload).to be_pending
+ expect(upstream_upstream_bridge.reload).to be_pending
end
end
end