File tree 1 file changed +35
-1
lines changed
kotlinx-coroutines-core/common/test/channels
1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class ChannelsTest: TestBase() {
20
20
}
21
21
22
22
@Test
23
- fun testCloseWithMultipleWaiters () = runTest {
23
+ fun testCloseWithMultipleSuspendedReceivers () = runTest {
24
24
// Once the channel is closed, the waiting
25
25
// requests should be cancelled in the order
26
26
// they were suspended in the channel.
@@ -53,6 +53,40 @@ class ChannelsTest: TestBase() {
53
53
finish(7 )
54
54
}
55
55
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
+
56
90
@Test
57
91
fun testEmptyList () = runTest {
58
92
assertTrue(emptyList<Nothing >().asReceiveChannel().toList().isEmpty())
You can’t perform that action at this time.
0 commit comments