question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I test back-pressure?

See original GitHub issue

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.

@Test
public fun `when I test - flow should backpressure`(): TestResult = runTest {
    val myFlow:Flow<Int> = flow {
        println("emitting 1")
        emit(1)
        println("emitted 1")
        delay(10)
        println("emitting 2")
        emit(2)
        println("emitted 2")
        delay(10)
        println("emitting 3")
        emit(3)
        println("emitted 3")
    }


    println("COLLECT")
    myFlow.collect {
        println("collected $it")
        delay(50)
    }

    println()
    println("TEST")
    // Test
    myFlow.test {
        val item1 = awaitItem()
        println("collected $item1")
        delay(50)
        val item2 = awaitItem()
        println("collected $item2")
        delay(50)
        val item3 = awaitItem()
        println("collected $item3")
        awaitComplete()
    }
}

Prints

COLLECT
emitting 1
collected 1
emitted 1
emitting 2
collected 2
emitted 2
emitting 3
collected 3
emitted 3

TEST
emitting 1
emitted 1
emitting 2
emitted 2
emitting 3
emitted 3
collected 1
collected 2
collected 3

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
JakeWhartoncommented, Sep 29, 2022

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.

1reaction
JakeWhartoncommented, Nov 18, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exhaust Back Pressure Test - Direct & Temperature - YouTube
In this video, I will guide you how to troubleshoot the exhaust back pressure. You should make sure, the back pressure is not...
Read more >
Simple Diagnostic Testing - Walker Exhaust
These tests are used to determine if blockages exist in the exhaust system, creating excessive backpressure. The following tests can help determine the...
Read more >
BPT02 Back Pressure Test Kit Instructions - Hickok Inc.
Using the BPT02 Back Pressure Test Kit will provide you with the most accurate and reliable means for detecting a restricted exhaust system....
Read more >
What is Backpressure testing of PRV? - AMARINE
The Backpressure Test is a compressed air or gas at a pressure of at least 2 bars. Go from the outlet side of...
Read more >
Exhaust Backpressure Testing (known bad compared to ...
Tools used · exhaust back-pressure test kit · vacuum/pressure gauge ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found