blob: ab02c296f35af8f26d066ef09baed905c7a2801f [file] [log] [blame]
Sergey Mashkov88951ac2017-10-27 22:36:08 +03001package kotlinx.coroutines.experimental.io
2
Roman Elizarov9fe5f462018-02-21 19:05:52 +03003import kotlinx.coroutines.experimental.*
4import kotlinx.coroutines.experimental.io.internal.*
5import org.junit.*
Roman Elizarov75675e62017-11-30 15:14:44 +03006import org.junit.Test
Roman Elizarov9fe5f462018-02-21 19:05:52 +03007import org.junit.rules.*
8import kotlin.coroutines.experimental.*
9import kotlin.test.*
Sergey Mashkov88951ac2017-10-27 22:36:08 +030010
11class CopyAndCloseNoAutoFlushTest : TestBase() {
12 private val verifyingPool = VerifyingObjectPool(BufferObjectPool)
13
14 private val from = ByteBufferChannel(true, verifyingPool)
15 private val to = ByteBufferChannel(false, verifyingPool)
16
17 @get:Rule
18 val pool get() = verifyingPool as TestRule
19
20 @Test
21 fun smokeTest() = runBlocking {
22 expect(1)
23
24 launch(coroutineContext) {
25 expect(2)
26 val copied = from.copyAndClose(to) // should suspend
27
28 expect(7)
29
30 assertEquals(8, copied)
31 }
32
33 yield()
34
35 expect(3)
36 from.writeInt(1)
37 expect(4)
38
39 yield()
40 assertEquals(4, to.availableForRead) // 4 bytes need to be copied in spite of that there is no autoFlush
41
42 from.writeInt(2)
43 expect(5)
44
45 yield()
46 expect(6)
47
48 from.close()
49 yield()
50
51 assertTrue { to.isClosedForWrite }
52 to.readPacket(8).release()
53 assertTrue { to.isClosedForRead }
54
55 finish(8)
56 }
57}