Skip to content

Commit 71fd27c

Browse files
authored
Don't re-use bad test matrices (#60)
* Don't re-use bad test matrices This CL changes the TestMatrix re-use logic to skip test matrices which failed for an infra or bad configuration error. Both of these error types have the possibility of being intermediate so it is best not to re-use them and instead try running them again. Test: TestMatrixStoreTest * rename test
1 parent 5944acd commit 71fd27c

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

AndroidXCI/lib/src/main/kotlin/dev/androidx/ci/testRunner/TestMatrixStore.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,16 @@ internal class TestMatrixStore(
8484
}
8585

8686
getExistingTestMatrix(testRunId)?.let {
87-
logger.info("found existing test matrix: ${it.testMatrixId}")
88-
return it
87+
logger.info("found existing test matrix: ${it.testMatrixId} with state: ${it.state}")
88+
val state = it.state
89+
// these states are ordered so anything above ERROR is not worth re-using
90+
if (state != null && state >= TestMatrix.State.ERROR) {
91+
logger.warn {
92+
"Skipping cache for ${it.testMatrixId} because its state is $state"
93+
}
94+
} else {
95+
return it
96+
}
8997
}
9098
logger.trace {
9199
"No test run history for $testRunId, creating a new one."

AndroidXCI/lib/src/test/kotlin/dev/androidx/ci/testRunner/TestMatrixStoreTest.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import dev.androidx.ci.generated.ftl.ClientInfoDetail
2828
import dev.androidx.ci.generated.ftl.EnvironmentMatrix
2929
import dev.androidx.ci.generated.ftl.FileReference
3030
import dev.androidx.ci.generated.ftl.ShardingOption
31+
import dev.androidx.ci.generated.ftl.TestMatrix
3132
import dev.androidx.ci.generated.ftl.UniformSharding
3233
import dev.androidx.ci.testRunner.vo.ApkInfo
3334
import dev.androidx.ci.testRunner.vo.DeviceSetup
@@ -220,6 +221,45 @@ internal class TestMatrixStoreTest {
220221
assertThat(reUploadedAfterDeletion.testMatrixId).isNotEqualTo(testMatrix.testMatrixId)
221222
}
222223

224+
@Test
225+
fun dontReuseTestMatricesWithInfraFailures() = runBlocking<Unit> {
226+
val appApk = createFakeApk("app.pak")
227+
val testApk = createFakeApk("test.apk")
228+
val extraApk = createFakeApk("extra.apk")
229+
val testMatrix = store.getOrCreateTestMatrix(
230+
appApk = appApk,
231+
testApk = testApk,
232+
environmentMatrix = envMatrix1,
233+
clientInfo = null,
234+
deviceSetup = null,
235+
sharding = null
236+
)
237+
val reload = store.getOrCreateTestMatrix(
238+
appApk = appApk,
239+
testApk = testApk,
240+
environmentMatrix = envMatrix1,
241+
clientInfo = null,
242+
deviceSetup = null,
243+
sharding = null
244+
)
245+
assertThat(testMatrix.testMatrixId).isEqualTo(reload.testMatrixId)
246+
// set it to failed.
247+
firebaseTestLabApi.setTestMatrix(
248+
testMatrix.copy(
249+
state = TestMatrix.State.ERROR
250+
)
251+
)
252+
val reloadAfterError = store.getOrCreateTestMatrix(
253+
appApk = appApk,
254+
testApk = testApk,
255+
environmentMatrix = envMatrix1,
256+
clientInfo = null,
257+
deviceSetup = null,
258+
sharding = null
259+
)
260+
assertThat(reloadAfterError.testMatrixId).isNotEqualTo(testMatrix.testMatrixId)
261+
}
262+
223263
@Test
224264
fun pullScreenshots() = runBlocking<Unit> {
225265
val appApk = createFakeApk("app.pak")

0 commit comments

Comments
 (0)