-
Notifications
You must be signed in to change notification settings - Fork 105
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
How can I test back-pressure? #157
Comments
Turbine uses an unconfined collector which runs concurrently with your test lambda to ensure that we see all values. We do not have a mechanism for applying backpressure to the upstream source. Can you describe what you're actually testing? |
This is probably not a good implementation, but I'm trying to see if I could have a flow that exposes an editable queue. So while collect is still suspended, and the queue is cleared, the next item would not be emitted. Any suggestions on how to achieve this would be appreciated :) Here is a bit of a naive implementation. val eventQueueList = mutableListOf<Event>()
val eventQueueFlow = flow {
while (true) {
val event = eventQueueList.removeFirstOrNull()
if (event != null) {
emit(event)
}
delay(10)
}
} |
We can possibly design a variation of the API that allows applying backpressure by using a channel with a smaller buffer and potentially an intermediate coroutine which controls the number of allowed items before it blocks the collector. |
Okay my thought here is that we basically let you control the number of buffered items by blocking the collector. By default it's infinite (the current behavior). You can explicitly increase the count which will unblock the collector for N items. Or if the collector is blocked and you call |
Ok I think I got it, so the default behavior would be the same, but somehow I could make this a blocking test, and there I would be able to call Is my understand correct? Do you think this could me implemented in the same |
I think it would be the same API. You would call |
I agree with enforcing at least 1. But I can't think of a use case where I would want to call |
I mean we can omit it and start with only two modes: rendezvous or unlimited buffer. If someone complains at least we have an idea on how to build support for arbitrary buffer capacities, but maybe no one actually needs it. |
Hi, I was wondering if there is any mechanism to test the same back-pressure behavior that
collect()
has.Here is an example on the different behaviors I encounter.
Prints
The text was updated successfully, but these errors were encountered: