Skip to content

Commit

Permalink
Removed asynchronous flow in both source and test files for CoverageR…
Browse files Browse the repository at this point in the history
…unner
  • Loading branch information
Rd4dev committed Jul 28, 2024
1 parent c2eddfb commit ffe7768
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ class CoverageRunner(
*/
fun runWithCoverageAsync(
bazelTestTarget: String
): Deferred<CoverageReport> {
return CoroutineScope(scriptBgDispatcher).async {
): CoverageReport {
val coverageResult = retrieveCoverageResult(bazelTestTarget)
?: error("Failed to retrieve coverage result for $bazelTestTarget")

coverageDataFileLines(coverageResult, bazelTestTarget)
}
return coverageDataFileLines(coverageResult, bazelTestTarget)
}

private fun retrieveCoverageResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class RunCoverage(
* @return a list of lists containing coverage data for each requested test target, if
* the file is exempted from having a test file, an empty list is returned
*/
fun execute() = runBlocking {
fun execute() {
val testFileExemptionList = loadTestFileExemptionsProto(testFileExemptionTextProto)
.testFileExemptionList
.filter { it.testFileNotRequired }
Expand All @@ -122,12 +122,10 @@ class RunCoverage(

val testTargets = bazelClient.retrieveBazelTargets(testFilePaths)

val deferredCoverageReports = testTargets.map { testTarget ->
val coverageReports = testTargets.map { testTarget ->
runCoverageForTarget(testTarget)
}

val coverageReports = deferredCoverageReports.awaitAll()

val aggregatedCoverageReport = calculateAggregateCoverageReport(coverageReports)
val reporter = CoverageReporter(repoRoot, aggregatedCoverageReport, reportFormat)
val (computedCoverageRatio, reportText) = reporter.generateRichTextReport()
Expand All @@ -146,7 +144,7 @@ class RunCoverage(
}
}

private fun runCoverageForTarget(testTarget: String): Deferred<CoverageReport> {
private fun runCoverageForTarget(testTarget: String): CoverageReport {
return CoverageRunner(rootDirectory, scriptBgDispatcher, commandExecutor)
.runWithCoverageAsync(testTarget.removeSuffix(".kt"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ class CoverageRunnerTest {
@Test
fun testRunWithCoverageAsync_emptyDirectory_throwsException() {
val exception = assertThrows<IllegalStateException>() {
runBlocking {
coverageRunner.runWithCoverageAsync(bazelTestTarget).await()
}
coverageRunner.runWithCoverageAsync(bazelTestTarget)
}

assertThat(exception).hasMessageThat().contains("not invoked from within a workspace")
Expand All @@ -97,9 +95,7 @@ class CoverageRunnerTest {
testBazelWorkspace.initEmptyWorkspace()

val exception = assertThrows<IllegalStateException>() {
runBlocking {
coverageRunner.runWithCoverageAsync(bazelTestTarget).await()
}
coverageRunner.runWithCoverageAsync(bazelTestTarget)
}

assertThat(exception).hasMessageThat().contains("Expected non-zero exit code")
Expand Down Expand Up @@ -192,11 +188,9 @@ class CoverageRunnerTest {
testSubpackage = "coverage/test/java/com/example"
)

val result = runBlocking {
coverageRunner.runWithCoverageAsync(
val result = coverageRunner.runWithCoverageAsync(
"//coverage/test/java/com/example:AddNumsTest"
).await()
}
)

val expectedResult = CoverageReport.newBuilder()
.setBazelTestTarget("//coverage/test/java/com/example:AddNumsTest")
Expand Down

0 comments on commit ffe7768

Please sign in to comment.