Skip to content

Commit

Permalink
Adding a method to schedule retry tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rnakade committed Aug 23, 2023
1 parent 719bf34 commit 5b7824c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ internal class FirebaseTestLabController(
}
}

/**
* Enqueues a request to create a [TestMatrix] to retry failed Tests
* specified in the [testTargets] list for the given [testMatrix]
*/
suspend fun submitRetryTests(
testMatrix: TestMatrix,
testTargets: List<String>? = null
): TestMatrix {
return testMatrixStore.createRetryTestMatrix(
testMatrix = testMatrix,
testTargets = testTargets
)
}

suspend fun collectTestResultsByTestMatrixIds(
testMatrixIds: List<String>,
pollIntervalMs: Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,44 @@ internal class TestMatrixStore(
return newTestMatrix
}

/**
* Creates a [TestMatrix] to run the failed tests specified in [testTargets] list
* using the configuration for [testMatrix]
*/
suspend fun createRetryTestMatrix(
testMatrix: TestMatrix,
testTargets: List<String>? = null
): TestMatrix {
logger.trace {
"test matrix id: ${testMatrix.testMatrixId}"
}

val testSpecification = testMatrix.testSpecification.copy(
androidInstrumentationTest = testMatrix.testSpecification.androidInstrumentationTest?.copy(
testTargets = testTargets
)
)
val newTestMatrix = firebaseTestLabApi.createTestMatrix(
projectId = firebaseProjectId,
requestId = UUID.randomUUID().toString(),
testMatrix = TestMatrix(
projectId = firebaseProjectId,
flakyTestAttempts = 0,
testSpecification = testSpecification,
clientInfo = testMatrix.clientInfo,
environmentMatrix = testMatrix.environmentMatrix,
resultStorage = ResultStorage(
googleCloudStorage = testMatrix.resultStorage.googleCloudStorage,
toolResultsHistory = testMatrix.resultStorage.toolResultsHistory
)
)
)
logger.info {
"created test matrix: $newTestMatrix"
}
return newTestMatrix
}

/**
* Returns an existing TestMatrix for the given [testRunId].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ interface TestRunnerService {
flakyTestAttempts: Int? = 2
): ScheduleTestsResponse

/**
* Schedules a task to create a [TestMatrix] to retry failed Tests
* specified in the [testTargets] list for the given [testMatrix]
*/
suspend fun scheduleRetryTests(
testMatrix: TestMatrix,
testTargets: List<String>? = null
): TestMatrix

/**
* Queries the Firebase for the given [testMatrixId] and returns it if it exists.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ internal class TestRunnerServiceImpl internal constructor(
)
}

override suspend fun scheduleRetryTests(
testMatrix: TestMatrix,
testTargets: List<String>?
): TestMatrix {
return testLabController.submitRetryTests(
testMatrix = testMatrix,
testTargets = testTargets
)
}

override suspend fun getTestMatrix(
testMatrixId: String
): TestMatrix? {
Expand Down

0 comments on commit 5b7824c

Please sign in to comment.