Skip to content

Commit

Permalink
fix: JUnitReport.xml only contained 50 test results (#1649)
Browse files Browse the repository at this point in the history
Fixes #1634

## Test Plan
> How do we know the code works?

Existing tests should not be broken

## Checklist

- [x] Documented
- [x] Unit tested
- [x] Integration tests updated
  • Loading branch information
dmytrodanylyk authored Mar 2, 2021
1 parent bb1741d commit 7880e59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
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(
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()
}
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

0 comments on commit 7880e59

Please sign in to comment.