diff --git a/runner/src/main/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractor.kt b/runner/src/main/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractor.kt index 830b4f7..5d5c9be 100644 --- a/runner/src/main/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractor.kt +++ b/runner/src/main/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractor.kt @@ -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 @@ -10,18 +14,29 @@ class TestRerunInteractor @Inject constructor( private val bitriseDataSource: BitriseDataSource ) { suspend fun execute(buildSlug: String): Result = 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> { + return GlobalScope.async { + bitriseDataSource + .getBuildDetails(buildSlug) + .map { it.branch } + } + } + + private fun getFailedTestsAsync(buildSlug: String): Deferred>> { + return GlobalScope.async { + bitriseDataSource + .getTestResults(buildSlug) + .mapCatching(::getFailedTestClassNames) + } } private fun getFailedTestClassNames(testSuiteList: List): List { diff --git a/runner/src/test/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractorTest.kt b/runner/src/test/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractorTest.kt index d9c3163..a40deb7 100644 --- a/runner/src/test/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractorTest.kt +++ b/runner/src/test/kotlin/net/lachlanmckee/bitrise/runner/domain/interactor/TestRerunInteractorTest.kt @@ -28,8 +28,9 @@ internal class TestRerunInteractorTest { assertEquals(exception, result.exceptionOrNull()) - coVerifySequence { + coVerify { bitriseDataSource.getBuildDetails("buildSlug") + bitriseDataSource.getTestResults("buildSlug") } } @@ -47,7 +48,7 @@ internal class TestRerunInteractorTest { assertEquals(exception, result.exceptionOrNull()) - coVerifySequence { + coVerify { bitriseDataSource.getBuildDetails("buildSlug") bitriseDataSource.getTestResults("buildSlug") } @@ -119,7 +120,7 @@ internal class TestRerunInteractorTest { result.getOrNull() ) - coVerifySequence { + coVerify { bitriseDataSource.getBuildDetails("buildSlug") bitriseDataSource.getTestResults("buildSlug") }