Skip to content

Commit

Permalink
fix: Add additional index to matrix when multiple test runs (#1261)
Browse files Browse the repository at this point in the history
* Update RunAndroidTests.kt

* Update RunAndroidTests.kt

* Added tests
  • Loading branch information
adamfilipow92 authored Oct 22, 2020
1 parent cc86dac commit 2726065
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test_runner/src/main/kotlin/ftl/run/platform/RunAndroidTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ internal suspend fun runAndroidTests(args: AndroidArgs): TestResult = coroutineS
val additionalApks = args.uploadAdditionalApks(runGcsPath)

args.createAndroidTestContexts().dumpShards(args).upload(args.resultsBucket, runGcsPath)
.forEachIndexed { index, context ->
.forEachIndexed { contextIndex, context ->
if (context is InstrumentationTestContext) {
ignoredTestsShardChunks += context.ignoredTestCases
allTestShardChunks += context.shards
}
val androidTestConfig = args.createAndroidTestConfig(context)
testMatrices += executeAndroidTestMatrix(runCount = args.repeatTests) {
testMatrices += executeAndroidTestMatrix(runCount = args.repeatTests) { runIndex ->
GcAndroidTestMatrix.build(
androidTestConfig = androidTestConfig,
runGcsPath = "$runGcsPath/matrix_$index/",
runGcsPath = runGcsPath.createGcsPath(contextIndex, runIndex),
additionalApkGcsPaths = additionalApks,
androidDeviceList = devices,
args = args,
Expand All @@ -78,6 +78,10 @@ internal suspend fun runAndroidTests(args: AndroidArgs): TestResult = coroutineS
)
}

private fun String.createGcsPath(contextIndex: Int, runIndex: Int) =
if (runIndex == 0) "$this/matrix_$contextIndex/"
else "$this/matrix_${contextIndex}_$runIndex/"

private fun List<AndroidTestContext>.dumpShards(config: AndroidArgs) = takeIf { config.isInstrumentationTest }?.apply {
filterIsInstance<InstrumentationTestContext>().asMatrixTestShards().saveShards(config.obfuscateDumpShards)
if (config.disableResultsUpload.not()) GcStorage.upload(ANDROID_SHARD_FILE, config.resultsBucket, config.resultsDir)
Expand All @@ -92,11 +96,11 @@ private fun AndroidMatrixTestShards.saveShards(obfuscateOutput: Boolean) = saveS

private suspend fun executeAndroidTestMatrix(
runCount: Int,
createTestMatrix: () -> Testing.Projects.TestMatrices.Create
createTestMatrix: (runIndex: Int) -> Testing.Projects.TestMatrices.Create
): List<Deferred<TestMatrix>> = coroutineScope {
(0 until runCount).map {
async(Dispatchers.IO) {
createTestMatrix().executeWithRetry()
createTestMatrix(it).executeWithRetry()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package ftl.run.platform

import ftl.args.AndroidArgs
import ftl.gc.GcAndroidTestMatrix
import ftl.run.model.TestResult
import ftl.test.util.FlankTestRunner
import ftl.test.util.mixedConfigYaml
import ftl.test.util.should
import io.mockk.every
import io.mockk.mockkObject
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
Expand Down Expand Up @@ -34,4 +38,54 @@ class RunAndroidTestsKtTest {
// then
assertEquals(expected, actual)
}

@Test
fun `should add additional index if repeatTests set`() {
val androidArgs = AndroidArgs.load(mixedConfigYaml)
mockkObject(GcAndroidTestMatrix, androidArgs) {

every { androidArgs.resultsDir } returns "test_dir"
every { androidArgs.resultsBucket } returns "test_bucket"
every { androidArgs.repeatTests } returns 2

runBlocking {
runAndroidTests(androidArgs)
}

verify {
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_0/", any(), any(), any(), any())
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_0_1/", any(), any(), any(), any())
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_1/", any(), any(), any(), any())
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_1_1/", any(), any(), any(), any())
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_2/", any(), any(), any(), any())
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_2_1/", any(), any(), any(), any())
}

verify(inverse = true) {
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_0_2/", any(), any(), any(), any())
}
}
}

@Test
fun `shouldn't add additional index if repeatTests not set`() {
val androidArgs = AndroidArgs.load(mixedConfigYaml)
mockkObject(GcAndroidTestMatrix, androidArgs) {

every { androidArgs.resultsDir } returns "test_dir"
every { androidArgs.resultsBucket } returns "test_bucket"

runBlocking {
runAndroidTests(androidArgs)
}

verify(inverse = true) {
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_0_1/", any(), any(), any(), any())
}

verify {
GcAndroidTestMatrix.build(any(), any(), "test_dir/matrix_0/", any(), any(), any(), any())
}
}
}
}

0 comments on commit 2726065

Please sign in to comment.