Skip to content

Commit 021cca3

Browse files
committed
Make testDelayChannelBackpressure2 not fail
This test could in theory already fail on the second `checkNotEmpty`: after the first `checkNotEmpty` has passed, first, the ticker channel awakens to produce a new element, and then the main thread awakens to check if it's there. However, if the ticker channel is sufficiently slowed down, it may not produce the element in time for the main thread to find it. After introducing the change that allows the worker thread in `DefaultExecutor` to shut down, the initial delay of 2500 ms is sufficient for the worker to shut down (which, by default, happens after 1000 ms of inactivity), and then the aforementioned race condition worsens: additional time is required to launch a new worker thread and it's much easier to miss the deadline. Now, the delays are much shorter, meaning that the worker thread is never inactive long enough to shut down.
1 parent dff1531 commit 021cca3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kotlinx-coroutines-core/jvm/test/channels/TickerChannelTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ class TickerChannelTest : TestBase() {
4747
@Test
4848
fun testDelayChannelBackpressure2() = withVirtualTimeSource {
4949
runTest {
50-
val delayChannel = ticker(delayMillis = 1000, initialDelayMillis = 0)
50+
val delayChannel = ticker(delayMillis = 200, initialDelayMillis = 0)
5151
delayChannel.checkNotEmpty()
5252
delayChannel.checkEmpty()
5353

54-
delay(2500)
54+
delay(500)
5555
delayChannel.checkNotEmpty()
56-
delay(510)
56+
delay(110)
5757
delayChannel.checkNotEmpty()
58-
delay(510)
58+
delay(110)
5959
delayChannel.checkEmpty()
60-
delay(510)
60+
delay(110)
6161
delayChannel.checkNotEmpty()
6262
delayChannel.cancel()
6363
}

0 commit comments

Comments
 (0)