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
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(: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
|
|
|
|
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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
project.add_developer(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe 'processing events counter' do
|
|
|
|
let(:metrics) { double('pipeline metrics') }
|
|
|
|
let(:counter) { double('events counter') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject)
|
|
|
|
.to receive(:metrics).and_return(metrics)
|
|
|
|
allow(metrics)
|
|
|
|
.to receive(:pipeline_processing_events_counter)
|
|
|
|
.and_return(counter)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'increments processing events counter' do
|
|
|
|
expect(counter).to receive(:increment)
|
|
|
|
|
|
|
|
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') }
|
|
|
|
|
|
|
|
it 'returns unique statuses' do
|
2020-07-28 23:09:34 +05:30
|
|
|
subject.execute
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(all_builds.latest).to contain_exactly(build, test)
|
|
|
|
expect(all_builds.retried).to contain_exactly(build_retried)
|
|
|
|
end
|
|
|
|
|
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
|