diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-29 15:20:10 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-05-29 15:20:10 +0200 |
commit | fc3d214130f2038b3c8bdf142506c9116f373244 (patch) | |
tree | a9b2c7f49deac67852c863fcb5a612a312be55c3 | |
parent | 8a3aa3a6365f511a2620b56946721f1584bade99 (diff) | |
download | gitlab-ce-fc3d214130f2038b3c8bdf142506c9116f373244.tar.gz |
Add a feature flag for switching pipeline stages
-rw-r--r-- | app/models/ci/pipeline.rb | 16 | ||||
-rw-r--r-- | app/serializers/pipeline_details_entity.rb | 2 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 81 |
3 files changed, 92 insertions, 7 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 9dac56fcd57..4b8c23a393d 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -250,13 +250,17 @@ module Ci end ## - # TODO consider switching to persisted stages only in pipelines table - # (not necessairly in the show pipeline page because of #23257. - # Hide this behind two feature flags - enabled / disabled and only - # gitlab-ce / everywhere. + # TODO We do not completely switch to persisted stages because of + # race conditions with setting statuses gitlab-ce#23257. # - def stages - super + def ordered_stages + return legacy_stages unless complete? + + if Feature.enabled?('ci_pipeline_persisted_stages') + stages + else + legacy_stages + end end def legacy_stages diff --git a/app/serializers/pipeline_details_entity.rb b/app/serializers/pipeline_details_entity.rb index d58572a5f87..8ba9cac53c4 100644 --- a/app/serializers/pipeline_details_entity.rb +++ b/app/serializers/pipeline_details_entity.rb @@ -1,6 +1,6 @@ class PipelineDetailsEntity < PipelineEntity expose :details do - expose :stages, using: StageEntity + expose :ordered_stages, as: :stages, using: StageEntity expose :artifacts, using: BuildArtifactEntity expose :manual_actions, using: BuildActionEntity end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index e7845b693a1..f3725e24470 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -500,6 +500,87 @@ describe Ci::Pipeline, :mailer do end end end + + describe '#stages' do + before do + create(:ci_stage_entity, project: project, + pipeline: pipeline, + name: 'build') + end + + it 'returns persisted stages' do + expect(pipeline.stages).not_to be_empty + expect(pipeline.stages).to all(be_persisted) + end + end + + describe '#ordered_stages' do + before do + create(:ci_stage_entity, project: project, + pipeline: pipeline, + position: 4, + name: 'deploy') + + create(:ci_build, project: project, + pipeline: pipeline, + stage: 'test', + stage_idx: 3, + name: 'test') + + create(:ci_build, project: project, + pipeline: pipeline, + stage: 'build', + stage_idx: 2, + name: 'build') + + create(:ci_stage_entity, project: project, + pipeline: pipeline, + position: 1, + name: 'sanity') + + create(:ci_stage_entity, project: project, + pipeline: pipeline, + position: 5, + name: 'cleanup') + end + + subject { pipeline.ordered_stages } + + context 'when using legacy stages' do + before do + stub_feature_flags(ci_pipeline_persisted_stages: false) + end + + it 'returns legacy stages in valid order' do + expect(subject.map(&:name)).to eq %w[build test] + end + end + + context 'when using persisted stages' do + before do + stub_feature_flags(ci_pipeline_persisted_stages: true) + end + + context 'when pipelines is not complete' do + it 'still returns legacy stages' do + expect(subject).to all(be_a Ci::LegacyStage) + expect(subject.map(&:name)).to eq %w[build test] + end + end + + context 'when pipeline is complete' do + before do + pipeline.succeed! + end + + it 'returns stages in valid order' do + expect(subject).to all(be_a Ci::Stage) + expect(subject.map(&:name)) + .to eq %w[sanity build test deploy cleanup] + end + end + end + end end describe 'state machine' do |