Commit c9355dd0 authored by Alex Kalderimis's avatar Alex Kalderimis

Test the Job and Pipeline duration fields

parent dbae65fc
...@@ -9,7 +9,8 @@ RSpec.describe Types::Ci::PipelineType do ...@@ -9,7 +9,8 @@ RSpec.describe Types::Ci::PipelineType do
it 'contains attributes related to a pipeline' do it 'contains attributes related to a pipeline' do
expected_fields = %w[ expected_fields = %w[
id iid sha before_sha status detailed_status config_source duration id iid sha before_sha status detailed_status config_source
duration queued_duration
coverage created_at updated_at started_at finished_at committed_at coverage created_at updated_at started_at finished_at committed_at
stages user retryable cancelable jobs source_job job downstream stages user retryable cancelable jobs source_job job downstream
upstream path project active user_permissions warnings commit_path uses_needs upstream path project active user_permissions warnings commit_path uses_needs
......
...@@ -5,6 +5,10 @@ require 'spec_helper' ...@@ -5,6 +5,10 @@ require 'spec_helper'
RSpec.describe 'Query.project(fullPath).pipelines.job(id)' do RSpec.describe 'Query.project(fullPath).pipelines.job(id)' do
include GraphqlHelpers include GraphqlHelpers
around do |example|
travel_to(Time.current) { example.run }
end
let_it_be(:user) { create_default(:user) } let_it_be(:user) { create_default(:user) }
let_it_be(:project) { create(:project, :repository, :public) } let_it_be(:project) { create(:project, :repository, :public) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
...@@ -35,13 +39,20 @@ RSpec.describe 'Query.project(fullPath).pipelines.job(id)' do ...@@ -35,13 +39,20 @@ RSpec.describe 'Query.project(fullPath).pipelines.job(id)' do
let(:terminal_type) { 'CiJob' } let(:terminal_type) { 'CiJob' }
it 'retrieves scalar fields' do it 'retrieves scalar fields' do
job_2.update!(
created_at: 40.seconds.ago,
queued_at: 32.seconds.ago,
started_at: 30.seconds.ago,
finished_at: 5.seconds.ago
)
post_graphql(query, current_user: user) post_graphql(query, current_user: user)
expect(graphql_data_at(*path)).to match a_hash_including( expect(graphql_data_at(*path)).to match a_hash_including(
'id' => global_id_of(job_2), 'id' => global_id_of(job_2),
'name' => job_2.name, 'name' => job_2.name,
'allowFailure' => job_2.allow_failure, 'allowFailure' => job_2.allow_failure,
'duration' => job_2.duration, 'duration' => 25,
'queuedDuration' => 2.0,
'status' => job_2.status.upcase 'status' => job_2.status.upcase
) )
end end
......
...@@ -8,6 +8,49 @@ RSpec.describe 'Query.project(fullPath).pipelines' do ...@@ -8,6 +8,49 @@ RSpec.describe 'Query.project(fullPath).pipelines' do
let_it_be(:project) { create(:project, :repository, :public) } let_it_be(:project) { create(:project, :repository, :public) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
around do |example|
travel_to(Time.current) { example.run }
end
describe 'duration fields' do
let_it_be(:pipeline) do
create(:ci_pipeline, project: project)
end
let(:query_path) do
[
[:project, { full_path: project.full_path }],
[:pipelines],
[:nodes]
]
end
let(:query) do
wrap_fields(query_graphql_path(query_path, 'queuedDuration duration'))
end
before do
pipeline.update!(
created_at: 1.minute.ago,
started_at: 55.seconds.ago
)
create(:ci_build, :success,
pipeline: pipeline,
started_at: 55.seconds.ago,
finished_at: 10.seconds.ago)
pipeline.update_duration
pipeline.save!
post_graphql(query, current_user: user)
end
it 'includes the duration fields' do
path = query_path.map(&:first)
expect(graphql_data_at(*path, :queued_duration)).to eq [5.0]
expect(graphql_data_at(*path, :duration)).to eq [45]
end
end
describe '.jobs' do describe '.jobs' do
let(:first_n) { var('Int') } let(:first_n) { var('Int') }
let(:query_path) do let(:query_path) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment