diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 2cacf04a791..96d9fba2a2d 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1891,11 +1891,7 @@ describe Ci::Build do let(:options) { { dependencies: ['test'] } } context 'when a depended job exists' do - let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0) } - - it { expect { build.run! }.not_to raise_error } - - context 'when "artifacts" keyword is specified on depended job' do + context 'when depended job has artifacts' do let!(:pre_stage_job) do create(:ci_build, :success, @@ -1906,22 +1902,36 @@ describe Ci::Build do options: { artifacts: { paths: ['binaries/'] } } ) end - context 'when artifacts of depended job has existsed' do - it { expect { build.run! }.not_to raise_error } - end - - context 'when artifacts of depended job has not existsed' do - before do - pre_stage_job.erase_artifacts! - end - - it { expect { build.run! }.to raise_error(Ci::Build::MissingDependenciesError) } - end + it { expect { build.run! }.not_to raise_error } end - end - context 'when depended jobs do not exist' do - it { expect { build.run! }.to raise_error(Ci::Build::MissingDependenciesError) } + context 'when depended job does not have artifacts' do + let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0) } + + it { expect { build.run! }.not_to raise_error } + end + + context 'when depended job has not been completed yet' do + let!(:pre_stage_job) { create(:ci_build, :running, pipeline: pipeline, name: 'test', stage_idx: 0) } + + it { expect { build.run! }.to raise_error(Ci::Build::MissingDependenciesError) } + 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 { expect { build.run! }.to raise_error(Ci::Build::MissingDependenciesError) } + end + + context 'when artifacts of depended job has been erased' do + let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0, erased_at: 1.minute.ago) } + + before do + pre_stage_job.erase + end + + it { expect { build.run! }.to raise_error(Ci::Build::MissingDependenciesError) } + end end end end diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index b86b9d7a42b..19e78faa591 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -277,6 +277,10 @@ module Ci end context 'when "dependencies" keyword is specified' do + before do + stub_feature_flags(ci_validates_dependencies: true) + end + let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: job_name, stage_idx: 0) } let!(:pending_job) do @@ -311,7 +315,7 @@ module Ci context 'when artifacts of depended job has not existsed' do before do - pre_stage_job.erase_artifacts! + pre_stage_job.erase end it 'does not pick the build and drops the build' do @@ -322,16 +326,6 @@ module Ci end end end - - context 'when depended jobs do not exist' do - let(:job_name) { 'robocop' } - - it 'does not pick the build and drops the build' do - expect(picked_job).to be_nil - expect(pending_job.reload).to be_failed - expect(pending_job).to be_missing_dependency_failure - end - end end def execute(runner)