Skip to content

Commit 262323a

Browse files
authored
Add a method to fetch test issues from FTL (#74)
* Add a method to fetch test issues from FTL * Add doc * Addressing feedback
1 parent df4b13e commit 262323a

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ interface TestRunnerService {
124124
gcsPath: GcsPath
125125
): ResultFileResource?
126126

127+
/**
128+
* Gets the testIssues encountered while running [testMatrix] in FTL.
129+
* If no severe issues were observed, returns an emptyList.
130+
*/
131+
suspend fun getTestMatrixTestIssues(
132+
testMatrix: TestMatrix
133+
): List<TestIssue>
134+
127135
companion object {
128136
/**
129137
* Creates an implementation of [TestRunnerService].
@@ -345,4 +353,22 @@ interface TestRunnerService {
345353
const val TEXTPROTO = "textproto"
346354
}
347355
}
356+
357+
/**
358+
* Represents the issue detected while running tests in a testMatrix in FTL
359+
*/
360+
data class TestIssue(
361+
/**
362+
* Error message describing the issue
363+
*/
364+
val errorMessage: String,
365+
/**
366+
* Severity of issue
367+
*/
368+
val severity: String?,
369+
/**
370+
* Type of issue
371+
*/
372+
val type: String?
373+
)
348374
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import dev.androidx.ci.generated.ftl.ClientInfo
2626
import dev.androidx.ci.generated.ftl.ShardingOption
2727
import dev.androidx.ci.generated.ftl.TestEnvironmentCatalog
2828
import dev.androidx.ci.generated.ftl.TestMatrix
29+
import dev.androidx.ci.generated.testResults.TestIssue
2930
import dev.androidx.ci.testRunner.vo.DeviceSetup
3031
import dev.androidx.ci.testRunner.vo.RemoteApk
3132
import dev.androidx.ci.testRunner.vo.UploadedApk
@@ -280,6 +281,21 @@ internal class TestRunnerServiceImpl internal constructor(
280281
}
281282
}
282283

284+
override suspend fun getTestMatrixTestIssues(testMatrix: TestMatrix): List<TestRunnerService.TestIssue> {
285+
val steps = testExecutionStore.getTestExecutionSteps(testMatrix)
286+
val testIssues = steps.flatMap {
287+
it.testExecutionStep?.testIssues ?: emptyList()
288+
}.map {
289+
TestRunnerService.TestIssue(
290+
errorMessage = it.errorMessage ?: "error message not set",
291+
severity = it.severity?.name ?: "unspecifiedSeverity",
292+
type = it.type?.name
293+
)
294+
}
295+
296+
return testIssues
297+
}
298+
283299
suspend fun getTestMatrixResults(
284300
testMatrixId: String
285301
): List<TestRunnerService.TestRunResult>? {

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import dev.androidx.ci.generated.testResults.FileReference
1919
import dev.androidx.ci.generated.testResults.Step
2020
import dev.androidx.ci.generated.testResults.TestCaseReference
2121
import dev.androidx.ci.generated.testResults.TestExecutionStep
22+
import dev.androidx.ci.generated.testResults.TestIssue
2223
import dev.androidx.ci.generated.testResults.ToolExecution
2324
import dev.androidx.ci.generated.testResults.ToolOutputReference
2425
import dev.androidx.ci.testRunner.vo.DeviceSetup
@@ -1410,6 +1411,58 @@ class TestRunnerServiceImplTest {
14101411
)
14111412
}
14121413

1414+
@Test
1415+
fun getTestIssues() = runBlocking {
1416+
val testMatrix = fakeBackend.fakeFirebaseTestLabApi.createTestMatrix(
1417+
projectId = fakeBackend.firebaseProjectId,
1418+
requestId = "requestId",
1419+
testMatrix = TestMatrix(
1420+
resultStorage = ResultStorage(
1421+
googleCloudStorage = GoogleCloudStorage(
1422+
"${fakeBackend.fakeGoogleCloudApi.rootGcsPath}/my-test-matrix-results"
1423+
),
1424+
toolResultsExecution = ToolResultsExecution(
1425+
executionId = "test_executionId",
1426+
historyId = "test_historyId"
1427+
)
1428+
),
1429+
projectId = fakeBackend.firebaseProjectId,
1430+
environmentMatrix = EnvironmentMatrix(),
1431+
testSpecification = TestSpecification()
1432+
)
1433+
)
1434+
assertThat(
1435+
subject.getTestMatrixTestIssues(testMatrix)
1436+
).isEmpty()
1437+
1438+
fakeToolsResultApi.addStep(
1439+
projectId = fakeBackend.firebaseProjectId,
1440+
executionId = "test_executionId",
1441+
historyId = "test_historyId",
1442+
step = Step(
1443+
stepId = UUID.randomUUID().toString(),
1444+
testExecutionStep = TestExecutionStep(
1445+
testIssues = listOf(
1446+
TestIssue(
1447+
errorMessage = "test module error",
1448+
severity = TestIssue.Severity.severe
1449+
)
1450+
)
1451+
)
1452+
)
1453+
)
1454+
val testIssues = subject.getTestMatrixTestIssues(testMatrix)
1455+
assertThat(
1456+
testIssues
1457+
).isNotEmpty()
1458+
1459+
assertThat(
1460+
testIssues.first().errorMessage
1461+
).isEqualTo(
1462+
"test module error"
1463+
)
1464+
}
1465+
14131466
private fun TestRunnerService.ResultFileResource.readFully() = openInputStream().use {
14141467
it.readAllBytes()
14151468
}

0 commit comments

Comments
 (0)