aboutsummaryrefslogtreecommitdiffstats
path: root/kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt
diff options
context:
space:
mode:
authorVsevolod Tolstopyatov <qwwdfsad@gmail.com>2021-04-13 16:47:55 +0300
committerGitHub <noreply@github.com>2021-04-13 16:47:55 +0300
commit3c83c0cfea619f68f1eb323773d1f057f294023f (patch)
tree992f7071599c7cbfaaea31969ddfe0dc94ebdae9 /kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt
parent7b1f3b379f1863521a26a7d3086b943d7fe3b58e (diff)
downloadplatform_external_kotlinx.coroutines-3c83c0cfea619f68f1eb323773d1f057f294023f.tar.gz
platform_external_kotlinx.coroutines-3c83c0cfea619f68f1eb323773d1f057f294023f.tar.bz2
platform_external_kotlinx.coroutines-3c83c0cfea619f68f1eb323773d1f057f294023f.zip
Deprecate SendChannel.offer and ReceiveChannel.poll, replace their usages along the codebase (#2644)
* Deprecate SendChannel.offer and replace its usages along the codebase * Deprecate ReceiveChannel.poll and replace its usages along the codebase Co-authored-by: Roman Elizarov <elizarov@gmail.com> Addresses #974
Diffstat (limited to 'kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt')
-rw-r--r--kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt45
1 files changed, 11 insertions, 34 deletions
diff --git a/kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt b/kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt
index a64284ae..8962acc3 100644
--- a/kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt
+++ b/kotlinx-coroutines-core/common/test/channels/BasicOperationsTest.kt
@@ -15,8 +15,8 @@ class BasicOperationsTest : TestBase() {
}
@Test
- fun testOfferAfterClose() = runTest {
- TestChannelKind.values().forEach { kind -> testOffer(kind) }
+ fun testTrySendAfterClose() = runTest {
+ TestChannelKind.values().forEach { kind -> testTrySend(kind) }
}
@Test
@@ -39,7 +39,7 @@ class BasicOperationsTest : TestBase() {
}
}
expect(1)
- channel.offer(42)
+ channel.trySend(42)
expect(2)
channel.close(AssertionError())
finish(4)
@@ -80,28 +80,6 @@ class BasicOperationsTest : TestBase() {
}
}
- private suspend fun testReceiveCatchingException(kind: TestChannelKind) = coroutineScope {
- val channel = kind.create<Int>()
- val d = async(NonCancellable) {
- channel.receive()
- }
-
- yield()
- channel.close(TestException())
- assertTrue(channel.isClosedForReceive)
-
- assertFailsWith<TestException> { channel.poll() }
- try {
- channel.receiveCatching().getOrThrow()
- expectUnreached()
- } catch (e: TestException) {
- // Expected
- }
-
- d.join()
- assertTrue(d.getCancellationException().cause is TestException)
- }
-
@Suppress("ReplaceAssertBooleanWithAssertEquality")
private suspend fun testReceiveCatching(kind: TestChannelKind) = coroutineScope {
reset()
@@ -131,22 +109,21 @@ class BasicOperationsTest : TestBase() {
finish(6)
}
- private suspend fun testOffer(kind: TestChannelKind) = coroutineScope {
+ private suspend fun testTrySend(kind: TestChannelKind) = coroutineScope {
val channel = kind.create<Int>()
val d = async { channel.send(42) }
yield()
channel.close()
assertTrue(channel.isClosedForSend)
- try {
- channel.offer(2)
- fail()
- } catch (e: ClosedSendChannelException) {
- if (!kind.isConflated) {
- assertEquals(42, channel.receive())
+ channel.trySend(2)
+ .onSuccess { expectUnreached() }
+ .onFailure {
+ assertTrue { it is ClosedSendChannelException}
+ if (!kind.isConflated) {
+ assertEquals(42, channel.receive())
+ }
}
- }
-
d.await()
}