debian-mirror-gitlab/spec/workers/pipeline_metrics_worker_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.5 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe PipelineMetricsWorker, feature_category: :continuous_integration do
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2018-03-17 18:26:18 +05:30
let!(:merge_request) do
2023-06-20 00:43:36 +05:30
create(:merge_request, source_project: project, source_branch: pipeline.ref, head_pipeline: pipeline)
2018-03-17 18:26:18 +05:30
end
2016-11-03 12:29:30 +05:30
let(:pipeline) do
2023-06-20 00:43:36 +05:30
create(
:ci_empty_pipeline,
status: status,
project: project,
ref: 'master',
sha: project.repository.commit('master').id,
started_at: 1.hour.ago,
finished_at: Time.current
)
2016-11-03 12:29:30 +05:30
end
2018-03-17 18:26:18 +05:30
let(:status) { 'pending' }
2016-11-03 12:29:30 +05:30
describe '#perform' do
2017-08-17 22:00:37 +05:30
before do
described_class.new.perform(pipeline.id)
end
2016-11-03 12:29:30 +05:30
context 'when pipeline is running' do
let(:status) { 'running' }
it 'records the build start time' do
expect(merge_request.reload.metrics.latest_build_started_at).to be_like_time(pipeline.started_at)
end
it 'clears the build end time' do
expect(merge_request.reload.metrics.latest_build_finished_at).to be_nil
end
2017-08-17 22:00:37 +05:30
it 'records the pipeline' do
expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
end
2016-11-03 12:29:30 +05:30
end
context 'when pipeline succeeded' do
let(:status) { 'success' }
it 'records the build end time' do
expect(merge_request.reload.metrics.latest_build_finished_at).to be_like_time(pipeline.finished_at)
end
2017-08-17 22:00:37 +05:30
it 'records the pipeline' do
expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
end
2016-11-03 12:29:30 +05:30
end
end
end