Skip to content

Commit

Permalink
fix potential performance issue when storing all the failure counts p…
Browse files Browse the repository at this point in the history
…er test suite - for sequential execution one integer is enough
  • Loading branch information
anmarchenko committed Dec 15, 2023
1 parent c65de65 commit 0bdbaa1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions lib/datadog/ci/contrib/cucumber/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(config)
@failed_tests_count = 0

@current_test_suite = nil
@failed_tests_per_test_suite = Hash.new(0)
@failed_tests_in_current_test_suite = 0

bind_events(config)
end
Expand Down Expand Up @@ -76,11 +76,10 @@ def on_test_case_finished(event)
# TestRunFinished event does not have a success attribute before 8.0.
#
# To track whether test suite failed or passed we need to
# track the number of failed tests per test suite.
# track the number of failed tests in the current test suite.
if event.result.failed?
@failed_tests_count += 1
test_suite = @current_test_suite
@failed_tests_per_test_suite[test_suite.name] += 1 if test_suite
@failed_tests_in_current_test_suite += 1
end

finish_test(test_span, event.result)
Expand Down Expand Up @@ -140,11 +139,12 @@ def finish_current_test_suite
test_suite = @current_test_suite
return unless test_suite

if @failed_tests_per_test_suite[test_suite.name].zero?
if @failed_tests_in_current_test_suite.zero?
test_suite.passed!
else
test_suite.failed!
end
@failed_tests_in_current_test_suite = 0
test_suite.finish
end

Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/contrib/cucumber/formatter.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Datadog
private
@failed_tests_count: Integer
@current_test_suite: Datadog::CI::Span?
@failed_tests_per_test_suite: Hash[String, Integer]
@failed_tests_in_current_test_suite: Integer

attr_reader config: untyped

Expand Down

0 comments on commit 0bdbaa1

Please sign in to comment.