2021-04-02 11:09:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Ci::AfterRequeueJobService do
|
|
|
|
let_it_be(:project) { create(:project) }
|
2022-01-19 19:15:02 -05:00
|
|
|
let_it_be(:user) { project.first_owner }
|
2021-04-02 11:09:19 -04:00
|
|
|
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
|
2022-01-17 13:16:07 -05:00
|
|
|
let!(:build1) { create(:ci_build, name: 'build1', pipeline: pipeline, stage_idx: 0) }
|
|
|
|
let!(:test1) { create(:ci_build, :success, name: 'test1', pipeline: pipeline, stage_idx: 1) }
|
|
|
|
let!(:test2) { create(:ci_build, :skipped, name: 'test2', pipeline: pipeline, stage_idx: 1) }
|
|
|
|
let!(:test3) { create(:ci_build, :skipped, :dependent, name: 'test3', pipeline: pipeline, stage_idx: 1, needed: build1) }
|
|
|
|
let!(:deploy) { create(:ci_build, :skipped, :dependent, name: 'deploy', pipeline: pipeline, stage_idx: 2, needed: test3) }
|
|
|
|
|
|
|
|
subject(:execute_service) { described_class.new(project, user).execute(build1) }
|
|
|
|
|
|
|
|
shared_examples 'processing subsequent skipped jobs' do
|
|
|
|
it 'marks subsequent skipped jobs as processable' do
|
|
|
|
expect(test1.reload).to be_success
|
|
|
|
expect(test2.reload).to be_skipped
|
|
|
|
expect(test3.reload).to be_skipped
|
|
|
|
expect(deploy.reload).to be_skipped
|
|
|
|
|
|
|
|
execute_service
|
|
|
|
|
|
|
|
expect(test1.reload).to be_success
|
|
|
|
expect(test2.reload).to be_created
|
|
|
|
expect(test3.reload).to be_created
|
|
|
|
expect(deploy.reload).to be_created
|
|
|
|
end
|
2021-04-02 11:09:19 -04:00
|
|
|
end
|
|
|
|
|
2022-01-17 13:16:07 -05:00
|
|
|
it_behaves_like 'processing subsequent skipped jobs'
|
|
|
|
|
2021-07-15 08:09:01 -04:00
|
|
|
context 'when there is a job need from the same stage' do
|
2022-01-17 13:16:07 -05:00
|
|
|
let!(:build2) do
|
2021-07-15 08:09:01 -04:00
|
|
|
create(:ci_build,
|
|
|
|
:skipped,
|
2021-08-10 08:11:00 -04:00
|
|
|
:dependent,
|
2022-01-17 13:16:07 -05:00
|
|
|
name: 'build2',
|
2021-07-15 08:09:01 -04:00
|
|
|
pipeline: pipeline,
|
|
|
|
stage_idx: 0,
|
2021-08-10 08:11:00 -04:00
|
|
|
scheduling_type: :dag,
|
2022-01-17 13:16:07 -05:00
|
|
|
needed: build1)
|
2021-07-15 08:09:01 -04:00
|
|
|
end
|
|
|
|
|
2022-01-17 13:16:07 -05:00
|
|
|
shared_examples 'processing the same stage job' do
|
|
|
|
it 'marks subsequent skipped jobs as processable' do
|
|
|
|
expect { execute_service }.to change { build2.reload.status }.from('skipped').to('created')
|
|
|
|
end
|
2021-07-15 08:09:01 -04:00
|
|
|
end
|
2022-01-17 13:16:07 -05:00
|
|
|
|
|
|
|
it_behaves_like 'processing subsequent skipped jobs'
|
|
|
|
it_behaves_like 'processing the same stage job'
|
2021-07-15 08:09:01 -04:00
|
|
|
end
|
|
|
|
|
2021-04-02 11:09:19 -04:00
|
|
|
context 'when the pipeline is a downstream pipeline and the bridge is depended' do
|
2022-01-17 13:16:07 -05:00
|
|
|
let!(:trigger_job) { create(:ci_bridge, :strategy_depend, name: 'trigger_job', status: 'success') }
|
2021-04-02 11:09:19 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
create(:ci_sources_pipeline, pipeline: pipeline, source_job: trigger_job)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks source bridge as pending' do
|
|
|
|
expect { execute_service }.to change { trigger_job.reload.status }.from('success').to('pending')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|