-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor
-
Component/s: flaky-test-handler-plugin
When the junit step runs with testDataPublishers: [[$class: 'JUnitFlakyTestDataPublisher']], the build's build.xml gets a full copy of the test results. JUnitFlakyTestData.testCaseFlakyInfoMap is saved with the TestResultAction. Each FlakyCaseResult in it has a parent chain to FlakySuiteResult and FlakyTestResult, and FlakyTestResult.testResultInstance (a hudson.tasks.junit.TestResult) is not transient. So XStream writes:
- the plugin's own tree of every suite, class and case, including each case's stdout, and
- the complete junit TestResult (all suites and cases, with stdout), which junit already stores in junitResult.xml.
Why it matters
- It exposes junit's internal types to build.xml. With junit 1463.v7508416a_349c, the flakyFailures/rerunFailures in that copy were hudson.tasks.junit.Failure, which was a Java record. XStream can't read records, so every build that had a rerun or flaky test failed to load after a Jenkins restart ("Possibly corrupt build.xml"). junit fixed its part in 1464.vece7e78fce08 (https://github.com/jenkinsci/junit-plugin/issues/1298). The same thing can happen again whenever junit changes a class that it only ever reads with its own StAX parser, because this plugin makes XStream read it too.
- Size and load time. Example build with 282 tests over 7 suites and no reruns:
- build.xml: 2.1 MB, of which the TestResultAction is 743 KB, almost all of it JUnitFlakyTestData.
- Inside that, the testResultInstance copy is 313 KB.
- junit's own junitResult.xml for the same build: 217 KB.
- Jenkins reads all of this again for every build when it loads the job.
To reproduce
- Pipeline job with junit testResults: '*.xml', testDataPublishers: [[$class: 'JUnitFlakyTestDataPublisher']].
- Run a build.
- Look for <testResultInstance plugin="junit@..."> under <com.google.jenkins.flakyTestHandler.plugin.JUnitFlakyTestData> in jobs/<job>/builds/<n>/build.xml.
Expected
build.xml holds only the flaky data the plugin needs (for example test ids and flaky-run information). The junit TestResult is not copied: it is already saved by junit, and can be fetched through the owning TestResultAction when it is needed.
Possible fix
Make FlakyTestResult.testResultInstance transient and resolve it from the owning action when needed. Consider also not persisting the duplicated per-case stdout.