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

Consider automatically applying @DirtiesContext to Testcontainer tests #38237

Open
philwebb opened this issue Nov 6, 2023 · 3 comments
Open
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Milestone

Comments

@philwebb
Copy link
Member

philwebb commented Nov 6, 2023

See #38176 for an example of a problem caused by a mismatch of the test containers and spring lifecycle. It would be nice if we could prevent users from hitting the same problem.

@philwebb philwebb added the type: enhancement A general enhancement label Nov 6, 2023
@philwebb philwebb added this to the 3.x milestone Nov 6, 2023
@wilkinsona wilkinsona changed the title Consier automatically applying @DirtiesContext to test container tests Consider automatically applying @DirtiesContext to Testcontainer tests Nov 6, 2023
@kth496
Copy link

kth496 commented Jan 22, 2024

@philwebb This seems interesting, can I take this issue?

After a quick look, I think I can solve it by creating a class that inherits from 'AbstractTestExecutionListener'. Something like 'TestcontainersTestExecutionListener' similar to 'DirtiesContextTestExecutionListener'... Is it okay to proceed in this way?

@philwebb
Copy link
Member Author

@kth496 I'd like to discuss this issue a little more as a team before we make any concrete decisions.

@philwebb philwebb added status: pending-design-work Needs design work before any code can be developed for: team-meeting An issue we'd like to discuss as a team to make progress labels Jan 22, 2024
@xak2000
Copy link
Contributor

xak2000 commented Feb 26, 2024

@philwebb What do you mean by

automatically applying @DirtiesContext to Testcontainer tests

If you mean that any test class that is annotated with @Testcontainers will be automatically marked with @DirtiesContext (even if not explicitly marked), then I think this is not a good idea. If you mean something else, then sorry for pinging.

I think, the lifecycle mismatch between Spring context shutdown and Testcontainers shutdown should be fixed in some other way. In a way that will make sure that containers are not stopped before Spring contexts are fully stopped.

This is especially important for containers with DB with migration applied. Usually such container is started only once per all integration tests. Marking every integration test with @DirtiesContext, while is cleaner solution, will force all DB migrations to run again and again (not speaking about context startup time itself).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants