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) }
|
|
|
|
let_it_be(:user) { project.owner }
|
|
|
|
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
|
2021-08-10 08:11:00 -04:00
|
|
|
let!(:build) { create(:ci_build, pipeline: pipeline, stage_idx: 0, name: 'build') }
|
2021-04-02 11:09:19 -04:00
|
|
|
let!(:test1) { create(:ci_build, :success, pipeline: pipeline, stage_idx: 1) }
|
|
|
|
let!(:test2) { create(:ci_build, :skipped, pipeline: pipeline, stage_idx: 1) }
|
2021-08-10 08:11:00 -04:00
|
|
|
let!(:test3) { create(:ci_build, :skipped, :dependent, pipeline: pipeline, stage_idx: 1, needed: build) }
|
|
|
|
let!(:deploy) { create(:ci_build, :skipped, :dependent, pipeline: pipeline, stage_idx: 2, needed: test3) }
|
2021-04-02 11:09:19 -04:00
|
|
|
|
|
|
|
subject(:execute_service) { described_class.new(project, user).execute(build) }
|
|
|
|
|
|
|
|
it 'marks subsequent skipped jobs as processable' do
|
|
|
|
expect(test1.reload).to be_success
|
|
|
|
expect(test2.reload).to be_skipped
|
2021-08-10 08:11:00 -04:00
|
|
|
expect(test3.reload).to be_skipped
|
|
|
|
expect(deploy.reload).to be_skipped
|
2021-04-02 11:09:19 -04:00
|
|
|
|
|
|
|
execute_service
|
|
|
|
|
|
|
|
expect(test1.reload).to be_success
|
|
|
|
expect(test2.reload).to be_created
|
2021-08-10 08:11:00 -04:00
|
|
|
expect(test3.reload).to be_created
|
|
|
|
expect(deploy.reload).to be_created
|
2021-04-02 11:09:19 -04:00
|
|
|
end
|
|
|
|
|
2021-07-15 08:09:01 -04:00
|
|
|
context 'when there is a job need from the same stage' do
|
2021-08-10 08:11:00 -04:00
|
|
|
let!(:test4) do
|
2021-07-15 08:09:01 -04:00
|
|
|
create(:ci_build,
|
|
|
|
:skipped,
|
2021-08-10 08:11:00 -04:00
|
|
|
:dependent,
|
2021-07-15 08:09:01 -04:00
|
|
|
pipeline: pipeline,
|
|
|
|
stage_idx: 0,
|
2021-08-10 08:11:00 -04:00
|
|
|
scheduling_type: :dag,
|
|
|
|
needed: build)
|
2021-07-15 08:09:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks subsequent skipped jobs as processable' do
|
2021-08-10 08:11:00 -04:00
|
|
|
expect { execute_service }.to change { test4.reload.status }.from('skipped').to('created')
|
2021-07-15 08:09:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-02 11:09:19 -04:00
|
|
|
context 'when the pipeline is a downstream pipeline and the bridge is depended' do
|
|
|
|
let!(:trigger_job) { create(:ci_bridge, :strategy_depend, status: 'success') }
|
|
|
|
|
|
|
|
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
|