2016-10-17 03:55:47 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PipelineMetricsWorker do
|
2017-03-27 16:42:08 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-08-22 05:37:35 -04:00
|
|
|
|
|
|
|
let!(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project,
|
|
|
|
source_branch: pipeline.ref,
|
|
|
|
head_pipeline: pipeline)
|
|
|
|
end
|
2016-10-17 03:55:47 -04:00
|
|
|
|
|
|
|
let(:pipeline) do
|
|
|
|
create(:ci_empty_pipeline,
|
|
|
|
status: status,
|
|
|
|
project: project,
|
|
|
|
ref: 'master',
|
|
|
|
sha: project.repository.commit('master').id,
|
|
|
|
started_at: 1.hour.ago,
|
|
|
|
finished_at: Time.now)
|
|
|
|
end
|
|
|
|
|
2017-08-22 05:37:35 -04:00
|
|
|
let(:status) { 'pending' }
|
|
|
|
|
2016-10-17 03:55:47 -04:00
|
|
|
describe '#perform' do
|
2016-10-20 10:20:04 -04:00
|
|
|
before do
|
|
|
|
described_class.new.perform(pipeline.id)
|
|
|
|
end
|
2016-10-17 03:55:47 -04:00
|
|
|
|
|
|
|
context 'when pipeline is running' do
|
|
|
|
let(:status) { 'running' }
|
|
|
|
|
|
|
|
it 'records the build start time' do
|
2016-10-17 08:40:02 -04:00
|
|
|
expect(merge_request.reload.metrics.latest_build_started_at).to be_like_time(pipeline.started_at)
|
2016-10-17 03:55:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'clears the build end time' do
|
|
|
|
expect(merge_request.reload.metrics.latest_build_finished_at).to be_nil
|
|
|
|
end
|
2016-10-20 10:20:04 -04:00
|
|
|
|
|
|
|
it 'records the pipeline' do
|
|
|
|
expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
|
|
|
|
end
|
2016-10-17 03:55:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline succeeded' do
|
|
|
|
let(:status) { 'success' }
|
|
|
|
|
|
|
|
it 'records the build end time' do
|
2016-10-17 08:40:02 -04:00
|
|
|
expect(merge_request.reload.metrics.latest_build_finished_at).to be_like_time(pipeline.finished_at)
|
2016-10-17 03:55:47 -04:00
|
|
|
end
|
2016-10-20 10:20:04 -04:00
|
|
|
|
|
|
|
it 'records the pipeline' do
|
|
|
|
expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
|
|
|
|
end
|
2016-10-17 03:55:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|