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

process_pipeline_service_spec.rb « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e02536fd07f7667c8f240fc73a2d08b33792c5c3 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::ProcessPipelineService do
  let(:user) { create(:user) }
  let(:project) { create(:project) }

  let(:pipeline) do
    create(:ci_empty_pipeline, ref: 'master', project: project)
  end

  subject { described_class.new(pipeline) }

  before do
    stub_ci_pipeline_to_return_yaml_file
    stub_not_protect_default_branch

    project.add_developer(user)
  end

  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

  describe 'updating a list of retried builds' do
    let!(:build_retried) { create_build('build') }
    let!(:build) { create_build('build') }
    let!(:test) { create_build('test') }

    context 'when FF ci_remove_update_retried_from_process_pipeline is enabled' do
      it 'does not update older builds as retried' do
        subject.execute

        expect(all_builds.latest).to contain_exactly(build, build_retried, test)
        expect(all_builds.retried).to be_empty
      end
    end

    context 'when FF ci_remove_update_retried_from_process_pipeline is disabled' do
      before do
        stub_feature_flags(ci_remove_update_retried_from_process_pipeline: false)
      end

      it 'returns unique statuses' do
        subject.execute

        expect(all_builds.latest).to contain_exactly(build, test)
        expect(all_builds.retried).to contain_exactly(build_retried)
      end

      context 'counter ci_legacy_update_jobs_as_retried_total' do
        let(:counter) { double(increment: true) }

        before do
          allow(Gitlab::Metrics).to receive(:counter).and_call_original
          allow(Gitlab::Metrics).to receive(:counter)
                                      .with(:ci_legacy_update_jobs_as_retried_total, anything)
                                      .and_return(counter)
        end

        it 'increments the counter' do
          expect(counter).to receive(:increment)

          subject.execute
        end

        context 'when the previous build has already retried column true' do
          before do
            build_retried.update_columns(retried: true)
          end

          it 'does not increment the counter' do
            expect(counter).not_to receive(:increment)

            subject.execute
          end
        end
      end
    end

    private

    def create_build(name, **opts)
      create(:ci_build, :created, pipeline: pipeline, name: name, **opts)
    end

    def all_builds
      pipeline.builds.order(:stage_idx, :id)
    end
  end
end