Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
bf59c67da4bb
Commit
d8aed6a2
authored
Oct 26, 2016
by
Kamil Trzcinski
Browse files
Fix optimistic locking
parent
054efa452bc1
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/models/commit_status.rb
View file @
bf59c67d
...
...
@@ -73,16 +73,16 @@ class CommitStatus < ActiveRecord::Base
transition
[
:created
,
:pending
,
:running
]
=>
:canceled
end
after
_transition
created:
[
:pending
,
:running
]
do
|
commit_status
|
commit_status
.
update_attributes
queued_at
:
Time
.
now
before
_transition
created:
[
:pending
,
:running
]
do
|
commit_status
|
commit_status
.
queued_at
=
Time
.
now
end
after
_transition
[
:created
,
:pending
]
=>
:running
do
|
commit_status
|
commit_status
.
update_attributes
started_at
:
Time
.
now
before
_transition
[
:created
,
:pending
]
=>
:running
do
|
commit_status
|
commit_status
.
started_at
=
Time
.
now
end
after
_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
commit_status
|
commit_status
.
update_attributes
finished_at
:
Time
.
now
before
_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
commit_status
|
commit_status
.
finished_at
=
Time
.
now
end
after_transition
do
|
commit_status
,
transition
|
...
...
app/services/ci/process_pipeline_service.rb
View file @
bf59c67d
...
...
@@ -40,10 +40,12 @@ def process_stage(index)
def
process_build
(
build
,
current_status
)
if
valid_statuses_for_when
(
build
.
when
).
include?
(
current_status
)
build
.
enqueue
r
=
build
.
enqueue
puts
"process_build:
#{
build
.
id
}
: enqueue:
#{
build
.
status
}
=>
#{
r
}
"
true
else
build
.
skip
r
=
build
.
skip
puts
"process_build:
#{
build
.
id
}
: skip:
#{
build
.
status
}
=>
#{
r
}
"
false
end
end
...
...
spec/lib/gitlab/import_export/safe_model_attributes.yml
View file @
bf59c67d
...
...
@@ -178,6 +178,7 @@ Ci::Pipeline:
-
finished_at
-
duration
-
user_id
-
lock_version
CommitStatus
:
-
id
-
project_id
...
...
@@ -217,6 +218,7 @@ CommitStatus:
-
yaml_variables
-
queued_at
-
token
-
lock_version
Ci::Variable:
-
id
-
project_id
...
...
spec/models/ci/pipeline_spec.rb
View file @
bf59c67d
...
...
@@ -138,9 +138,9 @@ def create_build(name, status)
describe
'state machine'
do
let
(
:current
)
{
Time
.
now
.
change
(
usec:
0
)
}
let
(
:build
)
{
create_build
(
'build1'
,
current
,
1
0
)
}
let
(
:build_b
)
{
create_build
(
'build2'
,
current
,
2
0
)
}
let
(
:build_c
)
{
create_build
(
'build3'
,
current
+
50
,
1
0
)
}
let
(
:build
)
{
create_build
(
'build1'
,
0
)
}
let
(
:build_b
)
{
create_build
(
'build2'
,
0
)
}
let
(
:build_c
)
{
create_build
(
'build3'
,
0
)
}
describe
'#duration'
do
before
do
...
...
@@ -163,11 +163,12 @@ def create_build(name, status)
build_c
.
success
end
pipeline
.
drop
# We have to reload pipeline, because its status is updated by processing builds
pipeline
.
reload
.
drop
end
it
'matches sum of builds duration'
do
pipeline
.
reload
binding
.
pry
expect
(
pipeline
.
duration
).
to
eq
(
40
)
end
...
...
@@ -455,7 +456,9 @@ def create_build(name, queued_at = current, started_from = 0)
context
'when all builds succeed'
do
before
do
build_a
.
success
build_b
.
success
# We have to reload build_b as this is in next stage and it gets triggered by PipelineProcessWorker
build_b
.
reload
.
success
end
it
'receives a success event once'
do
...
...
spec/requests/api/builds_spec.rb
View file @
bf59c67d
...
...
@@ -277,6 +277,7 @@ def path_for_ref(ref = pipeline.ref, job = build.name)
context
'with regular branch'
do
before
do
pipeline
.
reload
pipeline
.
update
(
ref:
'master'
,
sha:
project
.
commit
(
'master'
).
sha
)
...
...
@@ -288,6 +289,7 @@ def path_for_ref(ref = pipeline.ref, job = build.name)
context
'with branch name containing slash'
do
before
do
pipeline
.
reload
pipeline
.
update
(
ref:
'improve/awesome'
,
sha:
project
.
commit
(
'improve/awesome'
).
sha
)
end
...
...
spec/services/ci/register_build_service_spec.rb
View file @
bf59c67d
...
...
@@ -101,11 +101,11 @@ module Ci
it
'equalises number of running builds'
do
# after finishing the first build for project 1, get a second build from the same project
expect
(
service
.
execute
(
shared_runner
)).
to
eq
(
build1_project1
)
build1_project1
.
success
build1_project1
.
reload
.
success
expect
(
service
.
execute
(
shared_runner
)).
to
eq
(
build2_project1
)
expect
(
service
.
execute
(
shared_runner
)).
to
eq
(
build1_project2
)
build1_project2
.
success
build1_project2
.
reload
.
success
expect
(
service
.
execute
(
shared_runner
)).
to
eq
(
build2_project2
)
expect
(
service
.
execute
(
shared_runner
)).
to
eq
(
build1_project3
)
expect
(
service
.
execute
(
shared_runner
)).
to
eq
(
build3_project1
)
...
...
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
View file @
bf59c67d
...
...
@@ -147,6 +147,7 @@
expect
(
MergeWorker
).
not_to
receive
(
:perform_async
)
build
.
success
test
.
reload
test
.
drop
end
...
...
@@ -154,6 +155,7 @@
expect
(
MergeWorker
).
to
receive
(
:perform_async
)
build
.
success
test
.
reload
test
.
success
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