Skip to content

Commit

Permalink
Disable caching test matrices for retries
Browse files Browse the repository at this point in the history
  • Loading branch information
rnakade committed Aug 14, 2023
1 parent 7386d66 commit 719bf34
Showing 1 changed file with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ internal class TestMatrixStore(
testTargets: List<String>? = null,
flakyTestAttempts: Int? = 2
): TestMatrix {

val testRunId = TestRun.createId(
datastoreApi = datastoreApi,
environment = environmentMatrix,
Expand All @@ -85,25 +84,28 @@ internal class TestMatrixStore(
logger.trace {
"test run id: $testRunId"
}

getExistingTestMatrix(testRunId)?.let {
logger.info("found existing test matrix: ${it.testMatrixId} with state: ${it.state}")
val state = it.state
// these states are ordered so anything above ERROR is not worth re-using
if (state != null && state >= TestMatrix.State.ERROR) {
logger.warn {
"Skipping cache for ${it.testMatrixId} because its state is $state"
}
} else if (!cachedTestMatrixFilter(it)) {
logger.info {
"Not re-using cached matrix due to filter"
// we don't want cached results when retrying failed tests,
// so ensure list of failed tests is not provided when scheduling the ftl run
if (testTargets == null) {
getExistingTestMatrix(testRunId)?.let {
logger.info("found existing test matrix: ${it.testMatrixId} with state: ${it.state}")
val state = it.state
// these states are ordered so anything above ERROR is not worth re-using
if (state != null && state >= TestMatrix.State.ERROR) {
logger.warn {
"Skipping cache for ${it.testMatrixId} because its state is $state"
}
} else if (!cachedTestMatrixFilter(it)) {
logger.info {
"Not re-using cached matrix due to filter"
}
} else {
return it
}
} else {
return it
}
}
logger.trace {
"No test run history for $testRunId or cached TestMatrix is rejected, creating a new one."
logger.trace {
"No test run history for $testRunId or cached TestMatrix is rejected, creating a new one."
}
}
val newTestMatrix = firebaseTestLabApi.createTestMatrix(
projectId = firebaseProjectId,
Expand All @@ -124,18 +126,21 @@ internal class TestMatrixStore(
logger.info {
"created test matrix: $newTestMatrix"
}
// save it to cache, we don't worry about races here much such that if another instance happens to be creating
// If testMatrix is not for a failure retry, save it to cache,
// we don't worry about races here much such that if another instance happens to be creating
// the exact same test, one of them will win but that is OK since they'll each use their own test matrices and
// followup calls will re-use the winner of this race.
val testRun = TestRun(
id = testRunId,
testMatrixId = checkNotNull(newTestMatrix.testMatrixId) {
"newly created test matrix should not have null id $newTestMatrix"
if (testTargets == null) {
val testRun = TestRun(
id = testRunId,
testMatrixId = checkNotNull(newTestMatrix.testMatrixId) {
"newly created test matrix should not have null id $newTestMatrix"
}
)
datastoreApi.put(testRun.toEntity())
logger.info {
"saved test matrix info: $testRun"
}
)
datastoreApi.put(testRun.toEntity())
logger.info {
"saved test matrix info: $testRun"
}
return newTestMatrix
}
Expand Down

0 comments on commit 719bf34

Please sign in to comment.