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

Reliable test data clear down #215

Merged
merged 38 commits into from
May 11, 2023
Merged

Reliable test data clear down #215

merged 38 commits into from
May 11, 2023

Conversation

Jozzey
Copy link
Contributor

@Jozzey Jozzey commented May 9, 2023

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

Using the existing acceptance tests a common issue we face is that we can’t clear down the existing test data. Because of the solution previously implemented, it only focuses on data flagged as is_test === true. The problem is when using this data for test purposes you will often create related data that is not flagged as is_test. This leads to errors in the existing clear down process that we then have to create a and run manual SQL delete scripts to deal with.

If we’re often having to write SQL delete scripts manually, and these deal with the foreign key constraints that the existing process isn’t handling, it makes sense to us to use them always rather than the existing brittle process.

This PR creates an endpoint at /data/tear-down. To run locally, send a POST request to http://localhost:8013/data/tear-down.

Jozzey and others added 16 commits April 26, 2023 11:08
https://eaflood.atlassian.net/browse/WATER-3982

Using the existing acceptance tests a common issue we face is that we can’t clear down the existing test data. Because of the solution previously implemented, it only focuses on data flagged as `is_test === true`. The problem is when using this data for test purposes you will often create related data that is not flagged as `is_test`. This leads to errors in the existing clear down process that we then have to create a and run manual SQL delete scripts to deal with.

If we’re often having to write SQL delete scripts manually, and these deal with the foreign key constraints that the existing process isn’t handling, it makes sense to us to use them always rather than the existing brittle process.
@Jozzey Jozzey added the enhancement New feature or request label May 9, 2023
@Jozzey Jozzey self-assigned this May 9, 2023
@Jozzey
Copy link
Contributor Author

Jozzey commented May 9, 2023

I've had a word with @Cruikshanks about the test coverage on the schema services. As they are just for deleting test data we've agreed that they are not worth spending time on full unit testing since this would involve significant work in creating the new schemas/data in the test DB.

Testing has been added but just at the high level tear-down service and the controller.

@Jozzey Jozzey marked this pull request as ready for review May 9, 2023 16:24
@Jozzey Jozzey marked this pull request as draft May 10, 2023 12:03
@Jozzey Jozzey marked this pull request as ready for review May 10, 2023 14:43
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 some minor changes! I can't wait to give it a spin when done 😁

app/controllers/data/data.controller.js Show resolved Hide resolved
app/plugins/router.plugin.js Outdated Show resolved Hide resolved
app/routes/data.routes.js Outdated Show resolved Hide resolved
test/controllers/data/data.controller.test.js Outdated Show resolved Hide resolved
@Jozzey Jozzey requested a review from Cruikshanks May 11, 2023 10:44
@Jozzey Jozzey merged commit 526d60c into main May 11, 2023
@Jozzey Jozzey deleted the test-data-tear-down-take2 branch May 11, 2023 13:18
Cruikshanks added a commit to DEFRA/water-abstraction-acceptance-tests that referenced this pull request Jun 13, 2023
https://eaflood.atlassian.net/browse/WATER-3982

Using the existing acceptance tests a common issue we face is that we can't clear down the existing test data. Because of the solution previously implemented, it only focuses on data flagged as `is_test === true`. The problem is when using this data for test purposes you will often create related data that is not flagged as `is_test`. This leads to errors in the existing clear down process that we then have to create and run manual SQL delete scripts to deal with.

On top of that everything is driven through the network calls across the services. We know they haven't been properly isolated as they should have if micro-services was the intent. Knowing that we can improve the performance by just using direct SQL calls to do the tear down.

So we added a [Reliable test data clear down](DEFRA/water-abstraction-system#215) endpoint to the **water-abstraction-system** app.

This change updates the acceptance tests to use it rather than the old mechanism. Timings will vary across machines and environments. But so far our tests all show the new endpoint is quicker leading to a reduced runtime for all tests.
Cruikshanks added a commit to DEFRA/water-abstraction-acceptance-tests that referenced this pull request Jun 13, 2023
https://eaflood.atlassian.net/browse/WATER-3982

Using the existing acceptance tests a common issue we face is that we can't clear down the existing test data. Because of the solution previously implemented, it only focuses on data flagged as `is_test === true`. The problem is when using this data for test purposes you will often create related data that is not flagged as `is_test`. This leads to errors in the existing clear-down process that we then have to create and run manual SQL delete scripts to deal with.

On top of that everything is driven through the network calls across the services. We know they haven't been properly isolated as they should have if micro-services was the intent. Knowing that we can improve the performance by just using direct SQL calls to do the teardown.

So we added a [Reliable test data clear down](DEFRA/water-abstraction-system#215) endpoint to the **water-abstraction-system** app.

This change updates the acceptance tests to use it rather than the old mechanism. Timings will vary across machines and environments. But so far our tests all show the new endpoint is quicker leading to a reduced runtime for all tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants