-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Savedmatrix immutability change (#1028)
* Saved matrix refactor 1.0 * Saved matrix bug fixes 1.0 * Recursion error fix * Fixed failing tests * Fixed github flows failing tests * Further fixes besed on pullrequest comments, Outcomedetails nullability change * Further fixes besed on pullrequest comments * More code review comments * Remove vars from updatedSavedMatrix (#1037) Co-authored-by: Jan Góral <60390247+jan-gogo@users.noreply.github.com>
- v23.10.1
- v23.10.0
- v23.07.0
- v23.06.2
- v23.06.1
- v23.06.0
- v23.04.0
- v23.03.2
- v23.03.1
- v23.03.0
- v23.01.0
- v22.10.0
- v22.05.0
- v22.04.0
- v22.03.0
- v21.11.0
- v21.09.0
- v21.08.1
- v21.08.0
- v21.07.2
- v21.07.1
- v21.07.0
- v21.06.1
- v21.06.0
- v21.05.0
- v21.04.1
- v21.04.0
- v21.03.1
- v21.03.0
- v21.02.0
- v21.01.1
- v21.01.0
- v20.12.0
- v20.09.3
- v20.09.2
- v20.09.1
- v20.09.0
- v20.08.4
- github-action-1.0
- flank-wrapper-1.2.5
- flank-wrapper-1.2.4
- flank-wrapper-1.2.3
- flank-wrapper-1.2.2
- flank-wrapper-1.2.1
- flank-wrapper-1.2.0
- flank-wrapper-1.1.0
- flank-scripts-test
- flank-scripts-1.9.28
- flank-scripts-1.9.27
- flank-scripts-1.9.26
- flank-scripts-1.9.25
- flank-scripts-1.9.24
- flank-scripts-1.9.23
- flank-scripts-1.9.22
- flank-scripts-1.9.21
- flank-scripts-1.9.20
- flank-scripts-1.9.19
- flank-scripts-1.9.18
- flank-scripts-1.9.17
- flank-scripts-1.9.16
- flank-scripts-1.9.15
- flank-scripts-1.9.14
- flank-scripts-1.9.13
- flank-scripts-1.9.12
- flank-scripts-1.9.11
- flank-scripts-1.9.10
- flank-scripts-1.9.9
- flank-scripts-1.9.8
- flank-scripts-1.9.7
- flank-scripts-1.9.6
- flank-scripts-1.9.5
- flank-scripts-1.9.3
- flank-scripts-1.9.2
- flank-scripts-1.9.1
- flank-scripts-1.9.0
- flank-scripts-1.8.0
- flank-scripts-1.7.3
- flank-scripts-1.7.2
- flank-scripts-1.7.1
- flank-scripts-1.7.0
- flank-scripts-1.6.7
- flank-scripts-1.6.6
- flank-scripts-1.6.4
- flank-scripts-1.6.3
- flank-github-action
- flank_snapshot
- V1.5-action
- V1.4-action
- V1.3-action
- V1.2-action
- V1.1-action
- V1.0-action
Showing
15 changed files
with
158 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,107 @@ | ||
package ftl.json | ||
|
||
import com.google.api.services.testing.model.TestMatrix | ||
import ftl.reports.outcome.BillableMinutes | ||
import ftl.reports.outcome.TestOutcome | ||
import ftl.reports.outcome.createMatrixOutcomeSummary | ||
import ftl.reports.outcome.fetchTestOutcomeContext | ||
import ftl.util.FlankGeneralError | ||
import ftl.util.MatrixState.FINISHED | ||
import ftl.util.MatrixState.INVALID | ||
import ftl.util.StepOutcome.failure | ||
import ftl.util.StepOutcome.inconclusive | ||
import ftl.util.StepOutcome.skipped | ||
import ftl.util.StepOutcome.success | ||
import ftl.util.getClientDetails | ||
import ftl.util.getGcsPath | ||
import ftl.util.getGcsPathWithoutRootBucket | ||
import ftl.util.getGcsRootBucket | ||
import ftl.util.webLink | ||
import ftl.util.webLinkWithoutExecutionDetails | ||
|
||
// execution gcs paths aren't API accessible. | ||
class SavedMatrix(matrix: TestMatrix) { | ||
val matrixId: String = matrix.testMatrixId | ||
var state: String = matrix.state | ||
private set | ||
val gcsPath: String = matrix.resultStorage.googleCloudStorage.gcsPath | ||
var webLink: String = matrix.webLink() | ||
private set | ||
var downloaded = false | ||
|
||
var billableVirtualMinutes: Long = 0 | ||
private set | ||
var billablePhysicalMinutes: Long = 0 | ||
private set | ||
var outcome: String = "" | ||
private set | ||
var outcomeDetails: String = "" | ||
private set | ||
val clientDetails = matrix.clientInfo?.clientInfoDetails | ||
?.map { it.key to it.value } | ||
?.toMap() | ||
|
||
init { | ||
if (this.state == FINISHED) finished(matrix) | ||
} | ||
|
||
// ExitCodeFromRollupOutcome - https://github.com/bootstraponline/gcloud_cli/blob/137d864acd5928baf25434cf59b0225c4d1f9319/google-cloud-sdk/lib/googlecloudsdk/api_lib/firebase/test/exit_code.py#L46 | ||
fun failed(): Boolean { | ||
// outcome of the test execution. | ||
// skipped means unsupported environment | ||
return when (outcome) { | ||
failure -> true | ||
skipped -> true | ||
inconclusive -> true | ||
else -> false | ||
} | ||
} | ||
data class SavedMatrix( | ||
val matrixId: String = "", | ||
val state: String = "", | ||
val gcsPath: String = "", | ||
val webLink: String = "", | ||
val downloaded: Boolean = false, | ||
val billableVirtualMinutes: Long = 0, | ||
val billablePhysicalMinutes: Long = 0, | ||
val outcome: String = "", | ||
val outcomeDetails: String = "", | ||
val clientDetails: Map<String, String>? = null, | ||
val gcsPathWithoutRootBucket: String = "", | ||
val gcsRootBucket: String = "", | ||
val webLinkWithoutExecutionDetails: String? = "", | ||
) | ||
|
||
fun createSavedMatrix(testMatrix: TestMatrix) = SavedMatrix().updateWithMatrix(testMatrix) | ||
|
||
/** return true if the content changed **/ | ||
fun update(matrix: TestMatrix): Boolean { | ||
val newState = matrix.state | ||
val newLink = matrix.webLink() | ||
val changedState = state != newState | ||
val changedLink = webLink != newLink | ||
fun SavedMatrix.canceledByUser() = outcomeDetails == ABORTED_BY_USER_MESSAGE | ||
|
||
if (changedState) { | ||
updateState(newState, matrix) | ||
} | ||
fun SavedMatrix.infrastructureFail() = outcomeDetails == INFRASTRUCTURE_FAILURE_MESSAGE | ||
|
||
if (changedLink) { | ||
this.webLink = newLink | ||
} | ||
fun SavedMatrix.incompatibleFail() = outcomeDetails in arrayOf( | ||
INCOMPATIBLE_APP_VERSION_MESSAGE, | ||
INCOMPATIBLE_ARCHITECTURE_MESSAGE, | ||
INCOMPATIBLE_DEVICE_MESSAGE | ||
) | ||
|
||
fun SavedMatrix.isFailed() = when (outcome) { | ||
failure -> true | ||
skipped -> true | ||
inconclusive -> true | ||
else -> false | ||
} | ||
|
||
return changedState || changedLink | ||
} | ||
fun SavedMatrix.needsUpdate(newMatrix: TestMatrix): Boolean { | ||
val newState = newMatrix.state | ||
val newLink = newMatrix.webLink() | ||
val changedState = state != newState | ||
val changedLink = webLink != newLink | ||
return (changedState || changedLink) | ||
} | ||
|
||
private fun updateState(newState: String, testMatrix: TestMatrix) { | ||
state = newState | ||
when (state) { | ||
FINISHED -> finished(testMatrix) | ||
INVALID -> { | ||
outcomeDetails = "Matrix is invalid" | ||
outcome = "---" | ||
} | ||
} | ||
} | ||
internal fun SavedMatrix.updateWithMatrix(newMatrix: TestMatrix): SavedMatrix = | ||
if (needsUpdate(newMatrix)) updatedSavedMatrix(newMatrix) | ||
else this | ||
|
||
private fun finished(matrix: TestMatrix) { | ||
if (matrix.state != FINISHED) { | ||
throw FlankGeneralError("Matrix ${matrix.testMatrixId} ${matrix.state} != $FINISHED") | ||
} | ||
billableVirtualMinutes = 0 | ||
billablePhysicalMinutes = 0 | ||
outcome = success | ||
private fun SavedMatrix.updatedSavedMatrix( | ||
newMatrix: TestMatrix | ||
): SavedMatrix = when (newMatrix.state) { | ||
state -> this | ||
|
||
updateFinishedMatrixData(matrix) | ||
FINISHED -> newMatrix.fetchTestOutcomeContext().createMatrixOutcomeSummary().let { (billableMinutes, outcome) -> | ||
updateProperties(newMatrix).updateOutcome(outcome).updateBillableMinutes(billableMinutes) | ||
} | ||
|
||
private fun updateFinishedMatrixData(matrix: TestMatrix) { | ||
matrix.fetchTestOutcomeContext().createMatrixOutcomeSummary().let { (billableMinutes, summary) -> | ||
outcome = summary.outcome | ||
outcomeDetails = summary.testDetails | ||
billableVirtualMinutes = billableMinutes.virtual | ||
billablePhysicalMinutes = billableMinutes.physical | ||
} | ||
} | ||
INVALID -> updateProperties(newMatrix).updateOutcome(invalidTestOutcome()) | ||
|
||
val gcsPathWithoutRootBucket get() = gcsPath.substringAfter('/') | ||
val gcsRootBucket get() = gcsPath.substringBefore('/') | ||
val webLinkWithoutExecutionDetails: String | ||
get() { | ||
return if (webLink.isEmpty()) { | ||
webLink | ||
} else { | ||
val executionsRegex = "/executions/.+".toRegex() | ||
val foundValue = executionsRegex.find(webLink)?.value.orEmpty() | ||
webLink.removeSuffix(foundValue) | ||
} | ||
} | ||
else -> updateProperties(newMatrix) | ||
} | ||
|
||
fun SavedMatrix.canceledByUser() = outcomeDetails == ABORTED_BY_USER_MESSAGE | ||
|
||
fun SavedMatrix.infrastructureFail() = outcomeDetails == INFRASTRUCTURE_FAILURE_MESSAGE | ||
|
||
fun SavedMatrix.incompatibleFail() = outcomeDetails in arrayOf(INCOMPATIBLE_APP_VERSION_MESSAGE, INCOMPATIBLE_ARCHITECTURE_MESSAGE, INCOMPATIBLE_DEVICE_MESSAGE) | ||
private fun SavedMatrix.updateProperties(newMatrix: TestMatrix) = copy( | ||
matrixId = newMatrix.testMatrixId, | ||
state = newMatrix.state, | ||
gcsPath = newMatrix.getGcsPath(), | ||
webLink = newMatrix.webLink(), | ||
downloaded = false, | ||
clientDetails = newMatrix.getClientDetails(), | ||
gcsPathWithoutRootBucket = newMatrix.getGcsPathWithoutRootBucket(), | ||
gcsRootBucket = newMatrix.getGcsRootBucket(), | ||
webLinkWithoutExecutionDetails = newMatrix.webLinkWithoutExecutionDetails() | ||
) | ||
|
||
private fun SavedMatrix.updateBillableMinutes(billableMinutes: BillableMinutes) = copy( | ||
billablePhysicalMinutes = billableMinutes.physical, | ||
billableVirtualMinutes = billableMinutes.virtual, | ||
) | ||
|
||
private fun SavedMatrix.updateOutcome(testOutcome: TestOutcome) = copy( | ||
outcome = testOutcome.outcome, | ||
outcomeDetails = testOutcome.testDetails | ||
) | ||
|
||
private fun invalidTestOutcome() = TestOutcome( | ||
outcome = "---", | ||
testDetails = "Matrix is invalid" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters