From ffe7768acb72c94a776f26ad345f6c561a1d1386 Mon Sep 17 00:00:00 2001 From: Rd Date: Mon, 29 Jul 2024 03:46:08 +0530 Subject: [PATCH] Removed asynchronous flow in both source and test files for CoverageRunner --- .../android/scripts/coverage/CoverageRunner.kt | 6 ++---- .../oppia/android/scripts/coverage/RunCoverage.kt | 8 +++----- .../android/scripts/coverage/CoverageRunnerTest.kt | 14 ++++---------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt b/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt index b27cb822dbb..dac2ee1709b 100644 --- a/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt +++ b/scripts/src/java/org/oppia/android/scripts/coverage/CoverageRunner.kt @@ -36,13 +36,11 @@ class CoverageRunner( */ fun runWithCoverageAsync( bazelTestTarget: String - ): Deferred { - 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( diff --git a/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt b/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt index 70a978452cb..a0a88dd74f7 100644 --- a/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt +++ b/scripts/src/java/org/oppia/android/scripts/coverage/RunCoverage.kt @@ -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 } @@ -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() @@ -146,7 +144,7 @@ class RunCoverage( } } - private fun runCoverageForTarget(testTarget: String): Deferred { + private fun runCoverageForTarget(testTarget: String): CoverageReport { return CoverageRunner(rootDirectory, scriptBgDispatcher, commandExecutor) .runWithCoverageAsync(testTarget.removeSuffix(".kt")) } diff --git a/scripts/src/javatests/org/oppia/android/scripts/coverage/CoverageRunnerTest.kt b/scripts/src/javatests/org/oppia/android/scripts/coverage/CoverageRunnerTest.kt index 371026d23b7..df123786d56 100644 --- a/scripts/src/javatests/org/oppia/android/scripts/coverage/CoverageRunnerTest.kt +++ b/scripts/src/javatests/org/oppia/android/scripts/coverage/CoverageRunnerTest.kt @@ -84,9 +84,7 @@ class CoverageRunnerTest { @Test fun testRunWithCoverageAsync_emptyDirectory_throwsException() { val exception = assertThrows() { - runBlocking { - coverageRunner.runWithCoverageAsync(bazelTestTarget).await() - } + coverageRunner.runWithCoverageAsync(bazelTestTarget) } assertThat(exception).hasMessageThat().contains("not invoked from within a workspace") @@ -97,9 +95,7 @@ class CoverageRunnerTest { testBazelWorkspace.initEmptyWorkspace() val exception = assertThrows() { - runBlocking { - coverageRunner.runWithCoverageAsync(bazelTestTarget).await() - } + coverageRunner.runWithCoverageAsync(bazelTestTarget) } assertThat(exception).hasMessageThat().contains("Expected non-zero exit code") @@ -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")