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

initial_pipeline_process_worker_spec.rb « ci « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a94f1cbb4cbf680e3e7a6c4f44d4036a5d37acc (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::InitialPipelineProcessWorker, feature_category: :continuous_integration do
  let_it_be(:project) { create(:project, :repository) }
  let(:job) { build(:ci_build, project: project) }
  let(:stage) { build(:ci_stage, project: project, statuses: [job], position: 1) }
  let(:pipeline) { create(:ci_pipeline, stages: [stage], status: :created, project: project, builds: [job]) }

  describe '#perform' do
    include_examples 'an idempotent worker' do
      let(:job_args) { pipeline.id }

      it 'marks the pipeline as pending' do
        expect(pipeline).to be_created

        subject

        expect(pipeline.reload).to be_pending
      end
    end

    context 'when a pipeline does not contain a deployment job' do
      it 'does not create any deployments' do
        expect { subject }.not_to change { Deployment.count }
      end
    end

    context 'when a pipeline contains a teardown job' do
      let(:job) { build(:ci_build, :stop_review_app, project: project) }

      before do
        create(:environment, name: job.expanded_environment_name)
      end

      it 'does not create a deployment record' do
        expect { subject }.not_to change { Deployment.count }

        expect(job.deployment).to be_nil
      end
    end

    context 'when a pipeline contains a deployment job' do
      before do
        allow(::Deployments::CreateForJobService).to receive(:new).and_call_original
        allow(::Ci::PipelineProcessing::AtomicProcessingService).to receive(:new).and_call_original
      end

      let(:job) { build(:ci_build, :created, :start_review_app, project: project, stage_idx: 1) }
      let!(:environment) { create(:environment, project: project, name: job.expanded_environment_name) }

      it 'creates a deployment record' do
        expect { subject }.to change { Deployment.count }.by(1)
      end

      context 'when the corresponding environment does not exist' do
        let(:environment) {}

        it 'does not create a deployment record' do
          expect { subject }.not_to change { Deployment.count }

          expect(job.deployment).to be_nil
        end
      end

      it 'kicks off atomic processing before a deployment is created' do
        expect(::Ci::PipelineProcessing::AtomicProcessingService).to receive(:new).ordered
        expect(::Deployments::CreateForJobService).to receive(:new).ordered

        subject
      end

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

        it 'creates a deployment record' do
          expect { subject }.to change { Deployment.count }.by(1)

          expect(job.deployment).to have_attributes(
            project: job.project,
            ref: job.ref,
            sha: job.sha,
            deployable: job,
            deployable_type: 'CommitStatus',
            environment: job.persisted_environment
          )
        end

        it 'a deployment is created before atomic processing is kicked off' do
          expect(::Deployments::CreateForJobService).to receive(:new).ordered
          expect(::Ci::PipelineProcessing::AtomicProcessingService).to receive(:new).ordered

          subject
        end
      end
    end
  end
end