Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/reports')
-rw-r--r--lib/gitlab/ci/reports/test_case.rb32
-rw-r--r--lib/gitlab/ci/reports/test_reports.rb39
-rw-r--r--lib/gitlab/ci/reports/test_reports_comparer.rb38
-rw-r--r--lib/gitlab/ci/reports/test_suite.rb54
-rw-r--r--lib/gitlab/ci/reports/test_suite_comparer.rb57
5 files changed, 220 insertions, 0 deletions
diff --git a/lib/gitlab/ci/reports/test_case.rb b/lib/gitlab/ci/reports/test_case.rb
new file mode 100644
index 00000000000..b4d08ed257f
--- /dev/null
+++ b/lib/gitlab/ci/reports/test_case.rb
@@ -0,0 +1,32 @@
+module Gitlab
+ module Ci
+ module Reports
+ class TestCase
+ STATUS_SUCCESS = 'success'.freeze
+ STATUS_FAILED = 'failed'.freeze
+ STATUS_SKIPPED = 'skipped'.freeze
+ STATUS_ERROR = 'error'.freeze
+ STATUS_TYPES = [STATUS_SUCCESS, STATUS_FAILED, STATUS_SKIPPED, STATUS_ERROR].freeze
+
+ attr_reader :name, :classname, :execution_time, :status, :file, :system_output, :stack_trace, :key
+
+ def initialize(name:, classname:, execution_time:, status:, file: nil, system_output: nil, stack_trace: nil)
+ @name = name
+ @classname = classname
+ @file = file
+ @execution_time = execution_time.to_f
+ @status = status
+ @system_output = system_output
+ @stack_trace = stack_trace
+ @key = sanitize_key_name("#{classname}_#{name}")
+ end
+
+ private
+
+ def sanitize_key_name(key)
+ key.gsub(/[^0-9A-Za-z]/, '-')
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/reports/test_reports.rb b/lib/gitlab/ci/reports/test_reports.rb
new file mode 100644
index 00000000000..c6e732e68eb
--- /dev/null
+++ b/lib/gitlab/ci/reports/test_reports.rb
@@ -0,0 +1,39 @@
+module Gitlab
+ module Ci
+ module Reports
+ class TestReports
+ attr_reader :test_suites
+
+ def initialize
+ @test_suites = {}
+ end
+
+ def get_suite(suite_name)
+ test_suites[suite_name] ||= TestSuite.new(suite_name)
+ end
+
+ def total_time
+ test_suites.values.sum(&:total_time)
+ end
+
+ def total_count
+ test_suites.values.sum(&:total_count)
+ end
+
+ def total_status
+ if failed_count > 0 || error_count > 0
+ TestCase::STATUS_FAILED
+ else
+ TestCase::STATUS_SUCCESS
+ end
+ end
+
+ TestCase::STATUS_TYPES.each do |status_type|
+ define_method("#{status_type}_count") do
+ test_suites.values.sum { |suite| suite.public_send("#{status_type}_count") } # rubocop:disable GitlabSecurity/PublicSend
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/reports/test_reports_comparer.rb b/lib/gitlab/ci/reports/test_reports_comparer.rb
new file mode 100644
index 00000000000..c0943f5a51a
--- /dev/null
+++ b/lib/gitlab/ci/reports/test_reports_comparer.rb
@@ -0,0 +1,38 @@
+module Gitlab
+ module Ci
+ module Reports
+ class TestReportsComparer
+ include Gitlab::Utils::StrongMemoize
+
+ attr_reader :base_reports, :head_reports
+
+ def initialize(base_reports, head_reports)
+ @base_reports = base_reports || TestReports.new
+ @head_reports = head_reports
+ end
+
+ def suite_comparers
+ strong_memoize(:suite_comparers) do
+ head_reports.test_suites.map do |name, test_suite|
+ TestSuiteComparer.new(name, base_reports.get_suite(name), test_suite)
+ end
+ end
+ end
+
+ def total_status
+ if suite_comparers.any? { |suite| suite.total_status == TestCase::STATUS_FAILED }
+ TestCase::STATUS_FAILED
+ else
+ TestCase::STATUS_SUCCESS
+ end
+ end
+
+ %w(total_count resolved_count failed_count).each do |method|
+ define_method(method) do
+ suite_comparers.sum { |suite| suite.public_send(method) } # rubocop:disable GitlabSecurity/PublicSend
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/reports/test_suite.rb b/lib/gitlab/ci/reports/test_suite.rb
new file mode 100644
index 00000000000..b722d0ba735
--- /dev/null
+++ b/lib/gitlab/ci/reports/test_suite.rb
@@ -0,0 +1,54 @@
+module Gitlab
+ module Ci
+ module Reports
+ class TestSuite
+ attr_reader :name
+ attr_reader :test_cases
+ attr_reader :total_time
+
+ def initialize(name = nil)
+ @name = name
+ @test_cases = {}
+ @total_time = 0.0
+ @duplicate_cases = []
+ end
+
+ def add_test_case(test_case)
+ @duplicate_cases << test_case if existing_key?(test_case)
+
+ @test_cases[test_case.status] ||= {}
+ @test_cases[test_case.status][test_case.key] = test_case
+ @total_time += test_case.execution_time
+ end
+
+ def total_count
+ test_cases.values.sum(&:count)
+ end
+
+ def total_status
+ if failed_count > 0 || error_count > 0
+ TestCase::STATUS_FAILED
+ else
+ TestCase::STATUS_SUCCESS
+ end
+ end
+
+ TestCase::STATUS_TYPES.each do |status_type|
+ define_method("#{status_type}") do
+ test_cases[status_type] || {}
+ end
+
+ define_method("#{status_type}_count") do
+ test_cases[status_type]&.length.to_i
+ end
+ end
+
+ private
+
+ def existing_key?(test_case)
+ @test_cases[test_case.status]&.key?(test_case.key)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/reports/test_suite_comparer.rb b/lib/gitlab/ci/reports/test_suite_comparer.rb
new file mode 100644
index 00000000000..642aa593092
--- /dev/null
+++ b/lib/gitlab/ci/reports/test_suite_comparer.rb
@@ -0,0 +1,57 @@
+module Gitlab
+ module Ci
+ module Reports
+ class TestSuiteComparer
+ include Gitlab::Utils::StrongMemoize
+
+ attr_reader :name, :base_suite, :head_suite
+
+ def initialize(name, base_suite, head_suite)
+ @name = name
+ @base_suite = base_suite || TestSuite.new
+ @head_suite = head_suite
+ end
+
+ def new_failures
+ strong_memoize(:new_failures) do
+ head_suite.failed.reject do |key, _|
+ base_suite.failed.include?(key)
+ end.values
+ end
+ end
+
+ def existing_failures
+ strong_memoize(:existing_failures) do
+ head_suite.failed.select do |key, _|
+ base_suite.failed.include?(key)
+ end.values
+ end
+ end
+
+ def resolved_failures
+ strong_memoize(:resolved_failures) do
+ head_suite.success.select do |key, _|
+ base_suite.failed.include?(key)
+ end.values
+ end
+ end
+
+ def total_count
+ head_suite.total_count
+ end
+
+ def total_status
+ head_suite.total_status
+ end
+
+ def resolved_count
+ resolved_failures.count
+ end
+
+ def failed_count
+ new_failures.count + existing_failures.count
+ end
+ end
+ end
+ end
+end