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

Shared test resources across tests not being shared #629

Open
jamesdh opened this issue Mar 5, 2024 · 1 comment
Open

Shared test resources across tests not being shared #629

jamesdh opened this issue Mar 5, 2024 · 1 comment

Comments

@jamesdh
Copy link

jamesdh commented Mar 5, 2024

Expected Behavior

Multiple tests that make use of a Postgres container configured via test-resources will share the database container and not restart it for each separate test class. This is the default behavior as described in "Isolating Test Resources" under 5.2 JUnit Platform

Actual Behaviour

Postgres container is restarted for every test class containing a @MicronautTest annotation. This nearly doubles our test runtime. Was able to work around it by appending TC_REUSABLE to the datasource URL as a la: datasources.default.url: jdbc:tc:postgresql:16:///postgres;TC_REUSABLE=true

Steps To Reproduce

  1. Given a fresh application and the following config:
datasources:
  default:
    url: jdbc:tc:postgresql:16:///postgres
    driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
test-resources:
  enabled: true
  containers:
    postgres:
      image-name: postgres:16
  1. Add multiple test classes that make use of @MicronautTest
  2. Run your tests while observing docker and you'll see the Postgres container being shutdown and brought back up in rapid fire succession.

Environment Information

MacOS 14.2.1
Java 21.0.2-tem
Docker Desktop 4.28.0

Example Application

No response

Version

4.3.4

@graemerocher graemerocher transferred this issue from micronaut-projects/micronaut-servlet May 28, 2024
@melix
Copy link
Collaborator

melix commented May 28, 2024

Can you share a complete reproducer? There must be something else at play because this is definitely not how it works (we have a lot of test suites which definitely share the same container).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants