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
|
# 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 import is in progress' do
it 'marks the pipeline as finished' do
expect_next_instance_of(BulkImports::Logger) do |logger|
expect(logger).to receive(:info).with(
a_hash_including('message' => 'Tracker finished')
)
end
expect { subject.perform(pipeline_tracker.id) }
.to change { pipeline_tracker.reload.finished? }
.from(false).to(true)
end
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)
expect_next_instance_of(BulkImports::Logger) do |logger|
expect(logger).to receive(:error).with(
a_hash_including('message' => 'Tracker stale. Failing batches and tracker')
)
end
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
|