gitlab-org--gitlab-foss/app/serializers/test_suite_comparer_entity.rb
Kamil Trzciński a08209ffa3 Limit amount of JUnit tests returned
Currently, we do not cap amount of tests returned to frontend,
thus in some extreme cases we can see a MBs of data stored in Redis.

This adds an upper limit of 100 tests per-suite.

We will continue showing the total counters correctly,
but we will limit amount of tests that will be presented.
2019-07-03 22:27:14 +02:00

39 lines
1 KiB
Ruby

# frozen_string_literal: true
class TestSuiteComparerEntity < Grape::Entity
DEFAULT_MAX_TESTS = 100
DEFAULT_MIN_TESTS = 10
expose :name
expose :total_status, as: :status
expose :summary do
expose :total_count, as: :total
expose :resolved_count, as: :resolved
expose :failed_count, as: :failed
end
# rubocop: disable CodeReuse/ActiveRecord
expose :new_failures, using: TestCaseEntity do |suite|
suite.new_failures.take(max_tests)
end
expose :existing_failures, using: TestCaseEntity do |suite|
suite.existing_failures.take(
max_tests(suite.new_failures))
end
expose :resolved_failures, using: TestCaseEntity do |suite|
suite.resolved_failures.take(
max_tests(suite.new_failures, suite.existing_failures))
end
private
def max_tests(*used)
return Integer::MAX unless Feature.enabled?(:ci_limit_test_reports_size, default_enabled: true)
[DEFAULT_MAX_TESTS - used.map(&:count).sum, DEFAULT_MIN_TESTS].max
end
# rubocop: enable CodeReuse/ActiveRecord
end