Commit 0ae3fc6b authored by Erick Bajao's avatar Erick Bajao

Include suite errors in test summary

Exposes suite_error in test suite summary.
parent eb17d3ce
......@@ -38,6 +38,10 @@ module Ci
tests.dig("skipped").to_i
end
def suite_error
tests.dig("suite_error")
end
def tests_total
[tests_success, tests_failed, tests_errored, tests_skipped].sum
end
......
......@@ -4,4 +4,6 @@ class TestSuiteSummaryEntity < TestSuiteEntity
expose :build_ids do |summary|
summary.build_ids
end
expose :suite_error
end
......@@ -33,7 +33,8 @@ module Ci
failed: test_suite.failed_count,
errored: test_suite.error_count,
skipped: test_suite.skipped_count,
success: test_suite.success_count
success: test_suite.success_count,
suite_error: test_suite.suite_error
}
}
end
......
---
title: Display suite errors on test summary page
merge_request: 55770
author:
type: changed
......@@ -4,6 +4,8 @@ module Gitlab
module Ci
module Reports
class TestSuiteSummary
include Gitlab::Utils::StrongMemoize
def initialize(build_report_results)
@build_report_results = build_report_results
end
......@@ -42,6 +44,12 @@ module Gitlab
end
# rubocop: disable CodeReuse/ActiveRecord
def suite_error
strong_memoize(:suite_error) do
@build_report_results.map(&:suite_error).compact.first
end
end
def to_h
{
time: total_time,
......@@ -49,7 +57,8 @@ module Gitlab
success: success_count,
failed: failed_count,
skipped: skipped_count,
error: error_count
error: error_count,
suite_error: suite_error
}
end
end
......
......@@ -4,10 +4,15 @@ FactoryBot.define do
factory :ci_build_report_result, class: 'Ci::BuildReportResult' do
build factory: :ci_build
project factory: :project
transient do
test_suite_name { "rspec" }
end
data do
{
tests: {
name: "rspec",
name: test_suite_name,
duration: 0.42,
failed: 0,
errored: 2,
......@@ -21,7 +26,7 @@ FactoryBot.define do
data do
{
tests: {
name: "rspec",
name: test_suite_name,
duration: 0.42,
failed: 0,
errored: 0,
......@@ -31,5 +36,25 @@ FactoryBot.define do
}
end
end
trait :with_junit_suite_error do
transient do
test_suite_error { "some error" }
end
data do
{
tests: {
name: test_suite_name,
duration: 0.42,
failed: 0,
errored: 0,
skipped: 0,
success: 2,
suite_error: test_suite_error
}
}
end
end
end
end
......@@ -87,12 +87,44 @@ RSpec.describe Gitlab::Ci::Reports::TestSuiteSummary do
end
end
describe '#suite_error' do
subject(:suite_error) { test_suite_summary.suite_error }
context 'when there are no build report results with suite errors' do
it { is_expected.to be_nil }
end
context 'when there are build report results with suite errors' do
let(:build_report_result_1) do
build(
:ci_build_report_result,
:with_junit_suite_error,
test_suite_name: 'karma',
test_suite_error: 'karma parsing error'
)
end
let(:build_report_result_2) do
build(
:ci_build_report_result,
:with_junit_suite_error,
test_suite_name: 'karma',
test_suite_error: 'another karma parsing error'
)
end
it 'includes the first suite error from the collection of build report results' do
expect(suite_error).to eq('karma parsing error')
end
end
end
describe '#to_h' do
subject { test_suite_summary.to_h }
context 'when test suite summary has several build report results' do
it 'returns the total as a hash' do
expect(subject).to include(:time, :count, :success, :failed, :skipped, :error)
expect(subject).to include(:time, :count, :success, :failed, :skipped, :error, :suite_error)
end
end
end
......
......@@ -20,5 +20,9 @@ RSpec.describe TestSuiteSummaryEntity do
it 'contains the build_ids' do
expect(as_json).to include(:build_ids)
end
it 'contains the suite_error' do
expect(as_json).to include(:suite_error)
end
end
end
......@@ -26,6 +26,28 @@ RSpec.describe Ci::BuildReportResultService do
expect(unique_test_cases_parsed).to eq(4)
end
context 'and build has test report parsing errors' do
let(:build) { create(:ci_build, :success, :broken_test_reports) }
it 'creates a build report result entry with suite error', :aggregate_failures do
expect(build_report_result.tests_name).to eq("test")
expect(build_report_result.tests_success).to eq(0)
expect(build_report_result.tests_failed).to eq(0)
expect(build_report_result.tests_errored).to eq(0)
expect(build_report_result.tests_skipped).to eq(0)
expect(build_report_result.tests_duration).to eq(0)
expect(build_report_result.suite_error).to be_present
expect(Ci::BuildReportResult.count).to eq(1)
unique_test_cases_parsed = Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(
event_names: described_class::EVENT_NAME,
start_date: 2.weeks.ago,
end_date: 2.weeks.from_now
)
expect(unique_test_cases_parsed).to eq(0)
end
end
context 'when data has already been persisted' do
it 'raises an error and do not persist the same data twice' do
expect { 2.times { described_class.new.execute(build) } }.to raise_error(ActiveRecord::RecordNotUnique)
......
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