Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-goral committed Mar 24, 2020
1 parent ed61aac commit 3d5e8bf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ private fun Step.testSuiteName(): String {
return listOf(map["Model"], map["Version"], map["Locale"], map["Orientation"]).joinToString("-")
}

private fun List<JUnitTestCase>.sumTime() = this
private fun List<JUnitTestCase>.sumTime(): Double = this
.map { it.time?.toDouble() ?: 0.0 }
.reduce { acc, d -> acc + d }
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.reports.api

import com.google.api.services.testing.model.TestExecution
import com.google.api.services.testing.model.ToolResultsStep
import com.google.api.services.toolresults.model.ListTestCasesResponse
import com.google.api.services.toolresults.model.Step
import com.google.api.services.toolresults.model.Timestamp
Expand All @@ -9,6 +10,7 @@ import ftl.reports.api.data.TestExecutionData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.runBlocking

internal fun List<TestExecution>.createTestExecutionDataListAsync(): List<TestExecutionData> = runBlocking {
Expand All @@ -21,17 +23,26 @@ internal fun List<TestExecution>.createTestExecutionDataListAsync(): List<TestEx
}.awaitAll()
}

private fun TestExecution.createTestExecutionData(): TestExecutionData {
val response: ListTestCasesResponse = GcToolResults.listTestCases(toolResultsStep)
val step: Step = GcToolResults.getStepResult(toolResultsStep)
private suspend fun TestExecution.createTestExecutionData(): TestExecutionData {
val (
response: ListTestCasesResponse,
step: Step
) = getAsync(toolResultsStep)

return TestExecutionData(
testExecution = this,
testExecution = this@createTestExecutionData,
testCases = response.testCases,
step = step,
timestamp = response.getStartTimestamp()
)
}

private suspend fun getAsync(toolResultsStep: ToolResultsStep) = coroutineScope {
val response = async { GcToolResults.listTestCases(toolResultsStep) }
val step = async { GcToolResults.getStepResult(toolResultsStep) }
response.await() to step.await()
}

// Unfortunately is not possible to obtain from api exact the same timestamp as is in autogenerated test_result_1.xml from google cloud.
// This one is a little bit lower but close as possible. The difference is around ~3 seconds.
private fun ListTestCasesResponse.getStartTimestamp(): Timestamp = testCases.minBy { testCase ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ private fun TestExecutionData.reduceTestCases() = copy(
testCases.sortedBy { testCase: TestCase ->
testCase.startTime.asUnixTimestamp()
}.run {
firstOrNull { it.stackTraces != null } ?: first()
}.apply {
flaky = testCases.isFlaky()
if (!isFlaky()) first()
else first { it.stackTraces != null }.apply { flaky = true }
}
}
)
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/reports/api/ProcessFromApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fun processXmlFromApi(
.getTestExecutions()
.createJUnitTestResult()

internal fun refreshTestMatrices(
private fun refreshTestMatrices(
matrixIds: List<String>,
projectId: String
): List<TestMatrix> = runBlocking {
Expand All @@ -35,6 +35,6 @@ internal fun refreshTestMatrices(
}.awaitAll()
}

internal fun List<TestMatrix>.getTestExecutions(): List<TestExecution> = this
private fun List<TestMatrix>.getTestExecutions(): List<TestExecution> = this
.map(TestMatrix::getTestExecutions)
.flatten()
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/reports/xml/JUnitXml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private val xmlMapper = XmlMapper(xmlModule)
internal val xmlPrettyWriter = xmlMapper.writerWithDefaultPrettyPrinter()

private fun xmlBytes(path: Path): ByteArray {
if (!path.toFile().exists()) RuntimeException("$path doesn't exist!")
if (!path.toFile().exists()) throw RuntimeException("$path doesn't exist!")
return Files.readAllBytes(path)
}

Expand Down

0 comments on commit 3d5e8bf

Please sign in to comment.