Skip to content

Commit

Permalink
Add --dump-shards to dump Android/iOS shards for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Jun 26, 2019
1 parent 66a3a77 commit 5e42ef2
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions test_runner/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ EarlGreyExample/
xctestrun/
src/test/kotlin/ftl/fixtures/error_result/*.xml
src/test/kotlin/ftl/fixtures/success_result/*.xml
*.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.cli.firebase.test.android

import ftl.args.AndroidArgs
import ftl.args.AndroidTestShard
import ftl.args.yml.AppTestPair
import ftl.config.Device
import ftl.config.FtlConstants
Expand All @@ -9,7 +10,9 @@ import ftl.config.FtlConstants.defaultAndroidVersion
import ftl.config.FtlConstants.defaultLocale
import ftl.config.FtlConstants.defaultOrientation
import ftl.run.TestRunner
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.system.exitProcess
import kotlinx.coroutines.runBlocking
import picocli.CommandLine.Command
import picocli.CommandLine.Option
Expand All @@ -32,11 +35,24 @@ class AndroidRunCommand : Runnable {

override fun run() {
val config = AndroidArgs.load(Paths.get(configPath), cli = this)

if (dumpShards) {
val testShardChunks = AndroidTestShard.getTestShardChunks(config, config.testApk)
val testShardChunksJson = TestRunner.gson.toJson(testShardChunks)
Files.write(Paths.get("android_shards.json"), testShardChunksJson.toByteArray())
exitProcess(0)
}

runBlocking {
TestRunner.newRun(config)
}
}

// Flank debug

@Option(names = ["--dump-shards"], description = ["Dumps the shards to ios_shards.json for debugging"])
var dumpShards: Boolean = false

// Flank specific

@Option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import ftl.config.FtlConstants
import ftl.config.FtlConstants.defaultIosModel
import ftl.config.FtlConstants.defaultIosVersion
import ftl.run.TestRunner
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.system.exitProcess
import kotlinx.coroutines.runBlocking
import picocli.CommandLine.Command
import picocli.CommandLine.Option
Expand All @@ -28,11 +30,23 @@ Configuration is read from flank.yml
class IosRunCommand : Runnable {
override fun run() {
val config = IosArgs.load(Paths.get(configPath), cli = this)

if (dumpShards) {
val testShardChunksJson = TestRunner.gson.toJson(config.testShardChunks)
Files.write(Paths.get("ios_shards.json"), testShardChunksJson.toByteArray())
exitProcess(0)
}

runBlocking {
TestRunner.newRun(config)
}
}

// Flank debug

@Option(names = ["--dump-shards"], description = ["Dumps the shards to ios_shards.json for debugging"])
var dumpShards: Boolean = false

// Flank specific

@Option(
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/ios/Xctestrun.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object Xctestrun {
// Finds tests in a xctestrun file
private fun findTestNames(xctestrun: File): List<String> {
val root = parse(xctestrun)
var result = listOf<String>()
val result = mutableListOf<String>()
// EarlGreyExampleSwiftTests_iphoneos11.3-arm64.xctestrun => EarlGreyExampleSwiftTests
val testRoot = xctestrun.parent + "/"

Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/run/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

object TestRunner {
private val gson = GsonBuilder().setPrettyPrinting().create()!!
val gson = GsonBuilder().setPrettyPrinting().create()!!

fun assertMockUrl() {
if (!FtlConstants.useMock) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class AndroidRunCommandTest {
fun empty_params_parse_null() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parse()
assertThat(cmd.dumpShards).isFalse()
assertThat(cmd.app).isNull()
assertThat(cmd.test).isNull()
assertThat(cmd.testTargets).isNull()
Expand Down Expand Up @@ -358,4 +359,12 @@ class AndroidRunCommandTest {
val expected = AppTestPair(app = "a", test = "b")
assertThat(cmd.additionalAppTestApks).isEqualTo(listOf(expected))
}

@Test
fun `dump-shards parse`() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parse("--dump-shards=true")

assertThat(cmd.dumpShards).isEqualTo(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class IosRunCommandTest {
fun empty_params_parse_null() {
val cmd = IosRunCommand()
CommandLine(cmd).parse()
assertThat(cmd.dumpShards).isFalse()
assertThat(cmd.resultsBucket).isNull()
assertThat(cmd.recordVideo).isNull()
assertThat(cmd.noRecordVideo).isNull()
Expand Down Expand Up @@ -273,4 +274,12 @@ class IosRunCommandTest {

assertThat(cmd.smartFlankGcsPath).isEqualTo("foo")
}

@Test
fun `dump-shards parse`() {
val cmd = IosRunCommand()
CommandLine(cmd).parse("--dump-shards=true")

assertThat(cmd.dumpShards).isEqualTo(true)
}
}

0 comments on commit 5e42ef2

Please sign in to comment.