Skip to content
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

fix: JUnitReport.xml only contained 50 test results #1649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions test_runner/src/main/kotlin/ftl/gc/GcToolResults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.google.api.services.toolresults.model.ListEnvironmentsResponse
import com.google.api.services.toolresults.model.ListStepsResponse
import com.google.api.services.toolresults.model.ListTestCasesResponse
import com.google.api.services.toolresults.model.Step
import com.google.api.services.toolresults.model.TestCase
import com.google.testing.model.TestExecution
import com.google.testing.model.ToolResultsExecution
import com.google.testing.model.ToolResultsHistory
Expand Down Expand Up @@ -123,7 +124,10 @@ object GcToolResults {
.executeWithRetry()

// Lists Test Cases attached to a Step
fun listTestCases(toolResultsStep: ToolResultsStep): ListTestCasesResponse {
fun listTestCases(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we should update unit tests as well.

toolResultsStep: ToolResultsStep,
pageToken: String? = null
): ListTestCasesResponse {
return service
.projects()
.histories()
Expand All @@ -135,7 +139,19 @@ object GcToolResults {
toolResultsStep.historyId,
toolResultsStep.executionId,
toolResultsStep.stepId
).executeWithRetry()
)
.setPageToken(pageToken)
.executeWithRetry()
}

fun listAllTestCases(results: ToolResultsStep): List<TestCase> {
var response = listTestCases(results)
val testCases = response.testCases.toMutableList()
while (response.nextPageToken != null) {
response = listTestCases(results, response.nextPageToken)
testCases += response.testCases ?: emptyList()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we break the loop if an empty list found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, this code is just copy/paste from a similar code in this file (see listAllEnvironments, listAllSteps)

}
return testCases
}

fun getDefaultBucket(projectId: String, source: String? = null): String? = try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ftl.reports.api

import com.google.api.services.toolresults.model.ListTestCasesResponse
import com.google.api.services.toolresults.model.Step
import com.google.api.services.toolresults.model.TestCase
import com.google.api.services.toolresults.model.Timestamp
Expand All @@ -26,12 +25,10 @@ internal fun List<TestExecution>.createTestExecutionDataListAsync(): List<TestEx

private suspend fun TestExecution.createTestExecutionData(): TestExecutionData {
val (
response: ListTestCasesResponse,
testCases: List<TestCase>,
step: Step
) = getAsync(toolResultsStep)

val testCases = response.testCases ?: emptyList()

return TestExecutionData(
testExecution = this@createTestExecutionData,
testCases = testCases,
Expand All @@ -41,7 +38,7 @@ private suspend fun TestExecution.createTestExecutionData(): TestExecutionData {
}

private suspend fun getAsync(toolResultsStep: ToolResultsStep) = coroutineScope {
val response = async { GcToolResults.listTestCases(toolResultsStep) }
val response = async { GcToolResults.listAllTestCases(toolResultsStep) }
val step = async { GcToolResults.getStepResult(toolResultsStep) }
response.await() to step.await()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CreateTestExecutionDataKtTest {
fun `should not throw is ListTestCasesResponse testCases are null`() {
// given
every { GcToolResults.getStepResult(any()) } returns Step()
every { GcToolResults.listTestCases(any()) } returns ListTestCasesResponse()
every { GcToolResults.listAllTestCases(any()) } returns emptyList()

val testExecution = TestExecution().apply {
toolResultsStep = ToolResultsStep()
Expand Down