Closed timyates closed 1 month ago
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 datasources.default.url
is not defined, then the test resources server is queried, and based on the datasources.default.dbType
config, a database container is started, and the url is resolved.
However I didn't spot that datasources.default.url
has a value in application.yml
(it is set to the JDBC_URL
environment variable or falls back to a localhost connection url), so TestResources is never queried for a value for the property, so a container isn't started. It was working for me locally as I had a database running... 🙄
So instead, to speed up the tests
@TestContainers
and @Container
annotations... These will cycle the container after each classWe still have quite a few tests that do not extend TestContainerSuite
and these fire up a new container... I wonder if they should extend the suite instead
Front end snapshot tests are failing... Looks like they're failing on develop too after https://github.com/objectcomputing/check-ins/commit/d9e2acd653003dd89216e05726b30a1f0480a1f9
@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.
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?
Yes, or we could remove the configuration totally, and test-resources would also spin up a database automatically when we ran it with ./gradlew server:run
.
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)