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
Missing emissions when using combine operator #26
Comments
I think this issue is related to Kotlin/kotlinx.coroutines#2082 and similar. Running your example locally with coroutines 1.4.2, I'm getting yet another output variant:
The |
Specifically, this comment seems to highlight the problem. I try really, really hard to never use runBlockingTest because it has some wacky behaviors associated with it. |
Thanks for the responses and the link to the coroutines issue. There is indeed a difference between running it in For completeness, this is the code for the test comparing @Test
fun combineTest() {
runBlocking {
combine(flow1(), flow2()) { i, s -> i.toString() + s }.collect {
println("collect + runBlocking: $it") // Will print "1a 2b 2c"
}
}
runBlockingTest {
combine(flow1(), flow2()) { i, s -> i.toString() + s }.collect {
println("collection + runBlockingTest: $it") // Will print "1a 2a 2b 2c"
}
}
runBlocking {
combine(flow1(), flow2()) { i, s -> i.toString() + s }.test {
println("Turbine + runBlocking: ${expectItem()}") // Will print 2b
println("Turbine + runBlocking: ${expectItem()}") // Will print 2c
expectComplete()
}
}
runBlockingTest {
combine(flow1(), flow2()) { i, s -> i.toString() + s }.test {
println("Turbine + runBlockingTest: ${expectItem()}") // Will print 2b
println("Turbine + runBlockingTest: ${expectItem()}") // Will print 2c
expectComplete()
}
}
} Output:
|
I'm getting an unexpected result when checking flow emissions after using the combine operator. Using
.test{}
results in less emissions than using.collect{}
. I expect.test{}
to result in the same # of emissions.If this is indeed considered a bug and not a misuse from my side, I'd be happy to try and contribute a fix.
Reproduction test (based on the combine operator docs):
Output:
Running:
The text was updated successfully, but these errors were encountered: