BigW Consortium Gitlab

Commit 2a6a3737 by Kamil Trzciński Committed by LUKE BENNETT

Merge branch…

Merge branch '41023-activerecord-staleobjecterror--attempted-to-update-a-stale-object--ci-build' into 'master' Job dropping by MissingDependenciesError should consider StaleObjectError Closes #41023 See merge request gitlab-org/gitlab-ce!15873 (cherry picked from commit 6fff0473) 3494cdfe ActiveRecord::StaleObjectError: Attempted to update a stale object: Ci::Build
parent 90324cf7
......@@ -38,11 +38,15 @@ module Ci
begin
# In case when 2 runners try to assign the same build, second runner will be declined
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
build.runner_id = runner.id
build.run!
register_success(build)
return Result.new(build, true)
begin
build.runner_id = runner.id
build.run!
register_success(build)
return Result.new(build, true)
rescue Ci::Build::MissingDependenciesError
build.drop!(:missing_dependency_failure)
end
rescue StateMachines::InvalidTransition, ActiveRecord::StaleObjectError
# We are looping to find another build that is not conflicting
# It also indicates that this build can be picked and passed to runner.
......@@ -54,9 +58,6 @@ module Ci
# we still have to return 409 in the end,
# to make sure that this is properly handled by runner.
valid = false
rescue Ci::Build::MissingDependenciesError
build.drop!(:missing_dependency_failure)
valid = false
end
end
......
......@@ -307,6 +307,19 @@ module Ci
it_behaves_like 'not pick'
end
context 'when job object is staled' do
let!(:pre_stage_job) { create(:ci_build, :running, 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!))
end
it 'does not drop nor pick' do
expect(subject).to be_nil
end
end
end
shared_examples 'validation is not active' 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