Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when --legacy-junit-result set #950

Merged
merged 5 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## next (unreleased)
- [#952](https://github.com/Flank/flank/pull/952) Fix version printing on Flank release
- [#950](https://github.com/Flank/flank/pull/950) Fix crash when --legacy-junit-result set. ([adamfilipow92](https://github.com/adamfilipow92))
-
-

Expand Down
11 changes: 11 additions & 0 deletions test_runner/src/main/kotlin/ftl/reports/util/MatrixPath.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ftl.reports.util

import java.io.File
import java.nio.file.Paths

fun File.getMatrixPath(objectName: String) = getShardName()?.asObjectPath(objectName)

private fun File.getShardName() = shardNameRegex.find(toString())?.value?.removePrefix("/")?.removeSuffix("/")
private val shardNameRegex = "/.*(shard_|matrix_)\\d+(-rerun_\\d+)?/".toRegex()

private fun String.asObjectPath(objectName: String) = Paths.get(objectName, this).toString()
26 changes: 6 additions & 20 deletions test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import ftl.shard.createTestMethodDurationMap
import ftl.util.Artifacts
import ftl.util.resolveLocalRunPath
import java.io.File
import java.nio.file.Paths
import kotlin.math.roundToInt

object ReportManager {
Expand All @@ -40,25 +39,8 @@ object ReportManager {
return xmlFiles
}

private fun getWebLink(matrices: MatrixMap, xmlFile: File): String {
// xmlFile path changes based on if local-result-dir is used. may or may not contain objName
// 2019-03-22_17-20-53.594000_ftrh/shard_0/test_result_1.xml or shard_0/test_result_1.xml
val objName = matrices.runPath // 2019-03-22_17-20-53.594000_ftrh

// shard location in path changes based on iOS or Android.
val matchResult = Regex("/.*(shard_\\d+)(-rerun_\\d+)?/").find(xmlFile.toString())
val shardName = matchResult?.value?.removePrefix("/")?.removeSuffix("/") // shard_0 || shard_0-rerun_1
val matrixPath = Paths.get(objName, shardName).toString() // 2019-03-22_17-20-53.594000_ftrh/shard_0

var webLink = ""
val savedMatrix = matrices.map.values.firstOrNull { it.gcsPath.endsWith(matrixPath) }
if (savedMatrix != null) {
webLink = savedMatrix.webLink
} else {
println("WARNING: Matrix path not found in JSON. $matrixPath")
}
return webLink
}
private fun getWebLink(matrices: MatrixMap, xmlFile: File): String = xmlFile.getMatrixPath(matrices.runPath)
?.findMatrixPath(matrices) ?: "".also { println("WARNING: Matrix path not found in JSON.") }

private val deviceStringRgx = Regex("([^-]+-[^-]+-[^-]+-[^-]+).*")

Expand Down Expand Up @@ -215,3 +197,7 @@ object ReportManager {
GcStorage.uploadJunitXml(newTestResult, args)
}
}

private fun String.findMatrixPath(matrices: MatrixMap) =
matrices.map.values.firstOrNull { savedMatrix -> savedMatrix.gcsPath.endsWith(this) }?.webLink
?: "".also { println("WARNING: Matrix path not found in JSON. $this") }
7 changes: 4 additions & 3 deletions test_runner/src/test/kotlin/Debug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fun main() {
val projectId = System.getenv("GOOGLE_CLOUD_PROJECT")
?: "YOUR PROJECT ID"

val quantity = "single"
val type = "error"
val quantity = "multiple"
val type = "success"
// Bugsnag keeps the process alive so we must call exitProcess
// https://github.com/bugsnag/bugsnag-java/issues/151
withGlobalExceptionHandling {
Expand All @@ -23,7 +23,8 @@ fun main() {
// "--dry",
// "--dump-shards",
// "--output-style=single",
"--full-junit-result",
// "--full-junit-result",
// "--legacy-junit-result",
"-c=src/test/kotlin/ftl/fixtures/test_app_cases/flank-$quantity-$type.yml",
"--project=$projectId"
// "--client-details=key1=value1,key2=value2"
Expand Down
12 changes: 12 additions & 0 deletions test_runner/src/test/kotlin/ftl/reports/utils/ReportManagerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ftl.reports.FullJUnitReport
import ftl.reports.JUnitReport
import ftl.reports.MatrixResultsReport
import ftl.reports.util.ReportManager
import ftl.reports.util.getMatrixPath
import ftl.reports.xml.model.JUnitTestCase
import ftl.reports.xml.model.JUnitTestResult
import ftl.reports.xml.model.JUnitTestSuite
Expand All @@ -21,11 +22,13 @@ import io.mockk.mockkObject
import io.mockk.unmockkAll
import io.mockk.verify
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.contrib.java.lang.system.SystemErrRule
import org.junit.contrib.java.lang.system.SystemOutRule
import org.junit.runner.RunWith
import java.io.File

@RunWith(FlankTestRunner::class)
class ReportManagerTest {
Expand Down Expand Up @@ -196,4 +199,13 @@ class ReportManagerTest {
assertThat(ReportManager.getDeviceString(""))
.isEqualTo("")
}

@Test
fun `should get weblink from legacy path and ios path`() {
val legacyPath = File("results/2020-08-06_12-08-55.641213_jGpY/matrix_0/NexusLowRes-28-en-portrait/test_result_1.xml")
val iosPath = File("results/test_dir/shard_0/iphone8-12.0-en-portrait/test_result_0.xml")
val objectName = "object_name"
assertEquals("object_name/2020-08-06_12-08-55.641213_jGpY/matrix_0", legacyPath.getMatrixPath(objectName))
assertEquals("object_name/test_dir/shard_0", iosPath.getMatrixPath(objectName))
}
}