BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
47b2add4
Commit
47b2add4
authored
Oct 21, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for optimistic locking
parent
5d7ee7a1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
7 deletions
+38
-7
CHANGELOG.md
CHANGELOG.md
+1
-0
pipeline.rb
app/models/ci/pipeline.rb
+1
-1
register_build_service.rb
app/services/ci/register_build_service.rb
+1
-1
optimistic_locking.rb
lib/gitlab/optimistic_locking.rb
+7
-5
optimistic_locking_spec.rb
spec/lib/gitlab/optimistic_locking_spec.rb
+28
-0
No files found.
CHANGELOG.md
View file @
47b2add4
...
...
@@ -66,6 +66,7 @@ Please view this file on the master branch, on stable branches it's out of date.
-
Updating verbiage on git basics to be more intuitive
-
Fix project_feature record not generated on project creation
-
Clarify documentation for Runners API (Gennady Trafimenkov)
-
Use optimistic locking for pipelines and builds
-
The instrumentation for Banzai::Renderer has been restored
-
Change user & group landing page routing from /u/:username to /:username
-
Added documentation for .gitattributes files
...
...
app/models/ci/pipeline.rb
View file @
47b2add4
...
...
@@ -260,7 +260,7 @@ module Ci
end
def
update_status
Gitlab
::
OptimisticLocking
.
retry_lock
(
build
)
do
Gitlab
::
OptimisticLocking
.
retry_lock
(
self
)
do
case
latest_builds_status
when
'pending'
then
enqueue
when
'running'
then
run
...
...
app/services/ci/register_build_service.rb
View file @
47b2add4
...
...
@@ -35,7 +35,7 @@ module Ci
build
rescue
StateMachines
::
InvalidTransition
,
StaleObjectError
rescue
StateMachines
::
InvalidTransition
,
ActiveRecord
::
StaleObjectError
nil
end
...
...
lib/gitlab/optimistic_locking.rb
View file @
47b2add4
module
Gitlab
module
OptimisticLocking
def
retry_lock
(
subject
,
&
block
)
while
true
do
class
OptimisticLocking
def
self
.
retry_lock
(
subject
,
&
block
)
loop
do
begin
return
yield
subject
rescue
StaleObjectError
subject
.
transaction
do
return
block
.
call
(
subject
)
end
rescue
ActiveRecord
::
StaleObjectError
subject
.
reload
end
end
...
...
spec/lib/gitlab/optimistic_locking_spec.rb
0 → 100644
View file @
47b2add4
require
'spec_helper'
describe
Gitlab
::
OptimisticLocking
,
lib:
true
do
describe
'#retry_lock'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let!
(
:pipeline2
)
{
Ci
::
Pipeline
.
find
(
pipeline
.
id
)
}
it
'does not reload object if state changes'
do
expect
(
pipeline
).
not_to
receive
(
:reload
)
expect
(
pipeline
).
to
receive
(
:succeed
).
and_call_original
described_class
.
retry_lock
(
pipeline
)
do
|
subject
|
subject
.
succeed
end
end
it
'retries action if exception is raised'
do
pipeline
.
succeed
expect
(
pipeline2
).
to
receive
(
:reload
).
and_call_original
expect
(
pipeline2
).
to
receive
(
:drop
).
twice
.
and_call_original
described_class
.
retry_lock
(
pipeline2
)
do
|
subject
|
subject
.
drop
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