debian-mirror-gitlab/spec/services/ci/process_pipeline_service_spec.rb

101 lines
2.8 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Ci::ProcessPipelineService do
2021-06-08 01:23:25 +05:30
let_it_be(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:pipeline) do
create(:ci_empty_pipeline, ref: 'master', project: project)
end
2016-09-13 17:45:13 +05:30
2021-04-29 21:17:54 +05:30
let(:pipeline_processing_events_counter) { double(increment: true) }
let(:legacy_update_jobs_counter) { double(increment: true) }
let(:metrics) do
double(pipeline_processing_events_counter: pipeline_processing_events_counter,
legacy_update_jobs_counter: legacy_update_jobs_counter)
end
2020-07-28 23:09:34 +05:30
subject { described_class.new(pipeline) }
2016-09-13 17:45:13 +05:30
before do
2018-05-09 12:01:36 +05:30
stub_ci_pipeline_to_return_yaml_file
2017-09-10 17:25:29 +05:30
stub_not_protect_default_branch
2021-04-29 21:17:54 +05:30
allow(subject).to receive(:metrics).and_return(metrics)
2016-09-13 17:45:13 +05:30
end
2020-07-28 23:09:34 +05:30
describe 'processing events counter' do
it 'increments processing events counter' do
2021-04-29 21:17:54 +05:30
expect(pipeline_processing_events_counter).to receive(:increment)
2020-07-28 23:09:34 +05:30
subject.execute
end
end
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
describe 'updating a list of retried builds' do
2017-08-17 22:00:37 +05:30
let!(:build_retried) { create_build('build') }
let!(:build) { create_build('build') }
let!(:test) { create_build('test') }
2021-04-17 20:07:23 +05:30
context 'when FF ci_remove_update_retried_from_process_pipeline is enabled' do
it 'does not update older builds as retried' do
subject.execute
2017-08-17 22:00:37 +05:30
2021-04-17 20:07:23 +05:30
expect(all_builds.latest).to contain_exactly(build, build_retried, test)
expect(all_builds.retried).to be_empty
end
2017-08-17 22:00:37 +05:30
end
2021-04-17 20:07:23 +05:30
context 'when FF ci_remove_update_retried_from_process_pipeline is disabled' do
2021-03-11 19:13:27 +05:30
before do
2021-04-17 20:07:23 +05:30
stub_feature_flags(ci_remove_update_retried_from_process_pipeline: false)
2021-03-11 19:13:27 +05:30
end
2021-04-17 20:07:23 +05:30
it 'returns unique statuses' do
2021-03-11 19:13:27 +05:30
subject.execute
2021-04-17 20:07:23 +05:30
expect(all_builds.latest).to contain_exactly(build, test)
expect(all_builds.retried).to contain_exactly(build_retried)
2021-03-11 19:13:27 +05:30
end
2021-04-29 21:17:54 +05:30
it 'increments the counter' do
expect(legacy_update_jobs_counter).to receive(:increment)
2021-04-17 20:07:23 +05:30
2021-04-29 21:17:54 +05:30
subject.execute
end
2021-06-08 01:23:25 +05:30
it 'logs the project and pipeline id' do
expect(Gitlab::AppJsonLogger).to receive(:info).with(event: 'update_retried_is_used',
project_id: project.id,
pipeline_id: pipeline.id)
subject.execute
end
2021-04-29 21:17:54 +05:30
context 'when the previous build has already retried column true' do
2021-03-11 19:13:27 +05:30
before do
2021-04-29 21:17:54 +05:30
build_retried.update_columns(retried: true)
2021-03-11 19:13:27 +05:30
end
2021-04-29 21:17:54 +05:30
it 'does not increment the counter' do
expect(legacy_update_jobs_counter).not_to receive(:increment)
2021-03-11 19:13:27 +05:30
subject.execute
end
end
end
2021-04-17 20:07:23 +05:30
private
2020-07-28 23:09:34 +05:30
def create_build(name, **opts)
create(:ci_build, :created, pipeline: pipeline, name: name, **opts)
end
2018-12-05 23:21:45 +05:30
2020-07-28 23:09:34 +05:30
def all_builds
pipeline.builds.order(:stage_idx, :id)
end
2018-12-05 23:21:45 +05:30
end
2016-09-13 17:45:13 +05:30
end