-
Notifications
You must be signed in to change notification settings - Fork 1.9k
In 1.6.10 runTest, advanceUntilIdle never ends if collecting a flow with sample operator #3135
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
Comments
Works as intended. The reason is that the coroutine behind
Sure: the test times out after a minute of inactivity, but here, there is the activity of waiting for |
I understand that due to the current implementation of |
Is this the same reason why this test also does not work? @Test
fun c() = runTest(dispatchTimeoutMs = 1.seconds.inWholeMilliseconds) {
flow { emit(0) }.shareIn(this, started = SharingStarted.Lazily)
} |
±. Both are examples of a coroutine existing but not finishing its work. An even simpler example is just this: @Test
fun c() = runTest(dispatchTimeoutMs = 1000) {
launch(start = CoroutineStart.LAZY) {
}
} (This reminds me that we should add a This issue is not closed, despite the test framework working as intended because maybe there's a good answer to this question:
|
When testing flows with the new api runTest I generally collect values of the flow I want to test, advanceUntilIdle, and read the latest value. This way, I ignore intermediate values that are generally not relevant, and stick to the final value.
If I do this with a flow that uses the
sample
operator the test runs forever, stuck at theadvanceUntilIdle()
call.Simplified example:
Also, in other tests that did not complete with runTest, for example due to using a different dispatcher, the test would finish after 1 min with an exception. In the case of sample it does not, it runs forever.
The text was updated successfully, but these errors were encountered: