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

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

require 'spec_helper'

RSpec.describe BulkImports::FinishBatchedPipelineWorker, feature_category: :importers do
  let_it_be(:bulk_import) { create(:bulk_import) }
  let_it_be(:config) { create(:bulk_import_configuration, bulk_import: bulk_import) }
  let_it_be(:entity) { create(:bulk_import_entity, bulk_import: bulk_import) }

  let(:status_event) { :finish }
  let(:pipeline_tracker) { create(:bulk_import_tracker, :started, :batched, entity: entity) }

  subject(:worker) { described_class.new }

  describe '#perform' do
    context 'when job version is nil' do
      before do
        allow(subject).to receive(:job_version).and_return(nil)
      end

      it 'finishes pipeline and enqueues entity worker' do
        expect(BulkImports::EntityWorker).to receive(:perform_async)
          .with(entity.id)

        subject.perform(pipeline_tracker.id)

        expect(pipeline_tracker.reload.finished?).to eq(true)
      end
    end

    context 'when job version is present' do
      it 'finishes pipeline and does not enqueues entity worker' do
        expect(BulkImports::EntityWorker).not_to receive(:perform_async)

        subject.perform(pipeline_tracker.id)

        expect(pipeline_tracker.reload.finished?).to eq(true)
      end
    end

    context 'when import is in progress' do
      it 're-enqueues for any started batches' do
        create(:bulk_import_batch_tracker, :started, tracker: pipeline_tracker)

        expect(described_class)
          .to receive(:perform_in)
          .with(described_class::REQUEUE_DELAY, pipeline_tracker.id)

        subject.perform(pipeline_tracker.id)
      end

      it 're-enqueues for any created batches' do
        create(:bulk_import_batch_tracker, :created, tracker: pipeline_tracker)

        expect(described_class)
          .to receive(:perform_in)
          .with(described_class::REQUEUE_DELAY, pipeline_tracker.id)

        subject.perform(pipeline_tracker.id)
      end
    end

    context 'when pipeline tracker is stale' do
      let(:pipeline_tracker) { create(:bulk_import_tracker, :started, :batched, :stale, entity: entity) }

      it 'fails pipeline tracker and its batches' do
        create(:bulk_import_batch_tracker, :finished, tracker: pipeline_tracker)

        subject.perform(pipeline_tracker.id)

        expect(pipeline_tracker.reload.failed?).to eq(true)
        expect(pipeline_tracker.batches.first.reload.failed?).to eq(true)
      end
    end

    context 'when pipeline is not batched' do
      let(:pipeline_tracker) { create(:bulk_import_tracker, :started, entity: entity) }

      it 'returns' do
        expect_next_instance_of(BulkImports::Tracker) do |instance|
          expect(instance).not_to receive(:finish!)
        end

        subject.perform(pipeline_tracker.id)
      end
    end

    context 'when pipeline is not started' do
      let(:status_event) { :start }

      it 'returns' do
        expect_next_instance_of(BulkImports::Tracker) do |instance|
          expect(instance).not_to receive(:finish!)
        end

        described_class.new.perform(pipeline_tracker.id)
      end
    end
  end
end