-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AndroidTestContext as base data for dump shards & test execution #817
Merged
+493
−273
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5e97ed5
Omit global app apk if additional-app-test-apks specified
jan-goral ea3a530
CR fixes
jan-goral 3861cde
Add AndroidTestContext as base data for dump shards & test execution
jan-goral 907488a
Robo test with instrumented test can running in single run
jan-goral af6b27d
Add integration test for runAndroidTests
jan-goral 0ca0357
Add test for dumpShards
jan-goral 7d4a056
Improve should & ignore output
jan-goral 58c6c33
Fix RunAndroidTestsKtTest
jan-goral 03ba407
CR fix
jan-goral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test_runner/src/main/kotlin/ftl/run/model/AndroidTestContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ftl.run.model | ||
|
||
import ftl.args.ShardChunks | ||
import ftl.util.FileReference | ||
|
||
sealed class AndroidTestContext | ||
|
||
data class InstrumentationTestContext( | ||
val app: FileReference, | ||
val test: FileReference, | ||
val shards: ShardChunks = emptyList() | ||
) : AndroidTestContext() | ||
|
||
data class RoboTestContext( | ||
val app: FileReference, | ||
val roboScript: FileReference | ||
) : AndroidTestContext() |
8 changes: 0 additions & 8 deletions
8
test_runner/src/main/kotlin/ftl/run/model/InstrumentationTestApk.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 7 additions & 19 deletions
26
test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
package ftl.run.platform.android | ||
|
||
import ftl.args.AndroidArgs | ||
import ftl.args.ShardChunks | ||
import ftl.args.yml.UploadedApks | ||
import ftl.util.FlankFatalError | ||
import ftl.run.model.AndroidTestContext | ||
import ftl.run.model.InstrumentationTestContext | ||
import ftl.run.model.RoboTestContext | ||
|
||
internal fun AndroidArgs.createAndroidTestConfig( | ||
uploadedApks: UploadedApks, | ||
testShards: ShardChunks? = null, | ||
runGcsPath: String? = null, | ||
keepTestTargetsEmpty: Boolean = false | ||
): AndroidTestConfig = when { | ||
isInstrumentationTest -> createInstrumentationConfig( | ||
uploadedApks = uploadedApks, | ||
keepTestTargetsEmpty = keepTestTargetsEmpty, | ||
testShards = testShards ?: throw FlankFatalError("Arg testShards is required for instrumentation test.") | ||
) | ||
isRoboTest | ||
-> createRoboConfig( | ||
uploadedApks = uploadedApks, | ||
runGcsPath = runGcsPath ?: throw FlankFatalError("Arg runGcsPath is required for robo test.") | ||
) | ||
else -> throw FlankFatalError("Cannot create AndroidTestConfig, invalid AndroidArgs.") | ||
testContext: AndroidTestContext | ||
): AndroidTestConfig = when (testContext) { | ||
is InstrumentationTestContext -> createInstrumentationConfig(testContext) | ||
is RoboTestContext -> createRoboConfig(testContext) | ||
} |
72 changes: 72 additions & 0 deletions
72
test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ftl.run.platform.android | ||
|
||
import com.linkedin.dex.parser.DexParser | ||
import ftl.args.AndroidArgs | ||
import ftl.args.ArgsHelper | ||
import ftl.config.FtlConstants | ||
import ftl.filter.TestFilter | ||
import ftl.filter.TestFilters | ||
import ftl.run.model.AndroidTestContext | ||
import ftl.run.model.InstrumentationTestContext | ||
import ftl.util.FlankTestMethod | ||
import ftl.util.downloadIfNeeded | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
import kotlinx.coroutines.coroutineScope | ||
import java.io.File | ||
|
||
suspend fun AndroidArgs.createAndroidTestContexts(): List<AndroidTestContext> = resolveApks().setupShards(this) | ||
|
||
private suspend fun List<AndroidTestContext>.setupShards( | ||
args: AndroidArgs, | ||
testFilter: TestFilter = TestFilters.fromTestTargets(args.testTargets) | ||
): List<AndroidTestContext> = coroutineScope { | ||
map { testContext -> | ||
async { | ||
if (testContext !is InstrumentationTestContext) testContext | ||
else testContext.downloadApks().calculateShards( | ||
args = args, | ||
testFilter = testFilter | ||
) | ||
} | ||
}.awaitAll().dropEmptyInstrumentationTest() | ||
} | ||
|
||
private fun InstrumentationTestContext.downloadApks(): InstrumentationTestContext = copy( | ||
app = app.downloadIfNeeded(), | ||
test = test.downloadIfNeeded() | ||
) | ||
|
||
private fun InstrumentationTestContext.calculateShards( | ||
args: AndroidArgs, | ||
testFilter: TestFilter = TestFilters.fromTestTargets(args.testTargets) | ||
): InstrumentationTestContext = copy( | ||
shards = ArgsHelper.calculateShards( | ||
filteredTests = getFlankTestMethods(testFilter), | ||
args = args, | ||
forcedShardCount = args.numUniformShards | ||
).filter { it.isNotEmpty() } | ||
) | ||
|
||
private fun InstrumentationTestContext.getFlankTestMethods( | ||
testFilter: TestFilter | ||
): List<FlankTestMethod> = | ||
DexParser.findTestMethods(test.local).asSequence().distinct().filter(testFilter.shouldRun).map { testMethod -> | ||
FlankTestMethod( | ||
testName = "class ${testMethod.testName}", | ||
ignored = testMethod.annotations.any { it.name == "org.junit.Ignore" } | ||
) | ||
}.toList() | ||
|
||
private fun List<AndroidTestContext>.dropEmptyInstrumentationTest(): List<AndroidTestContext> = | ||
filterIsInstance<InstrumentationTestContext>().filter { it.shards.isEmpty() }.let { withoutTests -> | ||
if (withoutTests.isNotEmpty()) | ||
printNoTests(withoutTests) | ||
minus(withoutTests) | ||
} | ||
|
||
private fun printNoTests(testApks: List<InstrumentationTestContext>) { | ||
val testApkNames = testApks.joinToString(", ") { pathname -> File(pathname.test.local).name } | ||
println("${FtlConstants.indent}No tests for $testApkNames") | ||
println() | ||
} |
15 changes: 6 additions & 9 deletions
15
test_runner/src/main/kotlin/ftl/run/platform/android/CreateInstrumentationConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
package ftl.run.platform.android | ||
|
||
import ftl.args.AndroidArgs | ||
import ftl.args.ShardChunks | ||
import ftl.args.yml.UploadedApks | ||
import ftl.run.model.InstrumentationTestContext | ||
|
||
internal fun AndroidArgs.createInstrumentationConfig( | ||
uploadedApks: UploadedApks, | ||
keepTestTargetsEmpty: Boolean, | ||
testShards: ShardChunks | ||
testApk: InstrumentationTestContext | ||
) = AndroidTestConfig.Instrumentation( | ||
appApkGcsPath = uploadedApks.app, | ||
testApkGcsPath = uploadedApks.test!!, | ||
appApkGcsPath = testApk.app.gcs, | ||
testApkGcsPath = testApk.test.gcs, | ||
testRunnerClass = testRunnerClass, | ||
orchestratorOption = "USE_ORCHESTRATOR".takeIf { useOrchestrator }, | ||
disableSharding = disableSharding, | ||
numUniformShards = numUniformShards, | ||
testShards = testShards, | ||
keepTestTargetsEmpty = keepTestTargetsEmpty | ||
testShards = testApk.shards, | ||
keepTestTargetsEmpty = disableSharding && testTargets.isEmpty() | ||
) |
12 changes: 4 additions & 8 deletions
12
test_runner/src/main/kotlin/ftl/run/platform/android/CreateRoboConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
package ftl.run.platform.android | ||
|
||
import ftl.args.AndroidArgs | ||
import ftl.args.yml.UploadedApks | ||
import ftl.gc.GcStorage | ||
import ftl.run.model.RoboTestContext | ||
|
||
internal fun AndroidArgs.createRoboConfig( | ||
uploadedApks: UploadedApks, | ||
runGcsPath: String | ||
testApk: RoboTestContext | ||
) = AndroidTestConfig.Robo( | ||
appApkGcsPath = uploadedApks.app, | ||
appApkGcsPath = testApk.app.gcs, | ||
flankRoboDirectives = roboDirectives, | ||
roboScriptGcsPath = roboScript?.let { | ||
GcStorage.upload(it, resultsBucket, runGcsPath) | ||
} | ||
roboScriptGcsPath = testApk.roboScript.gcs | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion keeping curly braces is more redable
vs
or
Tell me what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curly braces make sense when u need to open new scope for more than one operation. Otherwise I prefer clear declarative expressions where curly braces are redundant.