From f3816529747f31b69cda09663ea3f465ee15e962 Mon Sep 17 00:00:00 2001 From: Jude Kwashie Date: Thu, 31 Oct 2024 13:47:47 +0000 Subject: [PATCH] fix: resolve flaky tests counts discrepancy --- .../kotlin/ftl/domain/junit/JUnitTestMerge.kt | 7 ++++ .../kotlin/ftl/client/xml/JUnitXmlTest.kt | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/test_runner/src/main/kotlin/ftl/domain/junit/JUnitTestMerge.kt b/test_runner/src/main/kotlin/ftl/domain/junit/JUnitTestMerge.kt index 40bd98f321..c2470d5ae1 100644 --- a/test_runner/src/main/kotlin/ftl/domain/junit/JUnitTestMerge.kt +++ b/test_runner/src/main/kotlin/ftl/domain/junit/JUnitTestMerge.kt @@ -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) { diff --git a/test_runner/src/test/kotlin/ftl/client/xml/JUnitXmlTest.kt b/test_runner/src/test/kotlin/ftl/client/xml/JUnitXmlTest.kt index c7ff9495af..1cf2d9a5d9 100644 --- a/test_runner/src/test/kotlin/ftl/client/xml/JUnitXmlTest.kt +++ b/test_runner/src/test/kotlin/ftl/client/xml/JUnitXmlTest.kt @@ -30,6 +30,15 @@ class JUnitXmlTest { + + """.trimIndent() + val flakyTestSuiteXml = """ + + + + + + """.trimIndent() } @@ -525,6 +534,32 @@ junit.framework.Assert.fail(Assert.java:50) 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( + """ + + + + + + + + + + + + + + + """.trimIndent() + ) + } } private fun String.writeToTempFile(): File = File.createTempFile("temp", "test")