diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-22 18:51:15 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-04-16 12:22:23 +0300 |
commit | fb07863693affd1d34f66847bd81a2a9f5ef81a2 (patch) | |
tree | 161fc48e7584a829293fa13cedd241f3734060d8 /spec/services/ci/create_pipeline_service_spec.rb | |
parent | ef82859d7d8ea70b29f600193fc18bdf5aea895e (diff) |
Rewind IID on Ci::Pipelines
If no pipeline is created we currently have IID gap.
This is due to fact that we generate IID not on save,
but rather ahead of time. This results, us,
losing IIDs.
Diffstat (limited to 'spec/services/ci/create_pipeline_service_spec.rb')
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 6f8a76e9d56..8a80652b3d8 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -25,7 +25,8 @@ describe Ci::CreatePipelineService do merge_request: nil, push_options: nil, source_sha: nil, - target_sha: nil) + target_sha: nil, + save_on_errors: true) params = { ref: ref, before: '00000000', after: after, @@ -36,7 +37,7 @@ describe Ci::CreatePipelineService do target_sha: target_sha } described_class.new(project, user, params).execute( - source, trigger_request: trigger_request, merge_request: merge_request) + source, save_on_errors: save_on_errors, trigger_request: trigger_request, merge_request: merge_request) end # rubocop:enable Metrics/ParameterLists @@ -57,6 +58,7 @@ describe Ci::CreatePipelineService do expect(pipeline).to eq(project.ci_pipelines.last) expect(pipeline).to have_attributes(user: user) expect(pipeline).to have_attributes(status: 'pending') + expect(pipeline.iid).not_to be_nil expect(pipeline.repository_source?).to be true expect(pipeline.builds.first).to be_kind_of(Ci::Build) end @@ -446,6 +448,43 @@ describe Ci::CreatePipelineService do expect(Ci::Build.all).to be_empty expect(Ci::Pipeline.count).to eq(0) end + + describe '#iid' do + let(:internal_id) do + InternalId.find_by(project_id: project.id, usage: :ci_pipelines) + end + + before do + expect_any_instance_of(Ci::Pipeline).to receive(:ensure_project_iid!) + .and_call_original + end + + context 'when ci_pipeline_rewind_iid is enabled' do + before do + stub_feature_flags(ci_pipeline_rewind_iid: true) + end + + it 'rewinds iid' do + result = execute_service + + expect(result).not_to be_persisted + expect(internal_id.last_value).to eq(0) + end + end + + context 'when ci_pipeline_rewind_iid is disabled' do + before do + stub_feature_flags(ci_pipeline_rewind_iid: false) + end + + it 'does not rewind iid' do + result = execute_service + + expect(result).not_to be_persisted + expect(internal_id.last_value).to eq(1) + end + end + end end context 'with manual actions' do |