File: pipeline_finished_worker_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (66 lines) | stat: -rw-r--r-- 2,235 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::PipelineFinishedWorker, '#perform', feature_category: :continuous_integration do
  subject(:perform) { described_class.new.perform(pipeline.id) }

  context 'when pipeline exists' do
    let_it_be_with_refind(:project) { create(:project) }
    let_it_be_with_refind(:pipeline) do
      create(:ci_pipeline, :success, user: create(:user), project: project, finished_at: 1.second.ago)
    end

    it 'saves pipeline on Ci::FinishedPipelineChSyncEvent by default' do
      expect { perform }.to change { Ci::FinishedPipelineChSyncEvent.all }
        .from([])
        .to([an_object_having_attributes(pipeline_id: pipeline.id, pipeline_finished_at: pipeline.finished_at,
          project_namespace_id: pipeline.project.project_namespace_id)])
    end

    context 'when pipeline has already been processed' do
      before do
        described_class.new.perform(pipeline.id)

        Ci::FinishedPipelineChSyncEvent.pending.first.update!(processed: true)
      end

      it 'ignores duplicate calls for same pipeline' do
        perform

        expect(Ci::FinishedPipelineChSyncEvent.all).to contain_exactly(
          an_object_having_attributes(
            pipeline_id: pipeline.id, pipeline_finished_at: pipeline.finished_at,
            project_namespace_id: pipeline.project.project_namespace_id, processed: true)
        )
      end
    end

    context 'when project is scheduled for deletion' do
      before do
        project.update!(pending_delete: true)
      end

      it 'does not save pipeline on Ci::FinishedPipelineChSyncEvent' do
        expect { perform }.not_to change { Ci::FinishedPipelineChSyncEvent.count }
      end
    end

    context 'when pipeline does not have finished_at value' do
      before do
        pipeline.update!(finished_at: nil)
      end

      it 'does not save pipeline on Ci::FinishedPipelineChSyncEvent' do
        expect { perform }.not_to change { Ci::FinishedPipelineChSyncEvent.count }
      end
    end
  end

  context 'when pipeline does not exist' do
    it 'does not raise exception' do
      expect { described_class.new.perform(non_existing_record_id) }
        .not_to raise_error
    end
  end
end