cancellability experiments in tests

This commit is contained in:
Sergey Chernov 2023-11-14 02:54:18 +03:00
parent 75e91f8092
commit 0c05cce13b

View File

@ -2,12 +2,8 @@ package net.sergeych.kiloparsec.adapters
import com.ionspin.kotlin.crypto.util.decodeFromUByteArray
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import kotlinx.coroutines.cancel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.yield
import net.sergeych.kiloparsec.adapter.UdpServer
import net.sergeych.kiloparsec.adapter.acceptTcpDevice
import net.sergeych.kiloparsec.adapter.connectTcpDevice
@ -38,8 +34,8 @@ class NetworkTest {
Log.connectConsole(Log.Level.DEBUG)
coroutineScope {
val serverFlow = acceptTcpDevice(17171).cancellable()
launch {
val serverFlow = acceptTcpDevice(17171)
val j = launch {
serverFlow.collect { device ->
println("collected input: $device")
device.output.send("Hello, world!".encodeToUByteArray())
@ -70,8 +66,9 @@ class NetworkTest {
println("--1")
assertEquals("Great", s.input.receive()!!.decodeFromUByteArray())
println("--2")
s.output.send("die".encodeToUByteArray())
// s.close()
// s.output.send("die".encodeToUByteArray())
s.close()
j.cancelAndJoin()
}
}
}