-
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
Reduce the need for @AutoConfigureTestDatabase(replace=NONE) when using a test-provided database #35253
Comments
That's #35125 trying to fix. |
Unfortunately, I don't think #35125 is the right approach. As I said when closing the PR, I don't think the location of where connection details are defined is a strong enough signal to decide whether or not the database should be replaced. A user could have defined their own |
@wilkinsona What about skip replacing DataSource if bean if (registry.containsBeanDefinition("org.springframework.boot.testcontainers.service.connection.ServiceConnectionAutoConfiguration") ) {
logger.info(
"Skip replacing DataSource bean with embedded version due to @ServiceConnection is using");
return;
} |
Thanks for the idea. Unfortunately, I don't think we can assume that the presence of I think we need a general purpose way of having more control over the replacement, but I don't yet know what that looks like. I think anything that relies on specifics will be too brittle. |
I have a possible solution to this at https://github.com/philwebb/spring-boot/tree/gh-35253, but it feels risky for a bug fix. Especially since adding I'm also not totally sure about how we should detect service connections. There's a |
Hi @philwebb, I tried the snapshots and it is working for those test with Testcontainers implementation as a static fields but not with Testcontainers JDBC URL branch: https://github.com/eddumelendez/testcontainers-samples/tree/autoconfigutetestdatabase Testcontainers as static fields https://github.com/eddumelendez/testcontainers-samples/blob/autoconfigutetestdatabase/spring-boot-cockroachdb-flyway/src/test/java/com/example/springbootcockroachdbflyway/CockroachDbTest.java ✅ Testcontainers JDBC URL https://github.com/eddumelendez/testcontainers-samples/blob/autoconfigutetestdatabase/spring-boot-cockroachdb-flyway/src/test/java/com/example/springbootcockroachdbflyway/CockroachDbHostLessTest.java ❌ Just wondering if this issue should cover both cases |
Thanks @eddumelendez, reopening to investigate :( |
Thanks again for testing the SNAPSHOT @eddumelendez. I've pushed a fix if you want to try again. |
I've tested locally and both tests are green now. Thanks @philwebb! |
If a test class is using
@ServiceConnection
to create a test-specificDataSource
,@DataJpaTest
or any other sliced-test annotation that uses@AutoConfigureTestDatabase
will replace it with an embedded database due to its default replacement policy ofANY
. I believe the same problem will occur with@DynamicPropertySource
so this problem isn't particularly new. That said we may not be able to fix it in maintenance releases, it'll depend on the nature and complexity of any fix. Assigning to 3.1.x for now.The text was updated successfully, but these errors were encountered: