Skip to content

Commit

Permalink
Fix empty test targets (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline authored Apr 16, 2019
1 parent ca27667 commit 859a2ce
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AndroidArgs(
val environmentVariables = cli?.environmentVariables ?: androidGcloud.environmentVariables
val directoriesToPull = cli?.directoriesToPull ?: androidGcloud.directoriesToPull
val performanceMetrics = cli?.performanceMetrics ?: cli?.noPerformanceMetrics?.not() ?: androidGcloud.performanceMetrics
val testTargets = cli?.testTargets ?: androidGcloud.testTargets
val testTargets = cli?.testTargets ?: androidGcloud.testTargets.filterNotNull()
val devices = cli?.device ?: androidGcloud.device

private val flank = flankYml.flank
Expand Down
15 changes: 10 additions & 5 deletions test_runner/src/main/kotlin/ftl/args/ArgsToString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import ftl.config.Device

object ArgsToString {

fun mapToString(map: Map<String, String>): String {
fun mapToString(map: Map<String, String>?): String {
if (map.isNullOrEmpty()) return ""
return map.map { (key, value) -> " $key: $value" }
.joinToString("\n")
}

fun listToString(list: List<String>): String {
return list.joinToString("\n") { dir -> " - $dir" }
fun listToString(list: List<String?>?): String {
if (list.isNullOrEmpty()) return ""
return list.filterNotNull()
.joinToString("\n") { dir -> " - $dir" }
}

fun devicesToString(devices: List<Device>): String {
return devices.joinToString("\n") { "$it" }
fun devicesToString(devices: List<Device?>?): String {
if (devices.isNullOrEmpty()) return ""
return devices.filterNotNull()
.joinToString("\n") { "$it" }
}
}
6 changes: 3 additions & 3 deletions test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class IosArgs(
override val localResultDir = cli?.localResultsDir ?: flank.localResultDir

private val iosFlank = iosFlankYml.flank
val testTargets = cli?.testTargets ?: iosFlank.testTargets
val testTargets = cli?.testTargets ?: iosFlank.testTargets.filterNotNull()

// computed properties not specified in yaml
override val testShardChunks: List<List<String>> by lazy {
Expand Down Expand Up @@ -166,13 +166,13 @@ ${listToString(testTargets)}
}
}

fun filterTests(validTestMethods: List<String>, testTargetsRgx: List<String>): List<String> {
fun filterTests(validTestMethods: List<String>, testTargetsRgx: List<String?>): List<String> {
if (testTargetsRgx.isEmpty()) {
return validTestMethods
}

return validTestMethods.filter { test ->
testTargetsRgx.forEach { target ->
testTargetsRgx.filterNotNull().forEach { target ->
try {
if (test.matches(target.toRegex())) {
return@filter true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AndroidGcloudYmlParams(
val performanceMetrics: Boolean = true,

@field:JsonProperty("test-targets")
val testTargets: List<String> = emptyList(),
val testTargets: List<String?> = emptyList(),

val device: List<Device> = listOf(Device(defaultAndroidModel, defaultAndroidVersion))
) {
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/IosFlankYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
@JsonIgnoreProperties(ignoreUnknown = true)
class IosFlankYmlParams(
@field:JsonProperty("test-targets")
val testTargets: List<String> = emptyList()
val testTargets: List<String?> = emptyList()
) {
companion object : IYmlKeys {
override val keys = listOf("test-targets")
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ object YamlDeprecated {

if (fix) {
Files.write(yamlPath, string.toByteArray())
println("\nUpdated flank.yml file")
println("\nUpdated ${yamlPath.fileName} file")
}
return errorDetected
}
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/shard/Shard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ object Shard {
shards = shards.sortedBy { it.time }
}

val allTests = testsToRun.size
val allTests = testsToRun.size // zero when test targets is empty
val cacheHit = allTests - cacheMiss
val cachePercent = cacheHit.toDouble() / allTests * 100.0
val cachePercent = if (allTests == 0) 0.0 else cacheHit.toDouble() / allTests * 100.0
println()
println(" Smart Flank cache hit: ${cachePercent.roundToInt()}% ($cacheHit / $allTests)")
println(" Shard times: " + shards.joinToString(", ") { "${it.time.roundToInt()}s" } + "\n")
Expand Down
15 changes: 15 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ class AndroidArgsTest {
@JvmField
var expectedException = ExpectedException.none()!!

@Test
fun empty_testTargets() {
val emptyTestTargets = """
gcloud:
app: $appApk
test: $testApk
test-targets:
-
""".trimIndent()

val args = AndroidArgs.load(emptyTestTargets)
assertThat(args.testTargets.size).isEqualTo(0)
}

@Test
fun androidArgs_invalidModel() {
expectedException.expect(RuntimeException::class.java)
Expand Down
16 changes: 16 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ class IosArgsTest {
@JvmField
val systemErrRule = SystemErrRule().muteForSuccessfulTests()!!

@Test
fun empty_testTargets() {
val emptyTestTargets = """
gcloud:
test: "./src/test/kotlin/ftl/fixtures/tmp/ios_earlgrey2.zip"
xctestrun-file: "./src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos12.1-arm64e.xctestrun"
flank:
test-targets:
-
""".trimIndent()

val args = IosArgs.load(emptyTestTargets)
assertThat(args.testTargets.size).isEqualTo(0)
}

@Test
fun args_invalidDeviceExits() {
exceptionRule.expectMessage("iOS 99.9 on iphoneZ is not a supported device")
Expand Down

0 comments on commit 859a2ce

Please sign in to comment.