Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve flaky tests counts discrepancy #2536

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ fun JUnitTest.Suite.merge(other: JUnitTest.Suite): JUnitTest.Suite {
this.errors = mergeInt(this.errors, other.errors)
this.skipped = mergeInt(this.skipped, other.skipped)
this.time = mergeDouble(this.time, other.time)
if (other.flakes != null) {
this.flakes = mergeInt(
this.flakes?.toString(),
other.flakes?.toString()
).toInt()
}


if (this.testcases == null) this.testcases = mutableListOf()
if (other.testcases?.isNotEmpty() == true) {
Expand Down
35 changes: 35 additions & 0 deletions test_runner/src/test/kotlin/ftl/client/xml/JUnitXmlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class JUnitXmlTest {
<skipped/>
</testcase>
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
</testsuite>
""".trimIndent()
val flakyTestSuiteXml = """
<testsuite name="" tests="2" failures="0" flakes="1" errors="0" skipped="0" time="0.026" timestamp="2018-10-26T19:57:28" hostname="localhost">
<properties/>
<testcase name="testFails" classname="com.example.app.ExampleUiTest" time="0.0">
<skipped/>
</testcase>
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
</testsuite>
""".trimIndent()
}
Expand Down Expand Up @@ -525,6 +534,32 @@ junit.framework.Assert.fail(Assert.java:50)</failure>
val oneSuiteXml = parseOneSuiteXml(crashingOneSuiteMessage.writeToTempFile()).toXmlString().trimIndent()
Assert.assertEquals("One Suite Messages should be the same!", expectedOneSuiteMessage, oneSuiteXml)
}

@Test
fun `merge flakes`() {
val merged = parseOneSuiteXml(flakyTestSuiteXml.writeToTempFile())
merged.merge(merged)
val actual = merged.toXmlString().normalizeLineEnding()

assertThat(actual).isEqualTo(
"""
<?xml version='1.0' encoding='UTF-8' ?>
<testsuites>
<testsuite name="" tests="4" failures="0" flakes="2" errors="0" skipped="0" time="0.052" timestamp="2018-10-26T19:57:28" hostname="localhost">
<testcase name="testFails" classname="com.example.app.ExampleUiTest" time="0.0">
<skipped/>
</testcase>
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
<testcase name="testFails" classname="com.example.app.ExampleUiTest" time="0.0">
<skipped/>
</testcase>
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
</testsuite>
</testsuites>

""".trimIndent()
)
}
}

private fun String.writeToTempFile(): File = File.createTempFile("temp", "test")
Expand Down
Loading