Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pipeline_metrics_worker_spec.rb « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7bd98f8f55d98461e9e44a786db330a663ae8d30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe PipelineMetricsWorker, feature_category: :continuous_integration do
  let(:project) { create(:project, :repository) }

  let!(:merge_request) do
    create(:merge_request, source_project: project, source_branch: pipeline.ref, head_pipeline: pipeline)
  end

  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.current
    )
  end

  let(:status) { 'pending' }

  describe '#perform' do
    before do
      described_class.new.perform(pipeline.id)
    end

    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

      it 'records the pipeline' do
        expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
      end
    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

      it 'records the pipeline' do
        expect(merge_request.reload.metrics.pipeline).to eq(pipeline)
      end
    end
  end
end