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

Remove DatabaseSupport.clean() from unit tests #1327

Merged
merged 85 commits into from
Sep 26, 2024
Merged

Remove DatabaseSupport.clean() from unit tests #1327

merged 85 commits into from
Sep 26, 2024

Conversation

Jozzey
Copy link
Contributor

@Jozzey Jozzey commented Sep 12, 2024

https://eaflood.atlassian.net/browse/WATER-4677

We currently have some unit tests that fail if DatabaseSupport.clean() is not run before each test. This is usually due to duplicate data being added to the DB causing a constraint violation.

Since we have introduced "seeders" to populate some of our reference data. It should now be possible to fix any tests that currently fail without the DB clean. This will speed up the running of the unit tests as it won't have to rebuild the DB after running some of them.

We currently have some unit tests that fail if `DatabaseSupport.clean()` is not run before each test. This is usually due to duplicate data being added to the DB causing a constraint violation.

Since we have introduced "seeders" to populate some of our reference data. It should now be possible to fix any tests that currently fail without the DB clean. This will speed up the running of the unit tests as it won't have to rebuild the DB after running some of them.
@Jozzey Jozzey added the housekeeping Refactoring, tidying up or other work which supports the project label Sep 12, 2024
@Jozzey Jozzey self-assigned this Sep 12, 2024
Jozzey and others added 27 commits September 12, 2024 11:31
The test was trying to check for an exact amount of records, which isn't possible without clearing the DB. Changed the test so that it is now checking for at least the amount of records it's expecting as that will cover it.
Jozzey and others added 14 commits September 23, 2024 15:32
As the unit tests were creating and checking for bill runs in real regions. When other tests were run in parallel this unit test would intermittently fail if other unit tests created bill runs in the same region.

As this service is not reliant on having the actual region data. A randomly generated ID is used for the region to prevent other tests from effecting the results.
This test was failing locally, but passing on GitHub due to a typo which should have been setting the `enableTwoPartTariffSupplementary` feature flag that most of us have set to 'true' locally to `false`.
Some tests were failing intermittently due to `duplicate key value violates unique constraint "licence_versions_external_id_unique"`
….js`

Because a lot of the other tests use random regions these tests have been intermittently failing when other tests create conflicting data. We have therefore switched to using the bill runs region as this is not selected randomly so the amount of data created in this region is kept to a minimum.

As few tests use this region it is relatively safe to remove test data once created without impacting other tests that may be running.
…ce.test.js`

Every now and then I think that another test is doing something with the supplementary flags which is causing this test to fail. To sort out the issue I'm using a dummy region id to minimise other tests interfering with this one. I'm also clearing out the data after the test so the fake region doesn't cause any issues with other tests that may require region data for licences.
@Jozzey Jozzey marked this pull request as ready for review September 25, 2024 16:06
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one little NIT. But this is outstanding work!

@Jozzey Jozzey requested a review from Cruikshanks September 26, 2024 08:36
Jozzey and others added 4 commits September 26, 2024 09:36
This intermittent failure was caused because when populating `invalidSecondaryPurpose` from the helper no purpose was specified so it was using a random one. Unfortunately every now and then the random one was actually the valid one with the `legacyId` being `ELC`
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jozzey Jozzey merged commit ac262b6 into main Sep 26, 2024
6 checks passed
@Jozzey Jozzey deleted the remove-db-clean branch September 26, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants