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

CoroutineLaunchedInTestWithoutRunTest | Fail to detect Flow based Coroutine Launches #7200

Open
tyvsmith opened this issue Apr 17, 2024 · 1 comment

Comments

@tyvsmith
Copy link
Contributor

Expected Behavior

The CoroutineLaunchedInTestWithoutRunTest rule does not account for Flow usage of coroutines, however, I would expect this to be true. It works otherwise on .launch.

Observed Behavior

Rule catches .launch but does not detect and flag flowOf().launchIn() outside of runTest

Steps to Reproduce

Run rule on following test:

class TestCoroutineRunTest {
  @Test
  fun testFlowNoRunTest() {
    flowOf("foo", "bar").launchIn(GlobalScope)
  }
}

Observe no rule violation.

Context

We have heavy use of Flow (in feature code under test), as well as direct usage in tests, that is causing flakeyness.

Your Environment

This was tested with the detekt.jar which we have wired up with Buck and Bazel, using type resolution.
Detekt 1.23.3 with backported rule.
Kotlin 1.9.20

@schalkms
Copy link
Member

Thanks for reporting this!
I removed the bug label as this finding rather shows a current limitation of this rule. The rule in the current detekt version provides a more or less naive implementation without type and symbol solving, which this rule needs to extend the analyzed scope.

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