Skip to content

Commit 6322ded

Browse files
committed
Review fixes
Signed-off-by: Nikita Koval <[email protected]>
1 parent eb68dba commit 6322ded

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

kotlinx-coroutines-core/common/test/channels/ChannelsTest.kt

+35-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ChannelsTest: TestBase() {
2020
}
2121

2222
@Test
23-
fun testCloseWithMultipleWaiters() = runTest {
23+
fun testCloseWithMultipleSuspendedReceivers() = runTest {
2424
// Once the channel is closed, the waiting
2525
// requests should be cancelled in the order
2626
// they were suspended in the channel.
@@ -53,6 +53,40 @@ class ChannelsTest: TestBase() {
5353
finish(7)
5454
}
5555

56+
@Test
57+
fun testCloseWithMultipleSuspendedSenders() = runTest {
58+
// Once the channel is closed, the waiting
59+
// requests should be cancelled in the order
60+
// they were suspended in the channel.
61+
val channel = Channel<Int>()
62+
launch {
63+
try {
64+
expect(2)
65+
channel.send(42)
66+
expectUnreached()
67+
} catch (e: CancellationException) {
68+
expect(5)
69+
}
70+
}
71+
72+
launch {
73+
try {
74+
expect(3)
75+
channel.send(42)
76+
expectUnreached()
77+
} catch (e: CancellationException) {
78+
expect(6)
79+
}
80+
}
81+
82+
expect(1)
83+
yield()
84+
expect(4)
85+
channel.cancel()
86+
yield()
87+
finish(7)
88+
}
89+
5690
@Test
5791
fun testEmptyList() = runTest {
5892
assertTrue(emptyList<Nothing>().asReceiveChannel().toList().isEmpty())

0 commit comments

Comments
 (0)