Skip to content

Commit

Permalink
#829 Fixing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Adamczyk committed Jun 24, 2020
1 parent 252771d commit d60eb38
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions test_runner/src/main/kotlin/ftl/json/SavedMatrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ import ftl.util.StepOutcome.flaky
import ftl.util.StepOutcome.inconclusive
import ftl.util.StepOutcome.skipped
import ftl.util.StepOutcome.success
import ftl.util.StepOutcome.unset
import ftl.util.getDetails
import ftl.util.webLink

private data class FinishedTestMatrixData(
val stepOutcome: Outcome,
val isVirtualDevice: Boolean,
val testSuiteOverviewData: TestSuiteOverviewData?,
val billableMinutes: Long?
)

// execution gcs paths aren't API accessible.
class SavedMatrix(matrix: TestMatrix) {
val matrixId: String = matrix.testMatrixId
Expand Down Expand Up @@ -95,36 +89,45 @@ class SavedMatrix(matrix: TestMatrix) {

private fun updateFinishedMatrixData(matrix: TestMatrix) {
matrix.testExecutions.createTestExecutionDataListAsync()
.map {
FinishedTestMatrixData(
.forEach {
updatedFinishedInfo(
stepOutcome = GcToolResults.getExecutionResult(it.testExecution).outcome,
isVirtualDevice = AndroidCatalog.isVirtualDevice(it.testExecution.environment.androidDevice, matrix.projectId.orEmpty()),
isVirtualDevice = AndroidCatalog.isVirtualDevice(
it.testExecution.environment.androidDevice,
matrix.projectId.orEmpty()
),
testSuiteOverviewData = it.createTestSuitOverviewData(),
billableMinutes = it.step.testExecutionStep?.testTiming?.testProcessDuration?.seconds
?.let { testTimeSeconds -> Billing.billableMinutes(testTimeSeconds) }
)
}
.forEach { (stepOutcome, isVirtualDevice, testSuiteOverviewData, billableMinutes) ->
updateOutcome(stepOutcome)
updateOutcomeDetails(stepOutcome, testSuiteOverviewData)
billableMinutes?.let { updateBillableMinutes(it, isVirtualDevice) }
}
}

private fun updateOutcome(stepOutcome: Outcome) {
// the matrix outcome is failure if any step fails
// if the matrix outcome is already set to failure then we can ignore the other step outcomes.
// inconclusive is treated as a failure
if (outcome == failure || outcome == inconclusive) return

outcome = stepOutcome.summary
private fun updatedFinishedInfo(
stepOutcome: Outcome?,
isVirtualDevice: Boolean,
testSuiteOverviewData: TestSuiteOverviewData?,
billableMinutes: Long?
) {
updateOutcome(stepOutcome)
updateOutcomeDetails(stepOutcome, testSuiteOverviewData)
billableMinutes?.let { updateBillableMinutes(it, isVirtualDevice) }
}

// Treat flaky outcome as a success
if (outcome == flaky) outcome = success
private fun updateOutcome(stepOutcome: Outcome?) {
outcome = when {
stepOutcome == null -> unset
// the matrix outcome is failure if any step fails
// if the matrix outcome is already set to failure then we can ignore the other step outcomes.
// inconclusive is treated as a failure
outcome == failure || outcome == inconclusive -> return
stepOutcome.summary == flaky -> success
else -> stepOutcome.summary
}
}

private fun updateOutcomeDetails(stepOutcome: Outcome, testSuiteOverviewData: TestSuiteOverviewData?) {
outcomeDetails = stepOutcome.getDetails(testSuiteOverviewData) ?: "---"
private fun updateOutcomeDetails(stepOutcome: Outcome?, testSuiteOverviewData: TestSuiteOverviewData?) {
outcomeDetails = stepOutcome?.getDetails(testSuiteOverviewData) ?: "---"
}

private fun updateBillableMinutes(billableMinutes: Long, isVirtualDevice: Boolean) {
Expand Down

0 comments on commit d60eb38

Please sign in to comment.