Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoroutineScope.launch reported as partially covered #1353

Closed
joshfriend opened this issue Aug 16, 2022 · 1 comment
Closed

CoroutineScope.launch reported as partially covered #1353

joshfriend opened this issue Aug 16, 2022 · 1 comment

Comments

@joshfriend
Copy link

joshfriend commented Aug 16, 2022

Steps to reproduce

  • JaCoCo version: 0.8.8.202204050719
  • Operating system: macOS 12.5
  • Tool integration: Gradle
  • Kotlin version: 1.7.10
  • Complete executable reproducer: CoroutineLaunchPartialCoverage.zip

Steps: (what exactly are you doing with the above reproducer?)

  1. Run ./gradlew jacocoTestReportDebug in the provided sample, or just open the jacoco report that should already be included from when I ran it app/build/reports/jacoco/debug/com.example.coroutinelaunch/ExampleRepository.kt.html

Expected behaviour

ExampleRepository.kt should have 100% coverage.

Actual behaviour

The call to CoroutineScope.launch is marked partially covered, I believe from the theoretically possible case where the coroutine somehow doesn't get launched.

ExampleRepository.doSomething.new Function2() {...} invokeSuspend(Object) is what I see marked as not covered.

I believe this to be a barebones reproducible version of #1290 which was closed for not having a sample. It is my understanding that 0.8.7 release should have fixed this this issue with the inclusion of #1149.

See also this issue from the kotlin coroutines repo: Kotlin/kotlinx.coroutines#2351

@joshfriend joshfriend added the type: bug 🐛 Something isn't working label Aug 16, 2022
@Godin
Copy link
Member

Godin commented Oct 13, 2022

In your case JaCoCo report

Screenshot 2022-10-13 at 15 05 58

correctly shows that the end of suspending lambda after the suspension point delay(100) is never reached.

The addition of debug output before and after the suspension point demonstrates this

Screenshot 2022-10-13 at 15 12 12

Screenshot 2022-10-13 at 15 12 52

And if you'll modify your test to wait a bit after the execution of doSomething()

    fun `demonstrate missed launch coroutine coverage`() = runTest {
         val repo = ExampleRepository()
         repo.doSomething()
+        Thread.sleep(1000)
    }

then you'll see that the end of suspending lambda is reached

Screenshot 2022-10-13 at 15 25 34

Screenshot 2022-10-13 at 15 27 27

Screenshot 2022-10-13 at 15 25 07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants