diff options
author | Stan Hu <stanhu@gmail.com> | 2019-07-03 21:47:32 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-07-03 21:47:32 +0000 |
commit | a1d113c9ff74d973575db3ff9738939aaf1c59c1 (patch) | |
tree | 89ab904125cff434ca3e4bfca53593dc7072ed60 /app/serializers/test_suite_comparer_entity.rb | |
parent | 2ad75a4f96c4d377e18788966e7eefee4d78b6d2 (diff) | |
parent | a08209ffa35a29cd84271895389b4537dee92e86 (diff) | |
download | gitlab-ce-a1d113c9ff74d973575db3ff9738939aaf1c59c1.tar.gz |
Merge branch 'limit-amount-of-tests-returned' into 'master'
Limit amount of JUnit tests returned
Closes #64035
See merge request gitlab-org/gitlab-ce!30274
Diffstat (limited to 'app/serializers/test_suite_comparer_entity.rb')
-rw-r--r-- | app/serializers/test_suite_comparer_entity.rb | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/app/serializers/test_suite_comparer_entity.rb b/app/serializers/test_suite_comparer_entity.rb index 9fa3a897ebe..d402a4d5718 100644 --- a/app/serializers/test_suite_comparer_entity.rb +++ b/app/serializers/test_suite_comparer_entity.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class TestSuiteComparerEntity < Grape::Entity + DEFAULT_MAX_TESTS = 100 + DEFAULT_MIN_TESTS = 10 + expose :name expose :total_status, as: :status @@ -10,7 +13,27 @@ class TestSuiteComparerEntity < Grape::Entity expose :failed_count, as: :failed end - expose :new_failures, using: TestCaseEntity - expose :resolved_failures, using: TestCaseEntity - expose :existing_failures, using: TestCaseEntity + # 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 |