Skip to content
Snippets Groups Projects
Commit 5f00b2e9 authored by Bala Kumar Subramani's avatar Bala Kumar Subramani
Browse files

Fix stale object error in Environment Stop

Changelog: fixed
parent 7568227e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -273,7 +273,15 @@ def stop_with_action!(current_user)
return unless available?
 
stop!
stop_action&.play(current_user)
return unless stop_action
Gitlab::OptimisticLocking.retry_lock(
stop_action,
name: 'environment_stop_with_action'
) do |build|
build&.play(current_user)
end
end
 
def reset_auto_stop
Loading
Loading
Loading
Loading
@@ -586,6 +586,31 @@
expect(subject.user).to eq(user)
end
end
context 'close action does not raise ActiveRecord::StaleObjectError' do
let!(:close_action) do
create(:ci_build, :manual, pipeline: pipeline, name: 'close_app')
end
before do
# preload the build
environment.stop_action
# Update record as the other process. This makes `environment.stop_action` stale.
close_action.drop!
end
it 'successfully plays the build even if the build was a stale object' do
# Since build is droped.
expect(close_action.processed).to be_falsey
# it encounters the StaleObjectError at first, but reloads the object and runs `build.play`
expect { subject }.not_to raise_error(ActiveRecord::StaleObjectError)
# Now the build should be processed.
expect(close_action.reload.processed).to be_truthy
end
end
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment