Skip to content

Submit failing RendezvousChannelStressTest #1455

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package kotlinx.coroutines.channels

import kotlinx.coroutines.TestBase
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.first
import org.junit.Test
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.concurrent.thread

class RendezvousChannelStressTest : TestBase() {

@Test
fun testOfferByThread_consumeAsFlow_StressTest() = runTest {
val channel = Channel<Long>(Channel.RENDEZVOUS)
val valueReceived = AtomicBoolean(false)
try {
thread {
try {
var i = 0L
while (!valueReceived.get()) {
i++
channel.offer(i)
}
} catch (e: ClosedSendChannelException) {

}
}

channel.consumeAsFlow().first { true }
} finally {
valueReceived.set(true)
}
}


@Test
fun testOfferByThread_consumeAsChannel_StressTest() = runTest {
val channel = Channel<Long>(Channel.RENDEZVOUS)
val valueReceived = AtomicBoolean(false)
try {
thread {
try {
var i = 0L
while (!valueReceived.get()) {
i++
channel.offer(i)
}
} catch (e: ClosedSendChannelException){

}
}

@Suppress("DEPRECATION")
channel.first { true }
} finally {
valueReceived.set(true)
}
}
}