blob: 6165aaff1c795a5436ba56f2d44767e5cceb6258 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::CancelPipelineWorker, :aggregate_failures do
let!(:pipeline) { create(:ci_pipeline, :running) }
describe '#perform' do
subject(:perform) { described_class.new.perform(pipeline.id, pipeline.id) }
it 'calls cancel_running' do
allow(::Ci::Pipeline).to receive(:find_by_id).and_return(pipeline)
expect(pipeline).to receive(:cancel_running).with(
auto_canceled_by_pipeline_id: pipeline.id,
cascade_to_children: false
)
perform
end
context 'if pipeline is deleted' do
subject(:perform) { described_class.new.perform(non_existing_record_id, non_existing_record_id) }
it 'does not error' do
expect(pipeline).not_to receive(:cancel_running)
perform
end
end
describe 'with builds and state transition side effects', :sidekiq_inline do
let!(:build) { create(:ci_build, :running, pipeline: pipeline) }
it_behaves_like 'an idempotent worker', :sidekiq_inline do
let(:job_args) { [pipeline.id, pipeline.id] }
it 'cancels the pipeline' do
perform
pipeline.reload
expect(pipeline).to be_canceled
expect(pipeline.builds.first).to be_canceled
expect(pipeline.builds.first.auto_canceled_by_id).to eq pipeline.id
expect(pipeline.auto_canceled_by_id).to eq pipeline.id
end
end
end
end
end
|