Osman Saral
03/27/2023, 3:39 PMOsman Saral
03/27/2023, 3:41 PM"null"
to "foo"
it doesn't fail with assertion, instead it throws kotlinx.coroutines.channels.ClosedReceiveChannelException: Channel was closed. Is there something wrong or is it normal.
@Test
fun testJsonNullWithWebsocketsClient(): Unit = testApplication {
install(io.ktor.server.websocket.WebSockets)
routing {
webSocket("/") {
for (frame in incoming) {
assertEquals("null", (frame as Frame.Text).readText())
outgoing.send(frame)
}
}
}
createClient {
install(WebSockets) {
contentConverter = KotlinxWebsocketSerializationConverter(
Json {
ignoreUnknownKeys = true
}
)
}
}.ws("/") {
val user: User? = null
sendSerialized(user)
val received = receiveDeserialized<User?>()
assertNull(received)
}
}
Aleksei Tirman [JB]
03/27/2023, 6:14 PMClosedReceiveChannelException
. Can you please share a complete test where that exception is thrown during the execution?Osman Saral
03/27/2023, 7:00 PMAleksei Tirman [JB]
03/28/2023, 8:59 AMassertEquals("error", (frame as Frame.Text).readText())
fails but the assertion exception doesn’t propagates to the top level. Then the test server Websockets connection is closed which leads to closing the receive channel on the client side.Osman Saral
03/28/2023, 9:01 AMAleksei Tirman [JB]
03/28/2023, 9:02 AMtry/catch
.Osman Saral
03/28/2023, 9:02 AMOsman Saral
03/28/2023, 9:03 AMAleksei Tirman [JB]
03/28/2023, 9:03 AMComparisonFailure
in the logs.Aleksei Tirman [JB]
03/28/2023, 9:04 AMAleksei Tirman [JB]
03/28/2023, 9:05 AMclose
method to close a connection.Osman Saral
03/28/2023, 9:06 AMAleksei Tirman [JB]
03/28/2023, 9:06 AMOsman Saral
03/28/2023, 9:08 AMComparisonFailure
in the logs. Or any other exception other than ClosedReceiveChannelException
, That makes things very hardOsman Saral
03/28/2023, 9:09 AMAleksei Tirman [JB]
03/28/2023, 9:12 AMOsman Saral
03/28/2023, 9:15 AMOsman Saral
03/28/2023, 9:19 AM