You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Test Resources default wait strategy is not "port" as specified in the documentation under "Wait strategies", and this makes them not work correctly in some environments.
I expect the default wait strategy for Test Containers created by Test Resources to be "port" as specified in the documentation.
Add a test using a StatefulRedisConnection from Lettuce.
I expect the application to be able to build with ./gradlew build --info and the test to be able to connect to Redis.
Actual Behaviour
I get the error below every time when building.
It seems Test Resources are not able to detect correctly, when the Redis container has actually started up, so it tries to run the test before the container is running and therefore get a connection refused, when attempting to connect to it.
If I add test-resources.containers.redis.wait-strategy=port to application.properties, the application builds fine afterwards.
This must mean, that the default wait strategy for containers created by Test Resources is not set to "port" as specified in the documentation under "Wait strategies".
I am using a new MacBook, which is very fast. I have also tested it on a slower Windows computer, where the error below doesn't occur.
Error:
RedisTest > testRedis() FAILED
org.junit.jupiter.api.extension.ParameterResolutionException: Failed to resolve parameter [io.lettuce.core.api.StatefulRedisConnection<java.lang.String, java.lang.String> redisConnection] in constructor [public example.micronaut.RedisTest(io.lettuce.core.api.StatefulRedisConnection<java.lang.String, java.lang.String>)]: Error instantiating bean of type [io.lettuce.core.api.StatefulRedisConnection]
Message: Unable to connect to localhost/<unresolved>:32817
Path Taken: DefaultRedisClientFactory.redisConnection(RedisClient redisClient)
at [email protected]/java.util.Optional.orElseGet(Optional.java:364)
at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1511)
at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by:
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [io.lettuce.core.api.StatefulRedisConnection]
Message: Unable to connect to localhost/<unresolved>:32817
Path Taken: DefaultRedisClientFactory.redisConnection(RedisClient redisClient)
at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2322)
at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2277)
at app//io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2289)
at app//io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3056)
at app//io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:81)
at app//io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:2958)
at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2919)
at app//io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2730)
at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1693)
at app//io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:840)
at app//io.micronaut.test.extensions.junit5.MicronautJunit5Extension.resolveParameter(MicronautJunit5Extension.java:380)
... 3 more
Caused by:
io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:32817
at app//io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
at app//io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
at app//io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350)
at app//io.lettuce.core.RedisClient.connect(RedisClient.java:216)
at app//io.micronaut.configuration.lettuce.AbstractRedisClientFactory.redisConnection(AbstractRedisClientFactory.java:88)
at app//io.micronaut.configuration.lettuce.DefaultRedisClientFactory.redisConnection(DefaultRedisClientFactory.java:68)
at app//io.micronaut.configuration.lettuce.$DefaultRedisClientFactory$RedisConnection1$Definition.instantiate(Unknown Source)
at app//io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2307)
... 13 more
Caused by:
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:32817
Caused by:
java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Steps To Reproduce
Note: as stated above, this only fails in some environments, my best guess is it depends on the speed of the computer, it is running on. It fails every time in the environment specified below.
runenielsen
changed the title
Test Resources do not work with Redis
Test Resources default wait strategy is not "port" as specified in the documentation, and this makes them not work correctly
Sep 14, 2023
Expected Behavior
Test Resources default wait strategy is not "port" as specified in the documentation under "Wait strategies", and this makes them not work correctly in some environments.
I expect the default wait strategy for Test Containers created by Test Resources to be "port" as specified in the documentation.
When I create a Micronaut application like this:
... and:
redis.uri
inapplication.properties
.aot
plugin from build.gradle.kts.StatefulRedisConnection
from Lettuce.I expect the application to be able to build with
./gradlew build --info
and the test to be able to connect to Redis.Actual Behaviour
I get the error below every time when building.
It seems Test Resources are not able to detect correctly, when the Redis container has actually started up, so it tries to run the test before the container is running and therefore get a connection refused, when attempting to connect to it.
If I add
test-resources.containers.redis.wait-strategy=port
to application.properties, the application builds fine afterwards.This must mean, that the default wait strategy for containers created by Test Resources is not set to "port" as specified in the documentation under "Wait strategies".
I am using a new MacBook, which is very fast. I have also tested it on a slower Windows computer, where the error below doesn't occur.
Error:
Steps To Reproduce
Note: as stated above, this only fails in some environments, my best guess is it depends on the speed of the computer, it is running on. It fails every time in the environment specified below.
https://github.com/runenielsen/test-resources-redis-fail-no-aot
.RedisTest
and verify that it should succeed when run../gradlew build --info
.test-resources.containers.redis.wait-strategy=port
in inapplication.properties
../gradlew build --info
.Environment Information
OS: MacOS Ventura 13.5.2
JDK: OpenJDK Temurin 17.0.8.1
Docker installed via Rancher Desktop 1.9.1 with containerd container engine
Example Application
https://github.com/runenielsen/test-resources-redis-fail-no-aot
Version
4.1.0
The text was updated successfully, but these errors were encountered: