Can we somehow inject properties to use the still unknown micronaut server port? The problem is that our tests sometimes fail because the port selected isn't available by the time we start the Embedded Server.
We have a pattern where we use:
@Requires(property = "micronaut.http.services.some-service.url")
for loading a client and micronaut uses the same. However, when testing controller code we use:
val port: Int = SocketUtils.findAvailableTcpPort()
val applicationProperties: Map<String, Any> =
mapOf(
"micronaut.server.port" to port,
"micronaut.http.services.some-service.url" to "http://localhost:$port"
)
val embeddedServer = ApplicationContext.run(
EmbeddedServer::class.java,
applicationProperties,
"test"
)
On a busy build server, this often fails (~5% of the time) as the port is in a race condition and not available. I'm aware of the Random Port, but I'm not sure we can use it in the properties.
Can we somehow inject properties to use the still unknown micronaut server port? The problem is that our tests sometimes fail because the port selected isn't available by the time we start the Embedded Server.
We have a pattern where we use:
@Requires(property = "micronaut.http.services.some-service.url")
for loading a client and micronaut uses the same. However, when testing controller code we use:
val port: Int = SocketUtils.findAvailableTcpPort()
val applicationProperties: Map<String, Any> =
mapOf(
"micronaut.server.port" to port,
"micronaut.http.services.some-service.url" to "http://localhost:$port"
)
val embeddedServer = ApplicationContext.run(
EmbeddedServer::class.java,
applicationProperties,
"test"
)
On a busy build server, this often fails (~5% of the time) as the port is in a race condition and not available. I'm aware of the Random Port, but I'm not sure we can use it in the properties.
Share Improve this question asked Mar 10 at 16:18 KurtKurt 5551 gold badge6 silver badges16 bronze badges1 Answer
Reset to default 0Yes, you can. For example in your application-test.properties
set a random port for the Micronaut Server. 99% of all execution it will pick a free port without any problem.
Then set the micronaut.server.port
to your http client.
micronaut.server.port=${random.port}
micronaut.http.services.some-service.url=http://localhost:${micronaut.server.port}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744835218a4596222.html
评论列表(0条)