Skip to content

Commit

Permalink
WIP manual sharding
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline authored and jan-goral committed Feb 24, 2020
1 parent b94851b commit fbc2db2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
1 change: 1 addition & 0 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ object ArgsHelper {

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)

return testMethodsAlwaysRun(shards.stringShards(), args)
Expand Down
27 changes: 10 additions & 17 deletions test_runner/src/main/kotlin/ftl/gc/GcAndroidTestMatrix.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
package ftl.gc

import com.google.api.services.testing.Testing
import com.google.api.services.testing.model.Account
import com.google.api.services.testing.model.AndroidDeviceList
import com.google.api.services.testing.model.AndroidInstrumentationTest
import com.google.api.services.testing.model.ClientInfo
import com.google.api.services.testing.model.EnvironmentMatrix
import com.google.api.services.testing.model.EnvironmentVariable
import com.google.api.services.testing.model.FileReference
import com.google.api.services.testing.model.GoogleAuto
import com.google.api.services.testing.model.GoogleCloudStorage
import com.google.api.services.testing.model.ResultStorage
import com.google.api.services.testing.model.TestMatrix
import com.google.api.services.testing.model.TestSetup
import com.google.api.services.testing.model.TestSpecification
import com.google.api.services.testing.model.ToolResultsHistory
import com.google.api.services.testing.model.*
import ftl.args.AndroidArgs
import ftl.util.ShardCounter
import ftl.util.Utils.fatalError
Expand All @@ -33,7 +20,7 @@ object GcAndroidTestMatrix {
testApkGcsPath: String,
runGcsPath: String,
androidDeviceList: AndroidDeviceList,
testTargets: List<String>,
testTargets: List<List<String>>,
args: AndroidArgs,
shardCounter: ShardCounter,
toolResultsHistory: ToolResultsHistory
Expand All @@ -44,9 +31,17 @@ object GcAndroidTestMatrix {

val matrixGcsPath = join(args.resultsBucket, runGcsPath, shardCounter.next())

// ShardingOption().setUniformSharding(UniformSharding().setNumShards())
val testTargetsForShard: List<TestTargetsForShard> = testTargets.map {
TestTargetsForShard().setTestTargets(it)
}
val manualSharding = ManualSharding().setTestTargetsForShard(testTargetsForShard)
val shardingOption = ShardingOption().setManualSharding(manualSharding)

val androidInstrumentation = AndroidInstrumentationTest()
.setAppApk(FileReference().setGcsPath(appApkGcsPath))
.setTestApk(FileReference().setGcsPath(testApkGcsPath))
.setShardingOption(shardingOption)

if (args.testRunnerClass != null) {
androidInstrumentation.testRunnerClass = args.testRunnerClass
Expand All @@ -56,8 +51,6 @@ object GcAndroidTestMatrix {
androidInstrumentation.orchestratorOption = "USE_ORCHESTRATOR"
}

androidInstrumentation.testTargets = testTargets

// --auto-google-login
// https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run
// https://github.com/bootstraponline/gcloud_cli/blob/e4b5e01610abad2e31d8a6edb20b17b2f84c5395/google-cloud-sdk/lib/googlecloudsdk/api_lib/firebase/test/android/matrix_creator.py#L174
Expand Down
31 changes: 15 additions & 16 deletions test_runner/src/main/kotlin/ftl/run/AndroidTestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ object AndroidTestRunner {
val testShardChunks = AndroidTestShard.getTestShardChunks(androidArgs, apk.test)
allTestShardChunks += testShardChunks
repeat(runCount) {
testShardChunks.forEach { testTargets ->
// specify dispatcher to avoid inheriting main runBlocking context that runs in the main thread
// https://kotlinlang.org/docs/reference/coroutines/coroutine-context-and-dispatchers.html
jobs += async(Dispatchers.IO) {
GcAndroidTestMatrix.build(
appApkGcsPath = apk.app ?: androidArgs.appApk,
testApkGcsPath = apk.test,
runGcsPath = runGcsPath,
androidDeviceList = androidDeviceList,
testTargets = testTargets,
args = androidArgs,
shardCounter = shardCounter,
toolResultsHistory = history
).executeWithRetry()
}
// specify dispatcher to avoid inheriting main runBlocking context that runs in the main thread
// https://kotlinlang.org/docs/reference/coroutines/coroutine-context-and-dispatchers.html
jobs += async(Dispatchers.IO) {
GcAndroidTestMatrix.build(
appApkGcsPath = apk.app ?: androidArgs.appApk,
testApkGcsPath = apk.test,
runGcsPath = runGcsPath,
androidDeviceList = androidDeviceList,
testTargets = testShardChunks,
args = androidArgs,
shardCounter = shardCounter,
toolResultsHistory = history
).executeWithRetry()
}
}
}
Expand All @@ -73,7 +71,8 @@ object AndroidTestRunner {
val result = mutableListOf<AppTestPair>()

appTestApks.forEach { apks ->
val appApkGcsPath = async(Dispatchers.IO) { GcStorage.upload(apks.app ?: args.appApk, gcsBucket, runGcsPath) }
val appApkGcsPath =
async(Dispatchers.IO) { GcStorage.upload(apks.app ?: args.appApk, gcsBucket, runGcsPath) }
val testApkGcsPath = async(Dispatchers.IO) { GcStorage.upload(apks.test, gcsBucket, runGcsPath) }

result.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GcAndroidTestMatrixTest {
testApkGcsPath = "",
runGcsPath = "",
androidDeviceList = AndroidDeviceList(),
testTargets = listOf(""),
testTargets = listOf(listOf("")),
args = androidArgs,
shardCounter = ShardCounter(),
toolResultsHistory = createToolResultsHistory(androidArgs)
Expand Down

0 comments on commit fbc2db2

Please sign in to comment.