Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- JUnit: Optimize processing time for large test results with many passing testcases

## [v1.11.0](https://github.com/bugcrowd/test-summary-buildkite-plugin/compare/v1.10.0...v1.11.0) - 2020-01-28
- Forward `HTTP_PROXY` ENV var to respect proxies [#58](https://github.com/bugcrowd/test-summary-buildkite-plugin/pull/58)

Expand Down
3 changes: 2 additions & 1 deletion lib/test_summary_buildkite_plugin/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def crop
class JUnit < Base
def file_contents_to_failures(str)
xml = REXML::Document.new(str)
xml.elements.enum_for(:each, '//testcase').each_with_object([]) do |testcase, failures|
failed_testcases = xml.elements.enum_for(:each, '//*[self::testcase][failure or error]')
failed_testcases.each_with_object([]) do |testcase, failures|
testcase.elements.each('failure | error') do |failure|
failures << Failure::Structured.new(
summary: summary(failure),
Expand Down
74 changes: 74 additions & 0 deletions spec/test_summary_buildkite_plugin/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,80 @@
expect(input.failures.first.details).to be_nil
end
end

context 'with failure and error elements in one testcase' do
let(:mixed_failure_junit) do
<<~XML
<testsuite>
<testcase name="mixed">
<error message="error first in XML"/>
<failure message="failure second in XML"/>
</testcase>
</testsuite>
XML
end

it 'preserves failure-before-error ordering' do
failures = input.file_contents_to_failures(mixed_failure_junit)

expect(failures.map(&:message)).to eq(['failure second in XML', 'error first in XML'])
end
end

context 'with many passing sibling testcases' do
let(:additional_options) do
{
summary: {
format: '%{testsuites.name}: %{testsuite.name}: %{testcase.name} '\
'(%{failure.message}%{error.message})'
}
}
end
let(:wide_junit) do
testcases = Array.new(2_000) do |index|
case index
when 500
'<testcase name="early error"><error message="boom">error details</error></testcase>'
when 1_500
'<testcase name="late failure"><failure message="bang">failure details'\
'<error message="nested error"/></failure></testcase>'
else
%(<testcase name="passing #{index}"/>)
end
end.join

<<~XML
<testsuites name="root">
<testsuite name="wide">
<error message="suite-level error"/>
#{testcases}
</testsuite>
</testsuites>
XML
end

it 'preserves testcase failure and error output in document order' do
failures = input.file_contents_to_failures(wide_junit)

expect(failures.map { |failure| [failure.summary, failure.message, failure.details] }).to eq(
[
['root: wide: early error (boom)', 'boom', 'error details'],
['root: wide: late failure (bang)', 'bang', 'failure details']
]
)
end

it 'does not build sibling indexes for every passing testcase' do
parent_index_calls = 0
trace = TracePoint.new(:call) do |event|
parent_index_calls += 1 if event.defined_class == REXML::Parent && event.method_id == :index
end

trace.enable { input.file_contents_to_failures(wide_junit) }

expect(parent_index_calls).to be < 100
end
end
end

describe 'with glob path' do
Expand Down