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
332f0c00
Commit
332f0c00
authored
Jul 01, 2021
by
Pedro Pombeiro
Committed by
Andreas Brandl
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return 0 for project runner when no associated projects are found
parent
c11a677a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
30 deletions
+37
-30
app/graphql/types/ci/runner_type.rb
app/graphql/types/ci/runner_type.rb
+4
-4
spec/requests/api/graphql/ci/runner_spec.rb
spec/requests/api/graphql/ci/runner_spec.rb
+33
-26
No files found.
app/graphql/types/ci/runner_type.rb
View file @
332f0c00
...
...
@@ -53,14 +53,14 @@ module Types
# rubocop: disable CodeReuse/ActiveRecord
def
project_count
BatchLoader
::
GraphQL
.
for
(
runner
.
id
).
batch
(
key: :runner_project_count
)
do
|
id
s
,
loader
,
args
|
BatchLoader
::
GraphQL
.
for
(
runner
).
batch
(
key: :runner_project_count
)
do
|
runner
s
,
loader
,
args
|
counts
=
::
Ci
::
RunnerProject
.
select
(
:runner_id
,
'COUNT(*) as count'
)
.
where
(
runner_id:
ids
)
.
where
(
runner_id:
runners
.
map
(
&
:id
)
)
.
group
(
:runner_id
)
.
index_by
(
&
:runner_id
)
ids
.
each
do
|
id
|
loader
.
call
(
id
,
counts
[
id
]
&
.
count
)
runners
.
each
do
|
runner
|
loader
.
call
(
runner
,
counts
[
runner
.
id
]
&
.
count
||
(
runner
.
project_type?
?
0
:
nil
)
)
end
end
end
...
...
spec/requests/api/graphql/ci/runner_spec.rb
View file @
332f0c00
...
...
@@ -5,25 +5,25 @@ require 'spec_helper'
RSpec
.
describe
'Query.runner(id)'
do
include
GraphqlHelpers
let_it_be
(
:user
)
{
create
_default
(
:user
,
:admin
)
}
let_it_be
(
:user
)
{
create
(
:user
,
:admin
)
}
let_it_be
(
:active_runner
)
do
let_it_be
(
:active_
instance_
runner
)
do
create
(
:ci_runner
,
:instance
,
description:
'Runner 1'
,
contacted_at:
2
.
hours
.
ago
,
active:
true
,
version:
'adfe156'
,
revision:
'a'
,
locked:
true
,
ip_address:
'127.0.0.1'
,
maximum_timeout:
600
,
access_level:
0
,
tag_list:
%w[tag1 tag2]
,
run_untagged:
true
)
end
let_it_be
(
:inactive_runner
)
do
let_it_be
(
:inactive_
instance_
runner
)
do
create
(
:ci_runner
,
:instance
,
description:
'Runner 2'
,
contacted_at:
1
.
day
.
ago
,
active:
false
,
version:
'adfe157'
,
revision:
'b'
,
ip_address:
'10.10.10.10'
,
access_level:
1
,
run_untagged:
true
)
end
def
get_runner
(
id
)
case
id
when
:active_runner
active_runner
when
:inactive_runner
inactive_runner
when
:active_
instance_
runner
active_
instance_
runner
when
:inactive_
instance_
runner
inactive_
instance_
runner
end
end
...
...
@@ -86,7 +86,7 @@ RSpec.describe 'Query.runner(id)' do
end
describe
'for active runner'
do
it_behaves_like
'runner details fetch'
,
:active_runner
it_behaves_like
'runner details fetch'
,
:active_
instance_
runner
context
'when tagList is not requested'
do
let
(
:query
)
do
...
...
@@ -95,7 +95,7 @@ RSpec.describe 'Query.runner(id)' do
let
(
:query_path
)
do
[
[
:runner
,
{
id:
active_runner
.
to_global_id
.
to_s
}]
[
:runner
,
{
id:
active_
instance_
runner
.
to_global_id
.
to_s
}]
]
end
...
...
@@ -110,29 +110,30 @@ RSpec.describe 'Query.runner(id)' do
end
describe
'for inactive runner'
do
it_behaves_like
'runner details fetch'
,
:inactive_runner
it_behaves_like
'runner details fetch'
,
:inactive_
instance_
runner
end
describe
'for multiple runners'
do
let_it_be
(
:project1
)
{
create
(
:project
,
:test_repo
)
}
let_it_be
(
:project2
)
{
create
(
:project
,
:test_repo
)
}
let_it_be
(
:project_runner
)
do
create
(
:ci_runner
,
:project
,
projects:
[
project1
,
project2
],
description:
'Runner 1'
,
contacted_at:
2
.
hours
.
ago
,
active:
true
,
version:
'adfe156'
,
revision:
'a'
,
locked:
true
,
ip_address:
'127.0.0.1'
,
maximum_timeout:
600
,
access_level:
0
,
run_untagged:
true
)
end
let_it_be
(
:project_runner1
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project1
,
project2
],
description:
'Runner 1'
)
}
let_it_be
(
:project_runner2
)
{
create
(
:ci_runner
,
:project
,
projects:
[],
description:
'Runner 2'
)
}
let!
(
:job
)
{
create
(
:ci_build
,
runner:
project_runner
)
}
let!
(
:job
)
{
create
(
:ci_build
,
runner:
project_runner
1
)
}
context
'requesting project and job counts'
do
let
(
:query
)
do
%(
query {
projectRunner: runner(id: "#{project_runner.to_global_id}") {
projectRunner1: runner(id: "#{project_runner1.to_global_id}") {
projectCount
jobCount
}
projectRunner2: runner(id: "#{project_runner2.to_global_id}") {
projectCount
jobCount
}
active
Runner: runner(id: "#{activ
e_runner.to_global_id}") {
active
InstanceRunner: runner(id: "#{active_instanc
e_runner.to_global_id}") {
projectCount
jobCount
}
...
...
@@ -141,17 +142,23 @@ RSpec.describe 'Query.runner(id)' do
end
before
do
project_runner2
.
projects
.
clear
post_graphql
(
query
,
current_user:
user
)
end
it
'retrieves expected fields'
do
runner1_data
=
graphql_data_at
(
:project_runner
)
runner2_data
=
graphql_data_at
(
:active_runner
)
runner1_data
=
graphql_data_at
(
:project_runner1
)
runner2_data
=
graphql_data_at
(
:project_runner2
)
runner3_data
=
graphql_data_at
(
:active_instance_runner
)
expect
(
runner1_data
).
to
match
a_hash_including
(
'jobCount'
=>
1
,
'projectCount'
=>
2
)
expect
(
runner2_data
).
to
match
a_hash_including
(
'jobCount'
=>
0
,
'projectCount'
=>
0
)
expect
(
runner3_data
).
to
match
a_hash_including
(
'jobCount'
=>
0
,
'projectCount'
=>
nil
)
end
...
...
@@ -159,15 +166,15 @@ RSpec.describe 'Query.runner(id)' do
end
describe
'by regular user'
do
let
(
:user
)
{
create
_default
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
it_behaves_like
'retrieval by unauthorized user'
,
:active_runner
it_behaves_like
'retrieval by unauthorized user'
,
:active_
instance_
runner
end
describe
'by unauthenticated user'
do
let
(
:user
)
{
nil
}
it_behaves_like
'retrieval by unauthorized user'
,
:active_runner
it_behaves_like
'retrieval by unauthorized user'
,
:active_
instance_
runner
end
describe
'Query limits'
do
...
...
@@ -185,7 +192,7 @@ RSpec.describe 'Query.runner(id)' do
let
(
:single_query
)
do
<<~
QUERY
{
active:
#{
runner_query
(
active_runner
)
}
active:
#{
runner_query
(
active_
instance_
runner
)
}
}
QUERY
end
...
...
@@ -193,8 +200,8 @@ RSpec.describe 'Query.runner(id)' do
let
(
:double_query
)
do
<<~
QUERY
{
active:
#{
runner_query
(
active_runner
)
}
inactive:
#{
runner_query
(
inactive_runner
)
}
active:
#{
runner_query
(
active_
instance_
runner
)
}
inactive:
#{
runner_query
(
inactive_
instance_
runner
)
}
}
QUERY
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