Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containers are not started when using @ImportTestcontainers #38913

Closed
philwebb opened this issue Dec 22, 2023 · 8 comments
Closed

Containers are not started when using @ImportTestcontainers #38913

philwebb opened this issue Dec 22, 2023 · 8 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@philwebb
Copy link
Member

philwebb commented Dec 22, 2023

From @sleepo581 in #38831 (comment)

After migrating to spring-boot v3.2.1 tests with @ImportTestcontainers are failing because container is not started.
E.g.:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.datasource.url' to java.lang.String:

    Reason: java.lang.IllegalStateException: Mapped port can only be obtained after the container is started`
public interface Containers {

    @Container
    PostgreSQLContainer<?> postgresContainer = new PostgreSQLContainer<>("postgres:16.1");

    @DynamicPropertySource
    static void setConnectionProperties(DynamicPropertyRegistry registry) {
        registry.add("spring.datasource.url", postgresContainer::getJdbcUrl);
        registry.add("spring.datasource.password", postgresContainer::getPassword);
        registry.add("spring.datasource.username", postgresContainer::getUsername);
    }
 }
@philwebb philwebb added the type: regression A regression from a previous release label Dec 22, 2023
@philwebb philwebb added this to the 3.2.x milestone Dec 22, 2023
@sleepo581
Copy link

@philwebb I've created a simple project with test setup that fails in v3.2.1, but works in 3.2.0.

https://github.com/sleepo581/testcontainers-bug/blob/master/spring-boot-3_2_0/src/test/java/com/example/springboot3_2_0/SpringBoot320ApplicationTests.java

It's project with 2 submodules (3.2.1/3.2.0) with identical code

@scottfrederick
Copy link
Contributor

Note that this only fails when @DynamicPropertySource is used. If @DynamicPropertySource is replaced by @ServiceConnection on the @Container bean field, then the tests will pass.

@goraxan
Copy link

goraxan commented Jan 9, 2024

I confirm the same behaviour, any plans to fix it? Thanks

@scottfrederick
Copy link
Contributor

@goraxan The issue has a regression label and a milestone assigned, which indicates that we plan to address it in a future 3.2.x release.

@acemrek
Copy link

acemrek commented Apr 26, 2024

Hello,
With 3.2.5 DynamicPropertySource is not being called also, which works in 3.2.0 which blocks us from upgrading as of now.

  @Container
  PostgreSQLContainer<?> dbContainer = new PostgreSQLContainer<>(DockerImageName
      .parse("docker.io/postgres")
      .asCompatibleSubstituteFor("postgres")
      .withTag(DEFAULT_POSTGRESQL_TAG));

  @DynamicPropertySource
  static void postgresProperties(DynamicPropertyRegistry registry) {
    registry.add("spring.datasource.url", dbContainer::getJdbcUrl);
    registry.add("spring.datasource.username", dbContainer::getUsername);
    registry.add("spring.datasource.password", dbContainer::getPassword);
    registry.add("spring.datasource.driverClassName", dbContainer::getDriverClassName);
  }

and if I remove DynamicPropertySource and switch to serviceConnections, it does not see it all and spins up the in memory db.

@quaff
Copy link
Contributor

quaff commented Apr 26, 2024

Hello, With 3.2.5 DynamicPropertySource is not being called also, which works in 3.2.0 which blocks us from upgrading as of now.

  @Container
  PostgreSQLContainer<?> dbContainer = new PostgreSQLContainer<>(DockerImageName
      .parse("docker.io/postgres")
      .asCompatibleSubstituteFor("postgres")
      .withTag(DEFAULT_POSTGRESQL_TAG));

  @DynamicPropertySource
  static void postgresProperties(DynamicPropertyRegistry registry) {
    registry.add("spring.datasource.url", dbContainer::getJdbcUrl);
    registry.add("spring.datasource.username", dbContainer::getUsername);
    registry.add("spring.datasource.password", dbContainer::getPassword);
    registry.add("spring.datasource.driverClassName", dbContainer::getDriverClassName);
  }

and if I remove DynamicPropertySource and switch to serviceConnections, it does not see it all and spins up the in memory db.

You should provide a minimized sample instead of code snippet.

@wilkinsona
Copy link
Member

@acemrek once you have a minimal sample to share, please open a new issue for your problem and we will investigate.

@ivangfr
Copy link

ivangfr commented Apr 30, 2024

I am facing the same issue. I've created this issue #40585, including a sample.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

8 participants