James Chen
11/25/2022, 6:39 PMexternalServices
. This is the mock I have right now in my `testApplication`:
externalServices {
hosts("<ws://test.com>") {
install(io.ktor.server.websocket.WebSockets) {}
routing {
webSocket("/") {
this.send("hello")
}
}
}
}
My test will hang when it tries to connect to <ws://test.com>
and eventually return a io.ktor.client.network.sockets.ConnectTimeoutException: Connect timeout has expired [url=<ws://test.com>, connect_timeout=unknown ms]
error. Can externalServices
mock out ws servers? If not, are there any suggestions on how to mock a ws server for testing? Thank you!James Chen
11/25/2022, 8:26 PMAleksei Tirman [JB]
11/28/2022, 11:46 AM@Test
fun test() = testApplication {
externalServices {
hosts("<ws://test.com>") {
this@hosts.install(WebSockets) {}
this@hosts.routing {
webSocket("/") {
this.send(Frame.Text("hello"))
}
}
}
}
val client = createClient {
install(io.ktor.client.plugins.websocket.WebSockets)
}
client.webSocket("<ws://test.com>") {
val frame = incoming.receive()
assertIs<Frame.Text>(frame)
assertEquals("hello", frame.readText())
}
}