Previous to 3.1.0-RC1, tests using Testcontainers JDBC URL like the one below used to work. With 3.1.0-RC1, it doesn't work anymore

@Testcontainers
@DataJdbcTest(properties = { "spring.datasource.url=jdbc:tc:postgresql:15-alpine:///" })
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
class PostgresHostLessTest {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Test
    void test() {
        var records = this.jdbcTemplate.queryForList("select count(*) from profile");
        assertThat(records).hasSize(1);
    }

}

Looks like liquibase and flyway are executing before the container is declared ready.

This branch contains a lot of examples using JDBC. The snippet above belongs to this test

Comment From: sivaprasadreddy

I bumped into the same issue with both 3.1.0-RC-1 and 3.1.0-SNAPSHOT.

Actually, with the special JDBC URL, one container is spinning up and flyway scripts are applied. But then another container is spinning up without flyway scripts applied and being used with the application.

Here is a reproducer: https://github.com/sivaprasadreddy/spring-boot-testcontainers-service-connection-flyway-issue/blob/main/src/test/java/com/sivalabs/boottcdevmode/domain/ProductRepositoryTest.java

Comment From: wilkinsona

@sivaprasadreddy You seem to have duplicated the container configuration. Once in a spring.datasource.url=jdbc:tc: property and once in a container declared as a @Bean.

Comment From: wilkinsona

Thanks, @eddumelendez. I've reproduced the problem. It's caused by FlywayConnectionDetails falling back to JdbcConnectionDetails so it appears that a Flway-specific URL has been configured. This results in a Flyway-specific DataSource being created and used to apply the migrations. The rest of the app then uses jdbc:tc:postgresql:15-alpine:/// again which results in Testcontainers starting a second container. We need to remove the fallback so that FlywayAutoConfiguration uses the main DataSource rather than creating its own.

Comment From: eddumelendez

Thank you so much for the quick fix, @wilkinsona !