Skip to content

Commit

Permalink
Fix bug where flag 'disable-sharding' causes bad request to TL
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Pasterz committed Feb 23, 2020
1 parent 67284dd commit 577e2bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 6 additions & 3 deletions test_runner/src/main/kotlin/ftl/args/AndroidTestShard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ object AndroidTestShard {

// computed properties not specified in yaml
fun getTestShardChunks(args: AndroidArgs, testApk: String): List<List<String>> {
if (args.disableSharding) return listOf(emptyList())

// Download test APK if necessary so it can be used to validate test methods
var testLocalApk = testApk
if (testApk.startsWith(FtlConstants.GCS_PREFIX)) {
Expand All @@ -28,7 +26,12 @@ object AndroidTestShard {

private fun getTestMethods(args: AndroidArgs, testLocalApk: String): List<String> {
val allTestMethods = DexParser.findTestMethods(testLocalApk)
require(allTestMethods.isNotEmpty()) { Utils.fatalError("Test APK has no tests") }
val shouldIgnoreMissingTests = allTestMethods.isEmpty() && args.disableSharding
val shouldThrowErrorIfMissingTests = allTestMethods.isEmpty() && !args.disableSharding
when {
shouldIgnoreMissingTests -> return mutableListOf()
shouldThrowErrorIfMissingTests -> throw IllegalStateException(Utils.fatalError("Test APK has no tests"))
}
val testFilter = TestFilters.fromTestTargets(args.testTargets)
val filteredTests = allTestMethods
.asSequence()
Expand Down
15 changes: 8 additions & 7 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,15 @@ object ArgsHelper {
}

fun calculateShards(filteredTests: List<String>, args: IArgs): List<List<String>> {
val oldTestResult = GcStorage.downloadJunitXml(args) ?: JUnitTestResult(mutableListOf())

val shardCount = Shard.shardCountByTime(filteredTests, oldTestResult, args)

// TODO: manual sharding must be limited to 1..50 tests per shard
val shards = Shard.createShardsByShardCount(filteredTests, oldTestResult, args, shardCount)
val shards = if (args.disableSharding) {
mutableListOf(filteredTests as MutableList<String>)
} else {
val oldTestResult = GcStorage.downloadJunitXml(args) ?: JUnitTestResult(mutableListOf())
val shardCount = Shard.shardCountByTime(filteredTests, oldTestResult, args)
Shard.createShardsByShardCount(filteredTests, oldTestResult, args, shardCount).stringShards()
}

return testMethodsAlwaysRun(shards.stringShards(), args)
return testMethodsAlwaysRun(shards, args)
}

private fun testMethodsAlwaysRun(shards: StringShards, args: IArgs): StringShards {
Expand Down

0 comments on commit 577e2bc

Please sign in to comment.