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
fb54a2d4
Commit
fb54a2d4
authored
Apr 30, 2020
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mark UpdateHeadPipelineForMergeRequestWorker as idempotent
parent
35404de2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
11 deletions
+60
-11
app/workers/all_queues.yml
app/workers/all_queues.yml
+1
-1
app/workers/update_head_pipeline_for_merge_request_worker.rb
app/workers/update_head_pipeline_for_merge_request_worker.rb
+3
-1
spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb
...ers/update_head_pipeline_for_merge_request_worker_spec.rb
+56
-9
No files found.
app/workers/all_queues.yml
View file @
fb54a2d4
...
@@ -863,7 +863,7 @@
...
@@ -863,7 +863,7 @@
:urgency: :high
:urgency: :high
:resource_boundary: :cpu
:resource_boundary: :cpu
:weight:
5
:weight:
5
:idempotent:
:idempotent:
true
-
:name: repository_check:repository_check_batch
-
:name: repository_check:repository_check_batch
:feature_category: :source_code_management
:feature_category: :source_code_management
:has_external_dependencies:
:has_external_dependencies:
...
...
app/workers/update_head_pipeline_for_merge_request_worker.rb
View file @
fb54a2d4
# frozen_string_literal: true
# frozen_string_literal: true
class
UpdateHeadPipelineForMergeRequestWorker
# rubocop:disable Scalability/IdempotentWorker
class
UpdateHeadPipelineForMergeRequestWorker
include
ApplicationWorker
include
ApplicationWorker
include
PipelineQueue
include
PipelineQueue
...
@@ -9,6 +9,8 @@ class UpdateHeadPipelineForMergeRequestWorker # rubocop:disable Scalability/Idem
...
@@ -9,6 +9,8 @@ class UpdateHeadPipelineForMergeRequestWorker # rubocop:disable Scalability/Idem
urgency
:high
urgency
:high
worker_resource_boundary
:cpu
worker_resource_boundary
:cpu
idempotent!
def
perform
(
merge_request_id
)
def
perform
(
merge_request_id
)
MergeRequest
.
find_by_id
(
merge_request_id
).
try
do
|
merge_request
|
MergeRequest
.
find_by_id
(
merge_request_id
).
try
do
|
merge_request
|
merge_request
.
update_head_pipeline
merge_request
.
update_head_pipeline
...
...
spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb
View file @
fb54a2d4
...
@@ -4,18 +4,27 @@ require 'spec_helper'
...
@@ -4,18 +4,27 @@ require 'spec_helper'
describe
UpdateHeadPipelineForMergeRequestWorker
do
describe
UpdateHeadPipelineForMergeRequestWorker
do
describe
'#perform'
do
describe
'#perform'
do
let
(
:user
)
{
create
(
:user
)
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
_it_be
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:latest_sha
)
{
'b83d6e391c22777fca1ed3012fce84f633d7fed0'
}
let
_it_be
(
:latest_sha
)
{
'b83d6e391c22777fca1ed3012fce84f633d7fed0'
}
context
'when pipeline exists for the source project and branch'
do
context
'when pipeline exists for the source project and branch'
do
before
do
let_it_be
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
,
ref:
merge_request
.
source_branch
,
sha:
latest_sha
)
}
create
(
:ci_empty_pipeline
,
project:
project
,
ref:
merge_request
.
source_branch
,
sha:
latest_sha
)
end
it
'updates the head_pipeline_id of the merge_request'
do
it
'updates the head_pipeline_id of the merge_request'
do
expect
{
subject
.
perform
(
merge_request
.
id
)
}.
to
change
{
merge_request
.
reload
.
head_pipeline_id
}
expect
{
subject
.
perform
(
merge_request
.
id
)
}
.
to
change
{
merge_request
.
reload
.
head_pipeline_id
}.
from
(
nil
).
to
(
pipeline
.
id
)
end
it_behaves_like
'an idempotent worker'
do
let
(
:job_args
)
{
merge_request
.
id
}
it
'sets the pipeline as the head pipeline when run multiple times'
do
subject
expect
(
merge_request
.
reload
.
head_pipeline_id
).
to
eq
(
pipeline
.
id
)
end
end
end
context
'when merge request sha does not equal pipeline sha'
do
context
'when merge request sha does not equal pipeline sha'
do
...
@@ -27,6 +36,15 @@ describe UpdateHeadPipelineForMergeRequestWorker do
...
@@ -27,6 +36,15 @@ describe UpdateHeadPipelineForMergeRequestWorker do
expect
{
subject
.
perform
(
merge_request
.
id
)
}
expect
{
subject
.
perform
(
merge_request
.
id
)
}
.
not_to
change
{
merge_request
.
reload
.
head_pipeline_id
}
.
not_to
change
{
merge_request
.
reload
.
head_pipeline_id
}
end
end
it_behaves_like
'an idempotent worker'
do
let
(
:job_args
)
{
merge_request
.
id
}
it
'does not update the head_pipeline_id when run multiple times'
do
expect
{
subject
}
.
not_to
change
{
merge_request
.
reload
.
head_pipeline_id
}
end
end
end
end
end
end
...
@@ -35,10 +53,19 @@ describe UpdateHeadPipelineForMergeRequestWorker do
...
@@ -35,10 +53,19 @@ describe UpdateHeadPipelineForMergeRequestWorker do
expect
{
subject
.
perform
(
merge_request
.
id
)
}
expect
{
subject
.
perform
(
merge_request
.
id
)
}
.
not_to
change
{
merge_request
.
reload
.
head_pipeline_id
}
.
not_to
change
{
merge_request
.
reload
.
head_pipeline_id
}
end
end
it_behaves_like
'an idempotent worker'
do
let
(
:job_args
)
{
merge_request
.
id
}
it
'does not update the head_pipeline_id when run multiple times'
do
expect
{
subject
}
.
not_to
change
{
merge_request
.
reload
.
head_pipeline_id
}
end
end
end
end
context
'when a merge request pipeline exists'
do
context
'when a merge request pipeline exists'
do
let
!
(
:merge_request_pipeline
)
do
let
_it_be
(
:merge_request_pipeline
)
do
create
(
:ci_pipeline
,
create
(
:ci_pipeline
,
project:
project
,
project:
project
,
source: :merge_request_event
,
source: :merge_request_event
,
...
@@ -52,6 +79,16 @@ describe UpdateHeadPipelineForMergeRequestWorker do
...
@@ -52,6 +79,16 @@ describe UpdateHeadPipelineForMergeRequestWorker do
.
from
(
nil
).
to
(
merge_request_pipeline
.
id
)
.
from
(
nil
).
to
(
merge_request_pipeline
.
id
)
end
end
it_behaves_like
'an idempotent worker'
do
let
(
:job_args
)
{
merge_request
.
id
}
it
'sets the merge request pipeline as the head pipeline when run multiple times'
do
subject
expect
(
merge_request
.
reload
.
head_pipeline_id
).
to
eq
(
merge_request_pipeline
.
id
)
end
end
context
'when branch pipeline exists'
do
context
'when branch pipeline exists'
do
let!
(
:branch_pipeline
)
do
let!
(
:branch_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
source: :push
,
sha:
latest_sha
)
create
(
:ci_pipeline
,
project:
project
,
source: :push
,
sha:
latest_sha
)
...
@@ -62,6 +99,16 @@ describe UpdateHeadPipelineForMergeRequestWorker do
...
@@ -62,6 +99,16 @@ describe UpdateHeadPipelineForMergeRequestWorker do
.
to
change
{
merge_request
.
reload
.
head_pipeline_id
}
.
to
change
{
merge_request
.
reload
.
head_pipeline_id
}
.
from
(
nil
).
to
(
merge_request_pipeline
.
id
)
.
from
(
nil
).
to
(
merge_request_pipeline
.
id
)
end
end
it_behaves_like
'an idempotent worker'
do
let
(
:job_args
)
{
merge_request
.
id
}
it
'sets the merge request pipeline as the head pipeline when run multiple times'
do
subject
expect
(
merge_request
.
reload
.
head_pipeline_id
).
to
eq
(
merge_request_pipeline
.
id
)
end
end
end
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