Skip to content

Error encountered exiting Spring ApplicationContext at the end of a @SpringBootTest using Testcontainers & Modulith #450

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

Closed
JakeTiritilli opened this issue Jan 12, 2024 · 4 comments
Assignees
Labels
meta: waiting for feedback Waiting for feedback of the original reporter

Comments

@JakeTiritilli
Copy link

JakeTiritilli commented Jan 12, 2024

Spring Boot version: 3.2.1
Spring Modulith version: 1.1.1
Testcontainers PostgreSQL version: 1.19.3

We have noticed an issue when using Spring Modulith in conjunction with a @SpringBootTest and a Testconainers initialization. The test successfully passes but then the execution suspends for several seconds before logging the below errors/warnings:

{"timestamp":"2024-01-12 16:38:15.232108+0000","level":"WARN","message":"HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection@7116e7d (This connection has been closed.). Possibly consider using a shorter maxLifetime value."}
{"timestamp":"2024-01-12 16:38:45.220959+0000","level":"WARN","message":"SQL Error: 0, SQLState: 08001"}
{"timestamp":"2024-01-12 16:38:45.221256+0000","level":"ERROR","message":"HikariPool-1 - Connection is not available, request timed out after 30005ms."}
{"timestamp":"2024-01-12 16:38:45.221382+0000","level":"ERROR","message":"Connection to localhost:55910 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."}
{"timestamp":"2024-01-12 16:38:45.223842+0000","level":"WARN","message":"Invocation of destroy method failed on bean with name 'eventPublicationRegistry': org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction"}

The amount of time it suspends for seems to be connected to the Hikari connection timeout value.

From the logs, it appears that the DefaultEventPublicationRegistry, which implements DisposableBean, is having its destroy method called after the Testcontainers DB has already been shutdown.

We found this issue on the Testcontainers Java repo and this issue on the Spring Boot repo which describe what sounds like a very similar problem.

Was wondering if anyone has more insight into why this happens or knows of a solution that would potentially fix it.

@odrotbohm
Copy link
Member

As you've seen, on the ticket you linked to, I had already chimed in on the problems of the advertised way of using TC. Can you confirm you use that way, or are you using @ServiceConnection beans? If it's the former, there's nothing more I can add and hope the Boot team finds a solution to the tangential ticket Phil created.

@odrotbohm odrotbohm self-assigned this Jan 15, 2024
@odrotbohm odrotbohm added the meta: waiting for feedback Waiting for feedback of the original reporter label Jan 15, 2024
@JakeTiritilli
Copy link
Author

Thanks for the response. We're creating the Testconainers DB as an ApplicationContextInitializer and setting it in the @ContextConfiguration for each @SpringBootTest. I also tried changing it to use a @ServiceConnection bean, as described here, but I still got the same warning logs. I'll keep an eye out for any updates on the ticket you're referring to, but since it isn't causing the tests to fail, it sounds like we can ignore it for the time being.

@odrotbohm
Copy link
Member

Spring Modulith doesn't even depend on or interact with Testcontainers at all. @AMT is essentially an @SpringBootTest with some tweaks to the component scanning. So any ApplicationContext lifecycle issues would either originate in the interaction between Testcontainers and that. If you can provide a minimal reproducer, it might help to investigate the problem, but fundamentally, I doubt that the culprit resides in Spring Modulith.

@JakeTiritilli
Copy link
Author

Sorry for the delayed response. I agree that this isn't a problem with Spring Modulith. I'll go ahead and close this issue. Thanks

@JakeTiritilli JakeTiritilli closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta: waiting for feedback Waiting for feedback of the original reporter
Projects
None yet
Development

No branches or pull requests

2 participants