Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5f00b2e9
Commit
5f00b2e9
authored
Apr 04, 2022
by
Bala Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix stale object error in Environment Stop
Changelog: fixed
parent
7568227e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
1 deletion
+34
-1
app/models/environment.rb
app/models/environment.rb
+9
-1
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+25
-0
No files found.
app/models/environment.rb
View file @
5f00b2e9
...
...
@@ -273,7 +273,15 @@ class Environment < ApplicationRecord
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
...
...
spec/models/environment_spec.rb
View file @
5f00b2e9
...
...
@@ -586,6 +586,31 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment