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
|
# frozen_string_literal: true
RSpec.shared_examples 'job is dropped with failure reason' do |failure_reason|
it 'changes status' do
service.execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq(failure_reason)
end
context 'when job has data integrity problem' do
it 'drops the job and logs the reason' do
allow(::Gitlab::Ci::Build::Status::Reason).to receive(:fabricate).and_raise(StandardError.new)
expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
.with(anything, a_hash_including(build_id: job.id))
.once
.and_call_original
service.execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('data_integrity_failure')
end
end
end
RSpec.shared_examples 'job is canceled' do
it 'changes status' do
service.execute
job.reload
expect(job).to be_canceled
end
end
RSpec.shared_examples 'job is unchanged' do
it 'does not change status' do
expect { service.execute }.not_to change { job.status }
end
end
RSpec.shared_examples 'when invalid dooms the job bypassing validations' do
it 'does not change status' do
allow_next_found_instance_of(Ci::Build) do |build|
allow(build).to receive(:drop!).and_raise(StateMachines::InvalidTransition)
end
expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
.with(anything, a_hash_including(build_id: job.id))
.once
.and_call_original
service.execute
job.reload
expect(job).to be_failed
expect(job.failure_reason).to eq('data_integrity_failure')
end
end
|