-
Notifications
You must be signed in to change notification settings - Fork 7
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
[2398] Reduce test run times by preventing migration after each test #2399
Conversation
This commit leverages Micronaut TestResources to manage the postgres database container for the tests. This means that the container will exist across all the tests and so we save time waiting for it to start up and migrate each test class. Locally I have seen the time to run all the tests drop from 4m55s to 2m11s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me. It does look like the tests are having issues connecting to the DB on the CI if you haven't already seen it yet.
I was curious how this change ensures the container is shared across all tests. I figured that static block where the container was originally initialized would've been shared as well. Not too familiar with how test resources are working under the hood for Micronaut though, but this certainly would be far simpler for my future reference.
Edit: I suppose because @MicronautTest is spinning up a new application context each time so the static doesn't actually stick?
server/src/test/java/com/objectcomputing/checkins/services/TestContainersSuite.java
Show resolved
Hide resolved
Ahhh... the failures are because I was running the local db (via docker-compose) and now that we're not specifying the URL in the test yaml, it's falling back to using the URL from application.yml in the non-test source... This is looking for a database on localhost:5432 -- which doesn't exist (when you aren't running docker compose up locally) :-( |
Micronaut Test Resources works by catching unknown properties at run time, and firing up a container if it can support the property evaluation. These containers by default last the length of the build, and are closed when it completes. So if a datasource is required, but However I didn't spot that So instead, to speed up the tests
We still have quite a few tests that do not extend |
Front end snapshot tests are failing... Looks like they're failing on develop too after d9e2acd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work. On the same hardware it got from 6 to 4 minutes.
@timyates Thanks for the additional explanation. It sounds like if we just removed the url configuration from application.yml, and into application-dev.yml it would allow you to go with your original approach? This is great though, and I don't think that is something we need to deal with today by any means. I'm not too familiar with how they are configuring their gcloud environments. |
Yes, or we could remove the configuration totally, and test-resources would also spin up a database automatically when we ran it with However I'm also not sure how the database is configured in prod, and I got scared to touch the config there 😉 |
This commit leverages Micronaut TestResources to manage the postgres database container for the tests.This PR shares the container in
TestContainerSuite
between all sub-classes.It fixes the
TestPropertyProvider
usage, and makes use of the TestContainers singleton patternOn my maching the tests go from 4m45s to 3m20s (30% speedup)