Skip to content

Commit 99db89d

Browse files
author
Piotr Mądry
committed
improve sharding
1 parent aed63f6 commit 99db89d

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ apply plugin: "com.gradle.plugin-publish"
66
apply plugin: "org.gradle.kotlin.kotlin-dsl"
77

88
group = "firebase.test.lab"
9-
version = "1.1.6.23"
9+
version = "1.1.7"
1010

1111
gradlePlugin {
1212
plugins {

plugin/src/main/java/com/appunite/firebasetestlabplugin/FirebaseTestLabPlugin.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ class FirebaseTestLabPlugin : Plugin<Project> {
277277
})
278278
}
279279

280+
val testResultFile = File(project.buildDir, "TestResults.txt")
281+
280282
val instrumentationTasks: List<Task> = combineAll(appVersions, variant.outputs)
281283
{ deviceAndMap, testApk -> Test(deviceAndMap.device, deviceAndMap.apk, testApk) }
282284
.map { test ->
@@ -286,8 +288,6 @@ class FirebaseTestLabPlugin : Plugin<Project> {
286288
val taskName = "$runTestsTaskInstrumentation$devicePart$apkPart$testApkPart"
287289
val numShards = test.device.numShards
288290

289-
val file = File(project.buildDir, "TestResults.txt")
290-
291291
if (numShards > 0) {
292292
project.tasks.create(taskName, InstrumentationShardingTask::class.java) {
293293
group = Constants.FIREBASE_TEST_LAB
@@ -300,17 +300,32 @@ class FirebaseTestLabPlugin : Plugin<Project> {
300300
apk = test.apk.outputFile,
301301
testType = TestType.Instrumentation(test.testApk.outputFile)
302302
)
303-
this.stateFile = file
303+
this.stateFile = testResultFile
304304

305305
if (downloader != null) {
306306
mustRunAfter(cleanTask)
307307
}
308308
dependsOn(taskSetup)
309309
dependsOn(arrayOf(test.apk.assemble, test.testApk.assemble))
310+
311+
doFirst {
312+
testResultFile.writeText("")
313+
}
310314

311315
doLast {
312-
val resultCode = file.readText().toInt()
313-
processResult(resultCode, ignoreFailures)
316+
val testResults = testResultFile.readText()
317+
val resultCode: Int? = testResults.toIntOrNull()
318+
319+
logger.lifecycle("TESTS RESULTS: Every digit represents single shard.")
320+
logger.lifecycle("\"0\" means -> tests for particular shard passed.")
321+
logger.lifecycle("\"1\" means -> tests for particular shard failed.")
322+
323+
logger.lifecycle("RESULTS_CODE: $resultCode")
324+
logger.lifecycle("When result code is equal to 0 means that all tests for all shards passed, otherwise some of them failed.")
325+
326+
if (resultCode != null) {
327+
processResult(resultCode, ignoreFailures)
328+
}
314329
}
315330
}
316331

@@ -419,6 +434,7 @@ class FirebaseTestLabPlugin : Plugin<Project> {
419434
project.logger.lifecycle("SUCCESS: All tests passed.")
420435
} else {
421436
if (ignoreFailures) {
437+
println("FAILURE: Tests failed.")
422438
project.logger.error("FAILURE: Tests failed.")
423439
} else {
424440
throw GradleException("FAILURE: Tests failed.")

plugin/src/main/java/com/appunite/firebasetestlabplugin/cloud/FirebaseTestLabProcessCreator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object FirebaseTestLabProcessCreator {
5656
"firebase", "test", "android", "run",
5757
"--format=json",
5858
"--device-ids=${device.deviceIds.joinArgs()}",
59-
"--app=$processData.apk",
59+
"--app=${processData.apk}",
6060
"--locales=${device.locales.joinArgs()}",
6161
"--os-version-ids=${device.androidApiLevels.joinArgs()}",
6262
"--orientations=${device.screenOrientations.map { orientation -> orientation.gcloudName }.joinArgs()}")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.appunite.firebasetestlabplugin.tasks
2+
3+
import org.gradle.api.GradleException
4+
import java.io.File
5+
import javax.inject.Inject
6+
7+
class TestProcess @Inject constructor(
8+
private val stateFile: File,
9+
private val value: Int
10+
) : Runnable {
11+
override fun run() {
12+
try {
13+
stateFile.appendText(text = "0")
14+
} catch (e: Exception){
15+
throw GradleException("There was a problem with processing ${e.message} $value")
16+
}
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.appunite.firebasetestlabplugin.tasks
2+
3+
import org.gradle.api.Action
4+
import org.gradle.api.DefaultTask
5+
import org.gradle.api.tasks.TaskAction
6+
import org.gradle.workers.WorkerConfiguration
7+
import org.gradle.workers.WorkerExecutor
8+
import java.io.File
9+
import javax.inject.Inject
10+
11+
open class TestTask @Inject constructor(private val workerExecutor: WorkerExecutor) : DefaultTask() {
12+
lateinit var stateFile: File
13+
14+
@TaskAction
15+
fun runAction() {
16+
(0 until 4).map { shardIndex ->
17+
workerExecutor.submit(TestProcess::class.java, object : Action<WorkerConfiguration> {
18+
override fun execute(config: WorkerConfiguration) {
19+
config.params(stateFile, shardIndex)
20+
}
21+
})
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)