I tried to adopt the new spring boot testcontainers feature in my project, and used @ImportTestcontaienrs to replace the original AppliationContextInitailzier to share test containers in tests, but failed.
I created a Kotlin interface to declare containers.
interface ContainersConfig{ // also tried to use class
companion object{
@Container
@ServiceConnction
var postgresSQLContaienr...
}
}
And applied the config on test classes by @ImportTestcontainers.
When running the test classes one by one on my local machine, all are passed.
But when I pushed my changes to Github and build the project on Github actions.
I got the exceptions like this.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'r2dbcScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/R2dbcInitializationConfiguration.class]:
Failed to execute database script
Caused by: org.springframework.r2dbc.connection.init.UncategorizedScriptException:
Failed to execute database script
Caused by: org.springframework.dao.DataAccessResourceFailureException:
Failed to obtain R2DBC Connection
Caused by: io.r2dbc.postgresql.ExceptionFactory$PostgresqlNonTransientResourceException:
[53300] sorry, too many clients already
All test classes used @ImportTestContainers are failed with similar info.
The original post I created on StackOverFlow, https://stackoverflow.com/questions/76320640/importtestcontainers-caused-exception-on-github-actions
Comment From: snicoll
There are people trying to help you on SO so let's keep the conversation over there and we can reopen here if it turns out some change in Spring Boot is required.