@@ -9,12 +9,6 @@ import org.gradle.kotlin.dsl.withType
99import org.gradle.testing.base.TestingExtension
1010import java.time.Duration
1111import java.time.temporal.ChronoUnit
12- import javax.xml.parsers.DocumentBuilderFactory
13- import javax.xml.transform.OutputKeys
14- import javax.xml.transform.TransformerFactory
15- import javax.xml.transform.dom.DOMSource
16- import javax.xml.transform.stream.StreamResult
17- import org.w3c.dom.Element
1812
1913// Need concrete implementation of BuildService in Kotlin
2014abstract class ForkedTestLimit : BuildService <BuildServiceParameters .None >
@@ -120,52 +114,3 @@ tasks.withType<Test>().configureEach {
120114 }
121115 }
122116}
123-
124- tasks.withType<Test >().configureEach {
125-
126- // Gradle generates synthetic test cases in JUnit reports for setup methods. When a setup is retried
127- // and eventually succeeds, multiple test cases are created, with only the last one passing. Since the
128- // retry succeeds, this does not fail the CI.
129- //
130- // However, all intermediate attempts are reported as failures in TestOptimization, which is misleading.
131- //
132- // To tackle this, we'll expose a final_status field:
133- // - "skip" for intermediate retries
134- // - nothing on last attempt, using the defaulting made by Test Optimization
135- //
136- // Charles de Beauchesne, March 2025
137-
138- doLast(" post-process-junit-xml-report" ) {
139- val dir = reports.junitXml.outputLocation.get().asFile
140- if (! dir.exists()) return @doLast
141- dir.walkTopDown()
142- .filter { it.isFile && it.extension == " xml" }
143- .forEach { xmlFile ->
144- try {
145- tagInitializationErrors(xmlFile)
146- } catch (e: Exception ) {
147- logger.warn(" Failed to remove initializationError testcases from {}: {}" , xmlFile.name, e.message)
148- }
149- }
150- }
151- }
152-
153- fun tagInitializationErrors (xmlFile : File ) {
154- val doc = DocumentBuilderFactory .newInstance().newDocumentBuilder().parse(xmlFile)
155- val testcases = doc.getElementsByTagName(" testcase" )
156- val initErrorCases = (0 until testcases.length)
157- .map { testcases.item(it) as Element }
158- .filter { it.getAttribute(" name" ) == " initializationError" }
159- if (initErrorCases.size <= 1 ) return
160- initErrorCases.dropLast(1 ).forEach { testcase ->
161- val properties = doc.createElement(" properties" )
162- val property = doc.createElement(" property" )
163- property.setAttribute(" name" , " dd_tags[test.final_status]" )
164- property.setAttribute(" value" , " skip" )
165- properties.appendChild(property)
166- testcase.appendChild(properties)
167- }
168- val transformer = TransformerFactory .newInstance().newTransformer()
169- transformer.setOutputProperty(OutputKeys .ENCODING , " UTF-8" )
170- transformer.transform(DOMSource (doc), StreamResult (xmlFile))
171- }
0 commit comments