blob: af7b505602e0dc74b784c628d487c889ecfea917 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::PipelineCleanupRefWorker, :sidekiq_inline, feature_category: :continuous_integration do
include ExclusiveLeaseHelpers
let_it_be(:pipeline) { create(:ci_pipeline, :success) }
let(:worker) { described_class.new }
subject { worker.perform(pipeline.id) }
it 'does remove persistent ref' do
expect_next_instance_of(Ci::PersistentRef) do |persistent_ref|
expect(persistent_ref).to receive(:delete).once
end
subject
end
context 'when pipeline is still running' do
let_it_be(:pipeline) { create(:ci_pipeline, :running) }
it 'does not remove persistent ref' do
expect_next_instance_of(Ci::PersistentRef) do |persistent_ref|
expect(persistent_ref).not_to receive(:delete)
end
subject
end
end
context 'when pipeline status changes while being locked' do
let_it_be(:pipeline) { create(:ci_pipeline, :success) }
it 'does not remove persistent ref' do
expect_next_instance_of(Ci::PersistentRef) do |persistent_ref|
expect(persistent_ref).not_to receive(:delete_refs)
end
expect(worker).to receive(:in_lock).and_wrap_original do |method, *args, **kwargs, &block|
pipeline.run!
method.call(*args, **kwargs, &block)
end
subject
end
end
context 'when max retry attempts reach' do
let(:lease_key) { "projects/#{pipeline.project_id}/serialized_remove_refs" }
let!(:lease) { stub_exclusive_lease_taken(lease_key) }
it 'does not raise error' do
expect(lease).to receive(:try_obtain).exactly(described_class::LOCK_RETRY + 1).times
expect { subject }.to raise_error(Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError)
end
end
end
|