Add disconnect lifecycle handlers
This commit is contained in:
1 parent
7bebbf7bd7
commit
19b349143d
4 files changed
+65
-9
No files matched your search
@@ -170,6 +170,41 @@ class TransportTest {
|
||||
d2.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDisconnectedHandlers() = runTest {
|
||||
initCrypto()
|
||||
|
||||
val cmdPing by command<String, String>()
|
||||
val (d1, d2) = createTestDevice()
|
||||
val serverDisconnected = CompletableDeferred<String>()
|
||||
val clientDisconnected = CompletableDeferred<String>()
|
||||
|
||||
val serverInterface = KiloInterface<String>().apply {
|
||||
onDisconnected {
|
||||
serverDisconnected.complete(session)
|
||||
}
|
||||
on(cmdPing) {
|
||||
"pong! [$it]"
|
||||
}
|
||||
}
|
||||
launch { KiloServerConnection(serverInterface, d1, "server session").run() }
|
||||
|
||||
val clientInterface = KiloInterface<String>().apply {
|
||||
onDisconnected {
|
||||
clientDisconnected.complete(session)
|
||||
}
|
||||
}
|
||||
val client = KiloClientConnection(clientInterface, d2, "client session")
|
||||
launch { client.run() }
|
||||
|
||||
assertEquals("pong! [hello]", client.call(cmdPing, "hello"))
|
||||
d1.close()
|
||||
d2.close()
|
||||
|
||||
assertEquals("server session", withTimeout(1000) { serverDisconnected.await() })
|
||||
assertEquals("client session", withTimeout(1000) { clientDisconnected.await() })
|
||||
}
|
||||
|
||||
class TestException(text: String) : Exception(text)
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user