Hi! What could this error mean? I have the connect...
# ktor
d
Hi! What could this error mean? I have the connectors set up and everything... (this is in unit tests using testApplication and the environment block to set the connectors...)
Copy code
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 
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)
a
What request causes this error?
d
I have this:
Copy code
fun 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
        }
    }
...
}
When I use the client in the tests, it gives me that error
a
Can you try to explicitly specify the host for the
DefaultRequest
plugin? I guess the problem is that the
127.0.0.1
and
localhost
are different things for the test engine.
d
Doesn't work for either... here's my connectors:
Copy code
fun ApplicationEngineEnvironmentBuilder.envConfig(module: Application.() -> Unit) {
    module {
        module()
    }
    connector {
        host = "0.0.0.0"
        port = 8080
    }
    connector {
        host = "127.0.0.1"
        port = 8090
    }
}
I tried and host = "localhost" and host = "127.0.0.1" in the client...
Ok.. the external one works with:
host = "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...
Or at least maybe a note in the "Testing" docs about this -- that's the first place I tried looking at when I came across the problem... but there was no mention of ports...
a
Can you please file an issue?