Skip to content

Commit b0356b3

Browse files
committed
Specify flaky tests in junit.xml format
1 parent 479d530 commit b0356b3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

ruby/lib/ci/queue/configuration.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ def from_env(env)
2525

2626
def load_flaky_tests(path)
2727
return [] unless path
28-
::File.readlines(path).map(&:chomp).to_set
28+
if ::File.extname(path) == ".xml"
29+
require 'rexml/document'
30+
REXML::Document.new(::File.read(path)).elements.to_a("//testcase").map do |element|
31+
"#{element.attributes['classname']}##{element.attributes['name']}"
32+
end.to_set
33+
else
34+
::File.readlines(path).map(&:chomp).to_set
35+
end
2936
rescue SystemCallError
3037
[]
3138
end

ruby/test/ci/queue/configuration_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ def test_parses_file_correctly
9090

9191
flaky_tests = Configuration.load_flaky_tests('/tmp/does-not-exist')
9292
assert_empty flaky_tests
93+
94+
Tempfile.open(['flaky_test_file', '.junit.xml']) do |file|
95+
file.write(<<~XML)
96+
<testsuite name="ATest">
97+
<testcase name="test_foo" classname="ATest" />
98+
<testcase name="test_bar" classname="ATest" />
99+
</testsuite>
100+
XML
101+
file.close
102+
103+
flaky_tests = Configuration.load_flaky_tests(file.path)
104+
assert_equal 2, flaky_tests.size
105+
assert_includes flaky_tests, "ATest#test_foo"
106+
assert_includes flaky_tests, "ATest#test_bar"
107+
end
93108
end
94109

95110
def test_queue_init_timeout_unset

0 commit comments

Comments
 (0)