dave08
03/30/2023, 9:35 AMCan not resolve request to <http://localhost:8080>. Main app runs at 0.0.0.0:8080, 127.0.0.1:8090 and external services are
io.ktor.server.testing.client.InvalidTestRequestException: Can not resolve request to <http://localhost:8080>. Main app runs at 0.0.0.0:8080, 127.0.0.1:8090 and external services are
at app//io.ktor.server.testing.client.DelegatingTestClientEngine.execute(DelegatingTestClientEngine.kt:59)
at app//io.ktor.client.engine.HttpClientEngine$executeWithinCallContext$2.invokeSuspend(HttpClientEngine.kt:99)
Aleksei Tirman [JB]
03/30/2023, 9:39 AMdave08
03/30/2023, 9:43 AMfun testApp(
token: String = "",
....
) = testApplication {
environment {
envConfig {
configureSerialization()
// This has a localPort(8090) { ... } in it
internalRoutes(...)
// This doesn't have any port()... block in it... 8080 should be the default...? But maybe I should add it... but the error doesn't say the path wasn't found... it returns that funny error
externalRoutes(...)
}
}
val client = createClient {
install(ContentNegotiation) { json() }
defaultRequest {
port = 8080
}
}
val internalClient = createClient {
install(ContentNegotiation) { json() }
defaultRequest {
port = 8090
}
}
...
}dave08
03/30/2023, 9:45 AMAleksei Tirman [JB]
03/30/2023, 9:47 AMDefaultRequest
plugin? I guess the problem is that the 127.0.0.1
and localhost
are different things for the test engine.dave08
03/30/2023, 9:51 AMfun ApplicationEngineEnvironmentBuilder.envConfig(module: Application.() -> Unit) {
module {
module()
}
connector {
host = "0.0.0.0"
port = 8080
}
connector {
host = "127.0.0.1"
port = 8090
}
}
dave08
03/30/2023, 9:51 AMdave08
03/30/2023, 9:53 AMhost = "0.0.0.0"
... 🤒 maybe Ktor should be a bit smarter when seeing these hosts? I'm sure I'm not the only one facing such things...dave08
03/30/2023, 9:59 AMAleksei Tirman [JB]
03/31/2023, 4:00 AM