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

Throw unconsumed events if the scope is cancelled #248

Merged
merged 1 commit into from
Jun 26, 2023

Conversation

Antimonit
Copy link
Contributor

This potentially fixes #247.

Copy link
Collaborator

@jingibus jingibus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this work. It points at some more cleanup that needs to be done related to the new turbineScope, but I'll deal with that in a followup PR!

@@ -211,6 +211,7 @@ internal class ChannelTurbine<T>(
var cause: Throwable? = null
while (true) {
val event = channel.takeEventUnsafe() ?: break
if (event is Event.Error && event.throwable is CancellationException) break
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the idea of just eating these at the source. I had dealt with CancellationException in an ad-hoc manner when implementing turbineScope, and this is much cleaner

@@ -195,7 +195,8 @@ private fun <T> testInInternal(flow: Flow<T>, timeout: Duration?, scope: Corouti
if (debug) println("Scope ending ${exception ?: ""}")

// Only validate events were consumed if the scope is exiting normally.
if (exception == null) {
// CancellationException also indicates _normal_ cancellation of a coroutine.
if (exception == null || exception is CancellationException) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can actually get rid of this whole invokeOnCompletion; turbineScope now has the code to run this validation, so we don't need it here. I'm kinda surprised it works, actually

Does not need to be changed before merge, I'll clean it up in a followup PR

@jingibus jingibus merged commit 794ba58 into cashapp:trunk Jun 26, 2023
@Antimonit Antimonit deleted the unconsumed_events branch June 28, 2023 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test and testIn do not behave consistently
2 participants