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 not shut down between tests when using .withReuse(true) but env. does not support reuse (e.g. CI builds) #39609

Closed
jgracin opened this issue Feb 17, 2024 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@jgracin
Copy link

jgracin commented Feb 17, 2024

Hi!

When an environment does NOT support container reuse (i.e. .testcontainers.properties does not have testcontainers.reuse.enabled=true), but a container is set up using container.withReuse(true), Testcontainers Java decides that the container is not reusable. However, the isShouldBeReused() method continues to return true, because it only reflects the values set by .withReuse().

Spring Boot Testcontainers module in TestcontainersLifecycleBeanPostProcessor.postProcessBeforeDestruction() checks container.isShouldBeReused() and decides it will not shut down the container even though the container cannot be reused because the environment does not support it.

This results in multiple instances of the same containers running, potentially exhausting the build machine resources. (In GH Actions, this often manifests as "build stuck in tests", because the machine is not able to spawn any more container instances.)

A workaround that I'm currently using is that, instead of unconditionally using .withReuse(true) in test setup, I use

if (TestcontainerConfiguration.getInstance().environmentSupportsReuse() {
  container.withReuse(true);
}

It seems that fixing this will probably need Testcontainers Java changes, I plan to raise an issue there as well.

Using Spring Boot 3.2.0, and Java 21.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 17, 2024
@scottfrederick
Copy link
Contributor

@jgracin Please add a comment with the link to a Testcontainers issue when you create one. We can decide what, if anything to do in Spring Boot once we see what the Testcontainers team wants to do.

@jgracin
Copy link
Author

jgracin commented Feb 18, 2024

The issue in Testcontainers is testcontainers/testcontainers-java#8323

@wilkinsona wilkinsona added the status: blocked An issue that's blocked on an external project change label Feb 21, 2024
@philwebb
Copy link
Member

The test containers issue doesn't seem to be getting any traction as yet. I think we could change TestcontainersLifecycleBeanPostProcessor.isReusedContainer to do the same TestcontainerConfiguration.getInstance().environmentSupportsReuse() check. We can always change again if a better approach is available later.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: blocked An issue that's blocked on an external project change labels Apr 22, 2024
@philwebb philwebb added this to the 3.1.x milestone Apr 22, 2024
@scottfrederick scottfrederick self-assigned this Apr 23, 2024
@scottfrederick scottfrederick modified the milestones: 3.1.x, 3.1.12 Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants