Skip to content

Commit

Permalink
Start implementing mergeTestTimes
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Nov 12, 2018
1 parent 3fbe2e2 commit 5209ead
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
7 changes: 6 additions & 1 deletion test_runner/src/main/kotlin/ftl/gc/GcStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -110,6 +114,7 @@ object GcStorage {
output.channel.transferFrom(readChannel, 0, Long.MAX_VALUE)
output.close()
} catch (e: Exception) {
if (ignoreError) return ""
fatalError(e)
}

Expand Down
30 changes: 22 additions & 8 deletions test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ data class JUnitTestResult(
@JacksonXmlProperty(localName = "testsuite")
var testsuites: MutableList<JUnitTestSuite>?
) {
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()
Expand Down

0 comments on commit 5209ead

Please sign in to comment.