From 5209ead631ce9afeb8fc5296aa120de546388361 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Mon, 12 Nov 2018 17:53:29 -0500 Subject: [PATCH] Start implementing mergeTestTimes --- .../src/main/kotlin/ftl/gc/GcStorage.kt | 7 ++++- .../kotlin/ftl/reports/util/ReportManager.kt | 30 ++++++++++++++----- .../ftl/reports/xml/model/JUnitTestResult.kt | 5 ++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt b/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt index 96d9619cdb..cbbc99f552 100644 --- a/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt +++ b/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt @@ -79,6 +79,10 @@ object GcStorage { fun downloadTestApk(args: AndroidArgs): String = download(args.testApk) + // junit xml may not exist. ignore error if it doesn't exist + fun downloadJunitXml(args: IArgs): String = + download(args.junitGcsPath, ignoreError = true) + private fun upload(file: String, fileBytes: ByteArray, rootGcsBucket: String, runGcsPath: String): String { val fileName = Paths.get(file).fileName.toString() val gcsFilePath = GCS_PREFIX + join(rootGcsBucket, runGcsPath, fileName) @@ -95,7 +99,7 @@ object GcStorage { return gcsFilePath } - private fun download(gcsUriString: String): String { + private fun download(gcsUriString: String, ignoreError: Boolean = false): String { val gcsURI = URI.create(gcsUriString) val bucket = gcsURI.authority val path = gcsURI.path.drop(1) // Drop leading slash @@ -110,6 +114,7 @@ object GcStorage { output.channel.transferFrom(readChannel, 0, Long.MAX_VALUE) output.close() } catch (e: Exception) { + if (ignoreError) return "" fatalError(e) } diff --git a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt index 3104c72cc2..faa651787b 100644 --- a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt +++ b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt @@ -11,6 +11,7 @@ import ftl.reports.MatrixResultsReport import ftl.reports.xml.model.JUnitTestResult import ftl.reports.xml.parseAndroidXml import ftl.reports.xml.parseIosXml +import ftl.reports.xml.xmlToString import ftl.util.ArtifactRegex import ftl.util.resolveLocalRunPath import java.io.File @@ -63,14 +64,18 @@ object ReportManager { return mergedXml } - /** Returns true if there were no test failures */ - fun generate(matrices: MatrixMap, args: IArgs): Int { + private fun parseTestSuite(matrices: MatrixMap, args: IArgs): JUnitTestResult? { val iosXml = args is IosArgs - val testSuite = if (iosXml) { + return if (iosXml) { processXml(matrices, ::parseIosXml) } else { processXml(matrices, ::parseAndroidXml) } + } + + /** Returns true if there were no test failures */ + fun generate(matrices: MatrixMap, args: IArgs): Int { + val testSuite = parseTestSuite(matrices, args) val testSuccessful = matrices.allSuccessful() listOf( @@ -80,17 +85,26 @@ object ReportManager { it.run(matrices, testSuite, printToStdout = true) } - JUnitReport.run(matrices, testSuite) - - val localJunitXmlPath = JUnitReport.reportPath(matrices) - GcStorage.uploadJunitXml(localJunitXmlPath, args) - if (!testSuccessful) { listOf( HtmlErrorReport ).map { it.run(matrices, testSuite) } } + JUnitReport.run(matrices, testSuite) + processJunitXml(testSuite, args) + return matrices.exitCode() } + + private fun processJunitXml(newTestResult: JUnitTestResult?, args: IArgs) { + if (newTestResult == null) return + + val oldXmlPath = GcStorage.downloadJunitXml(args) + val oldTestResult = if (oldXmlPath.isNotEmpty()) parseIosXml(oldXmlPath) else null + + newTestResult.mergeTestTimes(oldTestResult) + + GcStorage.uploadJunitXml(newTestResult.xmlToString(), args) + } } diff --git a/test_runner/src/main/kotlin/ftl/reports/xml/model/JUnitTestResult.kt b/test_runner/src/main/kotlin/ftl/reports/xml/model/JUnitTestResult.kt index 66fbd88ae3..2e81be4c2e 100644 --- a/test_runner/src/main/kotlin/ftl/reports/xml/model/JUnitTestResult.kt +++ b/test_runner/src/main/kotlin/ftl/reports/xml/model/JUnitTestResult.kt @@ -11,6 +11,11 @@ data class JUnitTestResult( @JacksonXmlProperty(localName = "testsuite") var testsuites: MutableList? ) { + fun mergeTestTimes(other: JUnitTestResult?): JUnitTestResult { + // TODO: ... + return this + } + fun merge(other: JUnitTestResult?): JUnitTestResult { if (other == null) return this if (this.testsuites == null) this.testsuites = mutableListOf()