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 101 102 103 104 105 106 107 108 109 110 111
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Environments::StopJobFailedWorker, feature_category: :continuous_delivery do
describe '#perform' do
let_it_be_with_refind(:environment) { create(:environment, state: :stopping) }
subject { described_class.new.perform(job.id) }
shared_examples_for 'recovering a stuck stopping environment' do
context 'when the job is not a stop job' do
let(:job) { non_stop_job }
it 'does not recover the environment' do
expect { subject }.not_to change { environment.reload.state }
end
end
context 'when the stop job is not failed' do
let(:job) { stop_job }
before do
job.update!(status: :success)
end
it 'does not recover the environment' do
expect { subject }.not_to change { environment.reload.state }
end
end
context 'when the stop job is failed' do
let(:job) { stop_job }
it 'recovers the environment' do
expect { subject }
.to change { environment.reload.state }
.from('stopping')
.to('available')
end
end
context 'when there is no environment' do
let(:job) { stop_job }
before do
environment.destroy!
end
it 'does not cause an error' do
expect { subject }.not_to raise_error
end
end
end
context 'with build job' do
let!(:stop_job) do
create(
:ci_build,
:stop_review_app,
environment: environment.name,
project: environment.project,
status: :failed
)
end
let!(:non_stop_job) do
create(
:ci_build,
:start_review_app,
environment: environment.name,
project: environment.project,
status: :failed
)
end
it_behaves_like 'recovering a stuck stopping environment'
end
context 'with bridge job' do
let!(:stop_job) do
create(
:ci_bridge,
:stop_review_app,
environment: environment.name,
project: environment.project,
status: :failed
)
end
let!(:non_stop_job) do
create(
:ci_bridge,
:start_review_app,
environment: environment.name,
project: environment.project,
status: :failed
)
end
it_behaves_like 'recovering a stuck stopping environment'
end
context 'when job does not exist' do
it 'does not raise exception' do
expect { described_class.new.perform(non_existing_record_id) }
.not_to raise_error
end
end
end
end
|