Skip to content

Commit

Permalink
Updated TestRerunInteractor to run in parallel (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
LachlanMcKee authored Oct 18, 2020
1 parent f7cccfb commit 9f46d95
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package net.lachlanmckee.bitrise.runner.domain.interactor

import kotlinx.coroutines.Deferred
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import net.lachlanmckee.bitrise.core.awaitGetOrThrow
import net.lachlanmckee.bitrise.core.data.datasource.remote.BitriseDataSource
import net.lachlanmckee.bitrise.core.data.entity.TestCase
import net.lachlanmckee.bitrise.core.data.entity.TestSuite
Expand All @@ -10,18 +14,29 @@ class TestRerunInteractor @Inject constructor(
private val bitriseDataSource: BitriseDataSource
) {
suspend fun execute(buildSlug: String): Result<RerunModel> = kotlin.runCatching {
val buildDetails = bitriseDataSource.getBuildDetails(buildSlug)
.getOrThrow()
val branchName = getBranchNameAsync(buildSlug)
val failedTests = getFailedTestsAsync(buildSlug)

bitriseDataSource
.getTestResults(buildSlug)
.map { testSuite ->
RerunModel(
branch = buildDetails.branch,
failedTests = getFailedTestClassNames(testSuite)
)
}
.getOrThrow()
RerunModel(
branch = branchName.awaitGetOrThrow(),
failedTests = failedTests.awaitGetOrThrow()
)
}

private fun getBranchNameAsync(buildSlug: String): Deferred<Result<String>> {
return GlobalScope.async {
bitriseDataSource
.getBuildDetails(buildSlug)
.map { it.branch }
}
}

private fun getFailedTestsAsync(buildSlug: String): Deferred<Result<List<String>>> {
return GlobalScope.async {
bitriseDataSource
.getTestResults(buildSlug)
.mapCatching(::getFailedTestClassNames)
}
}

private fun getFailedTestClassNames(testSuiteList: List<TestSuite>): List<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ internal class TestRerunInteractorTest {

assertEquals(exception, result.exceptionOrNull())

coVerifySequence {
coVerify {
bitriseDataSource.getBuildDetails("buildSlug")
bitriseDataSource.getTestResults("buildSlug")
}
}

Expand All @@ -47,7 +48,7 @@ internal class TestRerunInteractorTest {

assertEquals(exception, result.exceptionOrNull())

coVerifySequence {
coVerify {
bitriseDataSource.getBuildDetails("buildSlug")
bitriseDataSource.getTestResults("buildSlug")
}
Expand Down Expand Up @@ -119,7 +120,7 @@ internal class TestRerunInteractorTest {
result.getOrNull()
)

coVerifySequence {
coVerify {
bitriseDataSource.getBuildDetails("buildSlug")
bitriseDataSource.getTestResults("buildSlug")
}
Expand Down

0 comments on commit 9f46d95

Please sign in to comment.