-
Notifications
You must be signed in to change notification settings - Fork 104
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
Use test-specific unconfined when test scheduler is in use #151
Conversation
This retains the test scheduler virtual time. Unfortunately this requires taking a dependency on the test library and also relying on unstable API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of Unconfined
. But given that we're using it, this is the right thing to do.
Yeah no one should use it... except this library. Consuming a |
Is My mental model for the tool has always been something like (pseudocode): val channel
val job = launch { flow => channel }
validate(channel)
cleanup(channel, job) Which is just two coroutines running in parallel. When I'm lazy and want to sketch out a flow validation without adding the Turbine dependency, I tend to just do something like this by hand. And that works just fine. |
Without The test to ensure val flow = MutableStateFlow(0)
flow.test {
assertEquals(0, awaitItem())
flow.value = 1
flow.value = 2
assertEquals(1, awaitItem())
assertEquals(2, awaitItem())
} Remove |
@@ -108,10 +111,16 @@ public fun <T> Flow<T>.testIn(scope: CoroutineScope): ReceiveTurbine<T> { | |||
return turbine | |||
} | |||
|
|||
@OptIn(ExperimentalCoroutinesApi::class) // New kotlinx.coroutines test APIs are not stable 😬 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to #132 😭
Yep, I'm aware. :( My POV is that walking down this path leads to places like this. And I don't really like those places. I have this wonderful set of tools in my coroutines toolbelt, and those places say "Okay, write your real code with your coroutines toolbelt, and then switch to this totally different testing toolbelt to validate it. Your testing toolbelt will let you forget about all that coroutines stuff, it just works!" And I go "Hmm, okay..." and use the testing toolbelt. But then when my code gets bold and exciting (e.g. molecule), the underlying coroutines-iness rears its head and I have to deal with it again. |
That issue is precisely what we want! |
It's not what I want. See discussion here. See talk here. If it is in fact what I want, I need some convincing. The bedrock that has served me is this idea: tooling that encourages engineers to write code with an incorrect mental model will lead to confusion and errors. When I see advice like, "Oh, you just need to use And of course, whether that tooling can even work 100% of the time is still an open question. |
It's what this library wants. Completely dropping Unconfined and the conditional we have to make to support runTest sounds great. |
This retains the test scheduler virtual time.
Unfortunately this requires taking a dependency on the test library and also relying on unstable API.
Closes #124. Closes #118.