Commit a9e9bfc8 authored by Keith Richardson's avatar Keith Richardson Committed by Vitali Tatarintev

Fix expired artifacts causing dependency failures on locked pipelines

parent 6e1e1bf5
......@@ -891,7 +891,7 @@ module Ci
end
def valid_dependency?
return false if artifacts_expired?
return false if artifacts_expired? && !pipeline.artifacts_locked?
return false if erased?
true
......
......@@ -6,7 +6,7 @@ module API
module JobRequest
class Dependency < Grape::Entity
expose :id, :name, :token
expose :artifacts_file, using: Entities::Ci::JobArtifactFile, if: ->(job, _) { job.artifacts? }
expose :artifacts_file, using: Entities::Ci::JobArtifactFile, if: ->(job, _) { job.available_artifacts? }
end
end
end
......
......@@ -3743,7 +3743,21 @@ RSpec.describe Ci::Build do
context 'when artifacts of depended job has been expired' do
let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) }
it { expect(job).not_to have_valid_build_dependencies }
context 'when pipeline is not locked' do
before do
build.pipeline.unlocked!
end
it { expect(job).not_to have_valid_build_dependencies }
end
context 'when pipeline is locked' do
before do
build.pipeline.artifacts_locked!
end
it { expect(job).to have_valid_build_dependencies }
end
end
context 'when artifacts of depended job has been erased' do
......@@ -4763,8 +4777,24 @@ RSpec.describe Ci::Build do
let!(:pre_stage_job_invalid) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test2', stage_idx: 1) }
let!(:job) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 2, options: { dependencies: %w(test1 test2) }) }
it 'returns invalid dependencies' do
expect(job.invalid_dependencies).to eq([pre_stage_job_invalid])
context 'when pipeline is locked' do
before do
build.pipeline.unlocked!
end
it 'returns invalid dependencies when expired' do
expect(job.invalid_dependencies).to eq([pre_stage_job_invalid])
end
end
context 'when pipeline is not locked' do
before do
build.pipeline.artifacts_locked!
end
it 'returns no invalid dependencies when expired' do
expect(job.invalid_dependencies).to eq([])
end
end
end
......
......@@ -133,6 +133,7 @@ RSpec.describe BuildDetailsEntity do
let(:message) { subject[:callout_message] }
before do
build.pipeline.unlocked!
build.drop!(:missing_dependency_failure)
end
......
......@@ -5,8 +5,8 @@ require 'spec_helper'
module Ci
RSpec.describe RegisterJobService do
let_it_be(:group) { create(:group) }
let_it_be(:project, reload: true) { create(:project, group: group, shared_runners_enabled: false, group_runners_enabled: false) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be_with_reload(:project) { create(:project, group: group, shared_runners_enabled: false, group_runners_enabled: false) }
let_it_be_with_reload(:pipeline) { create(:ci_pipeline, project: project) }
let!(:shared_runner) { create(:ci_runner, :instance) }
let!(:specific_runner) { create(:ci_runner, :project, projects: [project]) }
......@@ -467,13 +467,27 @@ module Ci
context 'when depended job has not been completed yet' do
let!(:pre_stage_job) { create(:ci_build, :pending, :queued, :manual, pipeline: pipeline, name: 'test', stage_idx: 0) }
it { expect(subject).to eq(pending_job) }
it { is_expected.to eq(pending_job) }
end
context 'when artifacts of depended job has been expired' do
let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) }
it_behaves_like 'not pick'
context 'when the pipeline is locked' do
before do
pipeline.artifacts_locked!
end
it { is_expected.to eq(pending_job) }
end
context 'when the pipeline is unlocked' do
before do
pipeline.unlocked!
end
it_behaves_like 'not pick'
end
end
context 'when artifacts of depended job has been erased' do
......@@ -490,8 +504,12 @@ module Ci
let!(:pre_stage_job) { create(:ci_build, :success, :expired, pipeline: pipeline, name: 'test', stage_idx: 0) }
before do
allow_any_instance_of(Ci::Build).to receive(:drop!)
.and_raise(ActiveRecord::StaleObjectError.new(pending_job, :drop!))
pipeline.unlocked!
allow_next_instance_of(Ci::Build) do |build|
expect(build).to receive(:drop!)
.and_raise(ActiveRecord::StaleObjectError.new(pending_job, :drop!))
end
end
it 'does not drop nor pick' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment