2020-08-11 11:10:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-11-24 22:09:43 -05:00
|
|
|
RSpec.describe 'Query.project.pipeline' do
|
2020-08-11 11:10:08 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
|
2020-11-24 22:09:43 -05:00
|
|
|
let_it_be(:project) { create(:project, :repository, :public) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
def all(*fields)
|
|
|
|
fields.flat_map { |f| [f, :nodes] }
|
2020-08-11 11:10:08 -04:00
|
|
|
end
|
|
|
|
|
2020-11-24 22:09:43 -05:00
|
|
|
describe '.stages.groups.jobs' do
|
|
|
|
let(:pipeline) do
|
|
|
|
pipeline = create(:ci_pipeline, project: project, user: user)
|
2021-11-22 19:12:54 -05:00
|
|
|
stage = create(:ci_stage_entity, project: project, pipeline: pipeline, name: 'first', position: 1)
|
2021-12-03 10:10:36 -05:00
|
|
|
create(:ci_build, stage_id: stage.id, pipeline: pipeline, name: 'my test job', scheduling_type: :stage)
|
2020-11-24 22:09:43 -05:00
|
|
|
|
|
|
|
pipeline
|
|
|
|
end
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
let(:jobs_graphql_data) { graphql_data_at(:project, :pipeline, *all(:stages, :groups, :jobs)) }
|
|
|
|
|
|
|
|
let(:first_n) { var('Int') }
|
2020-11-24 22:09:43 -05:00
|
|
|
|
|
|
|
let(:query) do
|
2020-12-23 19:10:25 -05:00
|
|
|
with_signature([first_n], wrap_fields(query_graphql_path([
|
|
|
|
[:project, { full_path: project.full_path }],
|
|
|
|
[:pipeline, { iid: pipeline.iid.to_s }],
|
|
|
|
[:stages, { first: first_n }]
|
|
|
|
], stage_fields)))
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:stage_fields) do
|
|
|
|
<<~FIELDS
|
|
|
|
nodes {
|
|
|
|
name
|
|
|
|
groups {
|
|
|
|
nodes {
|
2021-07-14 17:09:44 -04:00
|
|
|
detailedStatus {
|
|
|
|
id
|
|
|
|
}
|
2020-12-23 19:10:25 -05:00
|
|
|
name
|
|
|
|
jobs {
|
|
|
|
nodes {
|
2021-12-22 19:11:02 -05:00
|
|
|
downstreamPipeline {
|
|
|
|
id
|
|
|
|
path
|
|
|
|
}
|
2020-12-23 19:10:25 -05:00
|
|
|
name
|
2021-01-06 16:10:18 -05:00
|
|
|
needs {
|
|
|
|
nodes { #{all_graphql_fields_for('CiBuildNeed')} }
|
|
|
|
}
|
2021-12-03 10:10:36 -05:00
|
|
|
previousStageJobsOrNeeds {
|
2021-11-22 19:12:54 -05:00
|
|
|
nodes {
|
2021-12-17 07:16:21 -05:00
|
|
|
... on CiBuildNeed {
|
|
|
|
#{all_graphql_fields_for('CiBuildNeed')}
|
|
|
|
}
|
|
|
|
... on CiJob {
|
|
|
|
#{all_graphql_fields_for('CiJob')}
|
|
|
|
}
|
|
|
|
}
|
2021-11-22 19:12:54 -05:00
|
|
|
}
|
|
|
|
detailedStatus {
|
|
|
|
id
|
|
|
|
}
|
2020-12-23 19:10:25 -05:00
|
|
|
pipeline {
|
|
|
|
id
|
2020-08-11 11:10:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-23 19:10:25 -05:00
|
|
|
}
|
|
|
|
FIELDS
|
2020-11-24 22:09:43 -05:00
|
|
|
end
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2020-11-24 22:09:43 -05:00
|
|
|
it 'returns the jobs of a pipeline stage' do
|
|
|
|
post_graphql(query, current_user: user)
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2020-11-24 22:09:43 -05:00
|
|
|
expect(jobs_graphql_data).to contain_exactly(a_hash_including('name' => 'my test job'))
|
|
|
|
end
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2021-11-22 19:12:54 -05:00
|
|
|
context 'when there is more than one stage and job needs' do
|
2020-12-23 19:10:25 -05:00
|
|
|
before do
|
|
|
|
build_stage = create(:ci_stage_entity, position: 2, name: 'build', project: project, pipeline: pipeline)
|
|
|
|
test_stage = create(:ci_stage_entity, position: 3, name: 'test', project: project, pipeline: pipeline)
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2021-12-03 10:10:36 -05:00
|
|
|
create(:ci_build, pipeline: pipeline, name: 'docker 1 2', scheduling_type: :stage, stage: build_stage, stage_idx: build_stage.position)
|
|
|
|
create(:ci_build, pipeline: pipeline, name: 'docker 2 2', stage: build_stage, stage_idx: build_stage.position, scheduling_type: :dag)
|
|
|
|
create(:ci_build, pipeline: pipeline, name: 'rspec 1 2', scheduling_type: :stage, stage: test_stage, stage_idx: test_stage.position)
|
|
|
|
test_job = create(:ci_build, pipeline: pipeline, name: 'rspec 2 2', scheduling_type: :dag, stage: test_stage, stage_idx: test_stage.position)
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2021-11-22 19:12:54 -05:00
|
|
|
create(:ci_build_need, build: test_job, name: 'my test job')
|
2020-12-23 19:10:25 -05:00
|
|
|
end
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2021-12-07 19:15:00 -05:00
|
|
|
it 'reports the build needs and execution requirements', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/347290' do
|
2021-11-22 19:12:54 -05:00
|
|
|
post_graphql(query, current_user: user)
|
2020-08-11 11:10:08 -04:00
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
expect(jobs_graphql_data).to contain_exactly(
|
2021-11-22 19:12:54 -05:00
|
|
|
a_hash_including(
|
|
|
|
'name' => 'my test job',
|
|
|
|
'needs' => { 'nodes' => [] },
|
2021-12-03 10:10:36 -05:00
|
|
|
'previousStageJobsOrNeeds' => { 'nodes' => [] }
|
2021-11-22 19:12:54 -05:00
|
|
|
),
|
|
|
|
a_hash_including(
|
|
|
|
'name' => 'docker 1 2',
|
|
|
|
'needs' => { 'nodes' => [] },
|
2021-12-03 10:10:36 -05:00
|
|
|
'previousStageJobsOrNeeds' => { 'nodes' => [
|
2021-12-17 07:16:21 -05:00
|
|
|
a_hash_including( 'name' => 'my test job' )
|
2021-11-22 19:12:54 -05:00
|
|
|
] }
|
|
|
|
),
|
|
|
|
a_hash_including(
|
|
|
|
'name' => 'docker 2 2',
|
|
|
|
'needs' => { 'nodes' => [] },
|
2021-12-03 10:10:36 -05:00
|
|
|
'previousStageJobsOrNeeds' => { 'nodes' => [] }
|
2021-11-22 19:12:54 -05:00
|
|
|
),
|
|
|
|
a_hash_including(
|
|
|
|
'name' => 'rspec 1 2',
|
|
|
|
'needs' => { 'nodes' => [] },
|
2021-12-03 10:10:36 -05:00
|
|
|
'previousStageJobsOrNeeds' => { 'nodes' => [
|
2021-12-17 07:16:21 -05:00
|
|
|
a_hash_including('name' => 'docker 1 2'),
|
|
|
|
a_hash_including('name' => 'docker 2 2')
|
2021-11-22 19:12:54 -05:00
|
|
|
] }
|
|
|
|
),
|
|
|
|
a_hash_including(
|
|
|
|
'name' => 'rspec 2 2',
|
|
|
|
'needs' => { 'nodes' => [a_hash_including('name' => 'my test job')] },
|
2021-12-03 10:10:36 -05:00
|
|
|
'previousStageJobsOrNeeds' => { 'nodes' => [
|
2021-12-17 07:16:21 -05:00
|
|
|
a_hash_including('name' => 'my test job' )
|
2021-11-22 19:12:54 -05:00
|
|
|
] }
|
|
|
|
)
|
2020-12-23 19:10:25 -05:00
|
|
|
)
|
2020-08-11 11:10:08 -04:00
|
|
|
end
|
2020-12-23 19:10:25 -05:00
|
|
|
|
2021-07-27 20:10:24 -04:00
|
|
|
it 'does not generate N+1 queries', :request_store, :use_sql_query_cache do
|
2021-12-22 19:11:02 -05:00
|
|
|
create(:ci_bridge, name: 'bridge-1', pipeline: pipeline, downstream_pipeline: create(:ci_pipeline))
|
|
|
|
|
2021-07-27 20:10:24 -04:00
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
|
|
|
|
control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
|
|
|
|
post_graphql(query, current_user: user)
|
2020-12-23 19:10:25 -05:00
|
|
|
end
|
|
|
|
|
2021-07-27 20:10:24 -04:00
|
|
|
create(:ci_build, name: 'test-a', pipeline: pipeline)
|
|
|
|
create(:ci_build, name: 'test-b', pipeline: pipeline)
|
2021-12-22 19:11:02 -05:00
|
|
|
create(:ci_bridge, name: 'bridge-2', pipeline: pipeline, downstream_pipeline: create(:ci_pipeline))
|
|
|
|
create(:ci_bridge, name: 'bridge-3', pipeline: pipeline, downstream_pipeline: create(:ci_pipeline))
|
2021-07-27 20:10:24 -04:00
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
expect do
|
2021-07-27 20:10:24 -04:00
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
end.not_to exceed_all_query_limit(control)
|
2020-08-11 11:10:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 22:09:43 -05:00
|
|
|
|
|
|
|
describe '.jobs.artifacts' do
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
query {
|
|
|
|
project(fullPath: "#{project.full_path}") {
|
|
|
|
pipeline(iid: "#{pipeline.iid}") {
|
2021-07-27 20:10:24 -04:00
|
|
|
stages {
|
2020-11-24 22:09:43 -05:00
|
|
|
nodes {
|
2021-07-27 20:10:24 -04:00
|
|
|
groups{
|
2020-11-24 22:09:43 -05:00
|
|
|
nodes {
|
2021-07-27 20:10:24 -04:00
|
|
|
jobs {
|
|
|
|
nodes {
|
|
|
|
artifacts {
|
|
|
|
nodes {
|
|
|
|
downloadPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-24 22:09:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the job is a build' do
|
|
|
|
it "returns the build's artifacts" do
|
|
|
|
create(:ci_build, :artifacts, pipeline: pipeline)
|
|
|
|
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
|
2021-07-27 20:10:24 -04:00
|
|
|
job_data = graphql_data_at(:project, :pipeline, :stages, :nodes, :groups, :nodes, :jobs, :nodes).first
|
2020-11-24 22:09:43 -05:00
|
|
|
expect(job_data.dig('artifacts', 'nodes').count).to be(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the job is not a build' do
|
|
|
|
it 'returns nil' do
|
|
|
|
create(:ci_bridge, pipeline: pipeline)
|
|
|
|
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
|
2021-07-27 20:10:24 -04:00
|
|
|
job_data = graphql_data_at(:project, :pipeline, :stages, :nodes, :groups, :nodes, :jobs, :nodes).first
|
2020-11-24 22:09:43 -05:00
|
|
|
expect(job_data['artifacts']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-11 11:10:08 -04:00
|
|
|
end
|