2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Pipeline::Chain::Sequence do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:pipeline) { build_stubbed(:ci_pipeline) }
|
2021-10-27 15:23:28 +05:30
|
|
|
let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new(project: project) }
|
2021-11-11 11:23:49 +05:30
|
|
|
let(:first_step) { spy('first step', name: 'FirstStep') }
|
|
|
|
let(:second_step) { spy('second step', name: 'SecondStep') }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:sequence) { [first_step, second_step] }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:histogram) { spy('prometheus metric') }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
subject do
|
|
|
|
described_class.new(pipeline, command, sequence)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when one of steps breaks the chain' do
|
|
|
|
before do
|
|
|
|
allow(first_step).to receive(:break?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not process the second step' do
|
2020-10-24 23:57:45 +05:30
|
|
|
subject.build!
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(second_step).not_to have_received(:perform!)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a pipeline object' do
|
|
|
|
expect(subject.build!).to eq pipeline
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when all chains are executed correctly' do
|
|
|
|
before do
|
|
|
|
sequence.each do |step|
|
|
|
|
allow(step).to receive(:break?).and_return(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'iterates through entire sequence' do
|
2020-10-24 23:57:45 +05:30
|
|
|
subject.build!
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(first_step).to have_received(:perform!)
|
|
|
|
expect(second_step).to have_received(:perform!)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a pipeline object' do
|
|
|
|
expect(subject.build!).to eq pipeline
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
it 'adds sequence duration to duration histogram' do
|
2020-06-23 00:09:42 +05:30
|
|
|
allow(command.metrics)
|
|
|
|
.to receive(:pipeline_creation_duration_histogram)
|
|
|
|
.and_return(histogram)
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
subject.build!
|
|
|
|
|
|
|
|
expect(histogram).to have_received(:observe)
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
it 'adds step sequence duration to duration histogram' do
|
|
|
|
expect(command.metrics)
|
|
|
|
.to receive(:pipeline_creation_step_duration_histogram)
|
|
|
|
.twice
|
|
|
|
.and_return(histogram)
|
|
|
|
expect(histogram).to receive(:observe).with({ step: 'FirstStep' }, any_args).ordered
|
|
|
|
expect(histogram).to receive(:observe).with({ step: 'SecondStep' }, any_args).ordered
|
|
|
|
|
|
|
|
subject.build!
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it 'records pipeline size by pipeline source in a histogram' do
|
|
|
|
allow(command.metrics)
|
|
|
|
.to receive(:pipeline_size_histogram)
|
|
|
|
.and_return(histogram)
|
|
|
|
|
|
|
|
subject.build!
|
|
|
|
|
|
|
|
expect(histogram).to have_received(:observe)
|
|
|
|
.with({ source: 'push' }, 0)
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe 'active jobs by pipeline plan histogram' do
|
|
|
|
before do
|
|
|
|
allow(command.metrics)
|
|
|
|
.to receive(:active_jobs_histogram)
|
|
|
|
.and_return(histogram)
|
|
|
|
|
|
|
|
pipeline = create(:ci_pipeline, :running, project: project)
|
|
|
|
create_list(:ci_build, 3, pipeline: pipeline)
|
|
|
|
create(:ci_bridge, pipeline: pipeline)
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it 'counts all the active jobs' do
|
|
|
|
subject.build!
|
2021-10-27 15:23:28 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(histogram).to have_received(:observe)
|
|
|
|
.with(hash_including(plan: project.actual_plan_name), 4)
|
|
|
|
end
|
2021-10-27 15:23:28 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|