2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-03 06:13:39 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe Ci::CompareTestReportsService do
|
2018-08-03 06:13:39 +00:00
|
|
|
let(:service) { described_class.new(project) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
2020-11-02 09:08:35 +00:00
|
|
|
subject(:comparison) { service.execute(base_pipeline, head_pipeline) }
|
2018-08-03 11:08:13 +00:00
|
|
|
|
|
|
|
context 'when head pipeline has test reports' do
|
|
|
|
let!(:base_pipeline) { nil }
|
|
|
|
let!(:head_pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
|
2018-08-03 06:13:39 +00:00
|
|
|
|
2018-08-03 11:08:13 +00:00
|
|
|
it 'returns status and data' do
|
2020-11-02 09:08:35 +00:00
|
|
|
expect(comparison[:status]).to eq(:parsed)
|
|
|
|
expect(comparison[:data]).to match_schema('entities/test_reports_comparer')
|
2018-08-03 06:13:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-03 11:08:13 +00:00
|
|
|
context 'when base and head pipelines have test reports' do
|
|
|
|
let!(:base_pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
|
|
|
|
let!(:head_pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
|
2018-08-03 06:13:39 +00:00
|
|
|
|
|
|
|
it 'returns status and data' do
|
2020-11-02 09:08:35 +00:00
|
|
|
expect(comparison[:status]).to eq(:parsed)
|
|
|
|
expect(comparison[:data]).to match_schema('entities/test_reports_comparer')
|
2018-08-03 06:13:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when head pipeline has corrupted test reports' do
|
2018-08-03 11:08:13 +00:00
|
|
|
let!(:base_pipeline) { nil }
|
|
|
|
let!(:head_pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
|
2018-08-03 06:13:39 +00:00
|
|
|
before do
|
2018-08-03 11:08:13 +00:00
|
|
|
build = create(:ci_build, pipeline: head_pipeline, project: head_pipeline.project)
|
|
|
|
create(:ci_job_artifact, :junit_with_corrupted_data, job: build, project: project)
|
2018-08-03 06:13:39 +00:00
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
it 'returns a parsed TestReports success status and failure on the individual suite' do
|
2020-11-02 09:08:35 +00:00
|
|
|
expect(comparison[:status]).to eq(:parsed)
|
|
|
|
expect(comparison.dig(:data, 'status')).to eq('success')
|
|
|
|
expect(comparison.dig(:data, 'suites', 0, 'status') ).to eq('error')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'test failure history' do
|
|
|
|
let!(:base_pipeline) { nil }
|
|
|
|
let!(:head_pipeline) { create(:ci_pipeline, :with_test_reports_with_three_failures, project: project) }
|
|
|
|
|
|
|
|
let(:new_failures) do
|
|
|
|
comparison.dig(:data, 'suites', 0, 'new_failures')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:recent_failures_per_test_case) do
|
|
|
|
new_failures.map { |f| f['recent_failures'] }
|
|
|
|
end
|
|
|
|
|
|
|
|
# Create test case failure records based on the head pipeline build
|
|
|
|
before do
|
|
|
|
stub_const("Gitlab::Ci::Reports::TestSuiteComparer::DEFAULT_MAX_TESTS", 2)
|
|
|
|
stub_const("Gitlab::Ci::Reports::TestSuiteComparer::DEFAULT_MIN_TESTS", 1)
|
|
|
|
|
|
|
|
build = head_pipeline.builds.last
|
|
|
|
build.update_column(:finished_at, 1.day.ago) # Just to be sure we are included in the report window
|
|
|
|
|
|
|
|
# The JUnit fixture for the given build has 3 failures.
|
|
|
|
# This service will create 1 test case failure record for each.
|
2020-12-10 15:10:12 +00:00
|
|
|
Ci::TestFailureHistoryService.new(head_pipeline).execute
|
2020-11-02 09:08:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'loads recent failures on limited test cases to avoid building up a huge DB query', :aggregate_failures do
|
|
|
|
expect(comparison[:data]).to match_schema('entities/test_reports_comparer')
|
|
|
|
expect(recent_failures_per_test_case).to eq([
|
|
|
|
{ 'count' => 1, 'base_branch' => 'master' },
|
|
|
|
{ 'count' => 1, 'base_branch' => 'master' }
|
|
|
|
])
|
|
|
|
expect(new_failures.count).to eq(2)
|
2018-08-03 06:13:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|