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
7112bd9a
Commit
7112bd9a
authored
Sep 16, 2021
by
Maxime Orefice
Committed by
Grzegorz Bizon
Sep 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add scopes for pending builds tags
parent
203b5077
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
1 deletion
+56
-1
app/models/ci/pending_build.rb
app/models/ci/pending_build.rb
+7
-0
app/services/ci/queue/pending_builds_strategy.rb
app/services/ci/queue/pending_builds_strategy.rb
+1
-1
spec/factories/ci/pending_builds.rb
spec/factories/ci/pending_builds.rb
+1
-0
spec/models/ci/pending_build_spec.rb
spec/models/ci/pending_build_spec.rb
+41
-0
spec/services/ci/register_job_service_spec.rb
spec/services/ci/register_job_service_spec.rb
+6
-0
No files found.
app/models/ci/pending_build.rb
View file @
7112bd9a
...
...
@@ -13,6 +13,13 @@ module Ci
scope
:ref_protected
,
->
{
where
(
protected:
true
)
}
scope
:queued_before
,
->
(
time
)
{
where
(
arel_table
[
:created_at
].
lt
(
time
))
}
scope
:with_instance_runners
,
->
{
where
(
instance_runners_enabled:
true
)
}
scope
:for_tags
,
->
(
tag_ids
)
do
if
tag_ids
.
present?
where
(
'ci_pending_builds.tag_ids <@ ARRAY[?]::int[]'
,
Array
.
wrap
(
tag_ids
))
else
where
(
"ci_pending_builds.tag_ids = '{}'"
)
end
end
class
<<
self
def
upsert_from_build!
(
build
)
...
...
app/services/ci/queue/pending_builds_strategy.rb
View file @
7112bd9a
...
...
@@ -24,7 +24,7 @@ module Ci
def
builds_matching_tag_ids
(
relation
,
ids
)
if
::
Feature
.
enabled?
(
:ci_queueing_denormalize_tags_information
,
runner
,
default_enabled: :yaml
)
relation
.
where
(
'tag_ids <@ ARRAY[?]::int[]'
,
runner
.
tags_ids
)
relation
.
for_tags
(
runner
.
tags_ids
)
else
relation
.
merge
(
CommitStatus
.
matches_tag_ids
(
ids
,
table:
'ci_pending_builds'
,
column:
'build_id'
))
end
...
...
spec/factories/ci/pending_builds.rb
View file @
7112bd9a
...
...
@@ -8,5 +8,6 @@ FactoryBot.define do
instance_runners_enabled
{
true
}
namespace
{
project
.
namespace
}
minutes_exceeded
{
false
}
tag_ids
{
build
.
tags_ids
}
end
end
spec/models/ci/pending_build_spec.rb
View file @
7112bd9a
...
...
@@ -34,6 +34,47 @@ RSpec.describe Ci::PendingBuild do
end
end
end
describe
'.for_tags'
do
subject
(
:pending_builds
)
{
described_class
.
for_tags
(
tag_ids
)
}
let_it_be
(
:pending_build_with_tags
)
{
create
(
:ci_pending_build
,
tag_ids:
[
1
,
2
])
}
let_it_be
(
:pending_build_without_tags
)
{
create
(
:ci_pending_build
)
}
context
'when tag_ids match pending builds'
do
let
(
:tag_ids
)
{
[
1
,
2
]
}
it
'returns matching pending builds'
do
expect
(
pending_builds
).
to
contain_exactly
(
pending_build_with_tags
,
pending_build_without_tags
)
end
end
context
'when tag_ids does not match pending builds'
do
let
(
:tag_ids
)
{
[
non_existing_record_id
]
}
it
'returns matching pending builds without tags'
do
expect
(
pending_builds
).
to
contain_exactly
(
pending_build_without_tags
)
end
end
context
'when tag_ids is not provided'
do
context
'with a nil value'
do
let
(
:tag_ids
)
{
nil
}
it
'returns matching pending builds without tags'
do
expect
(
pending_builds
).
to
contain_exactly
(
pending_build_without_tags
)
end
end
context
'with an empty array'
do
let
(
:tag_ids
)
{
[]
}
it
'returns matching pending builds without tags'
do
expect
(
pending_builds
).
to
contain_exactly
(
pending_build_without_tags
)
end
end
end
end
end
describe
'.upsert_from_build!'
do
...
...
spec/services/ci/register_job_service_spec.rb
View file @
7112bd9a
...
...
@@ -40,12 +40,16 @@ module Ci
context
'runner follow tag list'
do
it
"picks build with the same tag"
do
pending_job
.
update!
(
tag_list:
[
"linux"
])
pending_job
.
reload
pending_job
.
create_queuing_entry!
specific_runner
.
update!
(
tag_list:
[
"linux"
])
expect
(
execute
(
specific_runner
)).
to
eq
(
pending_job
)
end
it
"does not pick build with different tag"
do
pending_job
.
update!
(
tag_list:
[
"linux"
])
pending_job
.
reload
pending_job
.
create_queuing_entry!
specific_runner
.
update!
(
tag_list:
[
"win32"
])
expect
(
execute
(
specific_runner
)).
to
be_falsey
end
...
...
@@ -56,6 +60,8 @@ module Ci
it
"does not pick build with tag"
do
pending_job
.
update!
(
tag_list:
[
"linux"
])
pending_job
.
reload
pending_job
.
create_queuing_entry!
expect
(
execute
(
specific_runner
)).
to
be_falsey
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