Skip to content

Commit

Permalink
Handle num-uniform-shards with dump-shards & fix descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-goral committed May 23, 2020
1 parent 07ed2c3 commit 5606561
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
8 changes: 6 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ object ArgsHelper {
return ArgsFileVisitor("glob:$filePath").walk(searchDir)
}

fun calculateShards(filteredTests: List<FlankTestMethod>, args: IArgs): ShardChunks {
fun calculateShards(
filteredTests: List<FlankTestMethod>,
args: IArgs,
forcedShardCount: Int? = null
): ShardChunks {
if (filteredTests.isEmpty()) {
// Avoid unnecessary computing if we already know there aren't tests to run.
return listOf(emptyList())
Expand All @@ -234,7 +238,7 @@ object ArgsHelper {
listOf(filteredTests.map { it.testName }.toMutableList())
} else {
val oldTestResult = GcStorage.downloadJunitXml(args) ?: JUnitTestResult(mutableListOf())
val shardCount = Shard.shardCountByTime(filteredTests, oldTestResult, args)
val shardCount = forcedShardCount ?: Shard.shardCountByTime(filteredTests, oldTestResult, args)
Shard.createShardsByShardCount(filteredTests, oldTestResult, args, shardCount).stringShards()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ftl.config.FtlConstants.defaultAndroidVersion
import ftl.config.FtlConstants.defaultLocale
import ftl.config.FtlConstants.defaultOrientation
import ftl.mock.MockServer
import ftl.run.IOS_SHARD_FILE
import ftl.run.ANDROID_SHARD_FILE
import ftl.run.dumpShards
import ftl.run.newTestRun
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -51,7 +51,10 @@ class AndroidRunCommand : CommonRunCommand(), Runnable {

// Flank debug

@Option(names = ["--dump-shards"], description = ["Dumps the shards to $IOS_SHARD_FILE for debugging"])
@Option(
names = ["--dump-shards"],
description = ["Measures test shards from given test apks and writes them into $ANDROID_SHARD_FILE file instead of executing."]
)
var dumpShards: Boolean = false

// Flank specific
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ftl.config.FtlConstants
import ftl.config.FtlConstants.defaultIosModel
import ftl.config.FtlConstants.defaultIosVersion
import ftl.mock.MockServer
import ftl.run.ANDROID_SHARD_FILE
import ftl.run.IOS_SHARD_FILE
import ftl.run.dumpShards
import ftl.run.newTestRun
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -47,7 +47,10 @@ class IosRunCommand : CommonRunCommand(), Runnable {

// Flank debug

@Option(names = ["--dump-shards"], description = ["Dumps the shards to $ANDROID_SHARD_FILE for debugging"])
@Option(
names = ["--dump-shards"],
description = ["Measures test shards from given test apks and writes them into $IOS_SHARD_FILE file instead of executing."]
)
var dumpShards: Boolean = false

// Flank specific
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ fun getInstrumentationShardChunks(
testApks = testApks.download(),
testFilter = TestFilters.fromTestTargets(args.testTargets)
).mapValues { (_, testMethods: List<FlankTestMethod>) ->
when {
testMethods.isEmpty() -> emptyList<List<String>>().also { printNoTests(testApks) }
args.numUniformShards == null -> ArgsHelper.calculateShards(testMethods, args)
else -> listOf(testMethods.map(FlankTestMethod::testName))
}
if (testMethods.isEmpty())
emptyList<List<String>>().also { printNoTests(testApks) } else
ArgsHelper.calculateShards(testMethods, args, args.numUniformShards)
}

private fun getFlankTestMethods(
Expand Down

0 comments on commit 5606561

Please sign in to comment.