blob: 8d868c266a3cc1a6cd1c61d534a9da8ee1d3ca93 [file] [log] [blame]
Sergey Mashkov4ee9cfb2017-12-20 18:22:11 +03001package kotlinx.coroutines.experimental.io
2
3import kotlinx.coroutines.experimental.*
4import kotlinx.coroutines.experimental.channels.*
5import kotlinx.coroutines.experimental.io.internal.*
Sergey Mashkov4d01f7e2018-01-12 18:46:22 +03006import org.junit.Ignore
Sergey Mashkov4ee9cfb2017-12-20 18:22:11 +03007import org.junit.Test
Roman Elizarov9fe5f462018-02-21 19:05:52 +03008import kotlin.coroutines.experimental.*
Sergey Mashkov4ee9cfb2017-12-20 18:22:11 +03009import kotlin.test.*
10
Sergey Mashkov4d01f7e2018-01-12 18:46:22 +030011@Ignore
Sergey Mashkov4ee9cfb2017-12-20 18:22:11 +030012class InlineRendezvousSwapTest : TestBase() {
13 @Test
14 fun smokeTest1() = runTest {
15 val swap = InlineRendezvousSwap<String>()
16
17 launch(coroutineContext) {
18 assertEquals("1", swap.receive())
19 }
20
21 launch(coroutineContext) {
22 swap.send("1")
23 }
24 }
25
26 @Test
27 fun smokeTest2() = runTest {
28 val swap = InlineRendezvousSwap<String>()
29
30 launch(coroutineContext) {
31 swap.send("1")
32 }
33
34 launch(coroutineContext) {
35 assertEquals("1", swap.receive())
36 }
37 }
38
39 @Test
40 fun testLoop1() = runTest {
41 val swap = InlineRendezvousSwap<String>()
42 val received = Channel<String>(1)
43
44 launch(coroutineContext) {
45 while (true) {
46 val s = swap.receive()
47 if (s.isEmpty()) break
48 received.send(s)
49 }
50 received.close()
51 }
52
53 launch(coroutineContext) {
54 for (i in 1..10) {
55 swap.send(i.toString())
56 }
57 swap.send("")
58 }
59
60 assertEquals((1..10).map { it.toString() }, received.toList())
61 }
62
63 @Test
Sergey Mashkov4d01f7e2018-01-12 18:46:22 +030064 @Ignore
Sergey Mashkov4ee9cfb2017-12-20 18:22:11 +030065 fun testLoop2() = runTest {
66 val swap = InlineRendezvousSwap<String>()
67 val received = Channel<String>(1)
68
69 launch(coroutineContext) {
70 while (true) {
71 val s = swap.receive()
72 if (s.isEmpty()) break
73 received.send(s)
74 }
75 received.close()
76 }
77
78 launch(coroutineContext) {
79 for (i in 1..10) {
80 yield()
81 swap.send(i.toString())
82 }
83 swap.send("")
84 }
85
86 assertEquals((1..10).map { it.toString() }, received.toList())
87 }
88
89 @Test
90 fun testLoop3() = runTest {
91 val swap = InlineRendezvousSwap<String>()
92 val received = Channel<String>(1)
93
94 launch(coroutineContext) {
95 while (true) {
96 yield()
97 val s = swap.receive()
98 if (s.isEmpty()) break
99 received.send(s)
100 }
101 received.close()
102 }
103
104 launch(coroutineContext) {
105 for (i in 1..10) {
106 swap.send(i.toString())
107 }
108 swap.send("")
109 }
110
111 assertEquals((1..10).map { it.toString() }, received.toList())
112 }
113
114}