Fix OOM in ChannelAtomicCancelStressTest for LinkedListChannel
Sender must be slowed down when it goes too fast
diff --git a/kotlinx-coroutines-core/jvm/test/channels/ChannelAtomicCancelStressTest.kt b/kotlinx-coroutines-core/jvm/test/channels/ChannelAtomicCancelStressTest.kt
index d6fdd4e..6223213 100644
--- a/kotlinx-coroutines-core/jvm/test/channels/ChannelAtomicCancelStressTest.kt
+++ b/kotlinx-coroutines-core/jvm/test/channels/ChannelAtomicCancelStressTest.kt
@@ -115,7 +115,12 @@
else -> error("cannot happen")
}
lastSent = trySend // update on success
- if (counter++ % 1000 == 0) yield() // yield periodically to check cancellation on LinkedListChannel
+ when {
+ // must artificially slow down LINKED_LIST sender to avoid overwhelming receiver and going OOM
+ kind == TestChannelKind.LINKED_LIST -> while (lastSent > lastReceived + 100) yield()
+ // yield periodically to check cancellation on conflated channels
+ kind.isConflated -> if (counter++ % 100 == 0) yield()
+ }
}
}
}