-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
When using JPA and ImportTestcontainers, test context may fail to refresh due to "Mapped port can only be obtained after the container is started" #40585
Comments
Here's a minimal reproducer: import org.junit.jupiter.api.Test;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.weaving.LoadTimeWeaverAware;
import org.springframework.instrument.classloading.LoadTimeWeaver;
@SpringBootTest
@ImportTestcontainers(MyContainers.class)
public class LoaderTimeWeaverAwareConsumerImportTestcontainersTests implements MyContainers {
@Test
void test() {
}
@Configuration
@ImportAutoConfiguration(DataSourceAutoConfiguration.class)
static class TestConfiguration {
@Bean
LoaderTimeWeaverAwareConsumer loadTimeWeaverAwareConsumer(JdbcConnectionDetails connectionDetails) {
return new LoaderTimeWeaverAwareConsumer(connectionDetails);
}
}
static class LoaderTimeWeaverAwareConsumer implements LoadTimeWeaverAware {
public LoaderTimeWeaverAwareConsumer(JdbcConnectionDetails jdbcConnectionDetails) {
jdbcConnectionDetails.getJdbcUrl();
}
@Override
public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) {
}
}
}
interface MyContainers {
@Container
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:16.1");
} The problem in the real app is that the entity manager factory implements |
This looks similar to #38913 |
Hi, I've upgraded
this project
from Spring Boot 3.1.4 to 3.2.5.After that, I've started having issues in my test cases.
I am defining the
MyContainers
interfaceThen, using the
ImportTestcontainers
annotationIt seems that the test cases are not waiting for the containers to start
If I downgrade to Spring Boot 3.1.4, the test cases will run ok.
How to reproduce
git clone https://github.com/ivangfr/spring-data-jpa-relationships.git
./mvnw clean test
Thanks
The text was updated successfully, but these errors were encountered: