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

Spike: ENP testing atomic transactions #190

Open
4 tasks
kalbfled opened this issue Mar 5, 2025 · 0 comments
Open
4 tasks

Spike: ENP testing atomic transactions #190

kalbfled opened this issue Mar 5, 2025 · 0 comments
Labels
Dev Reviewed Reviewed by Tech Lead Notify Board trigger PM Reviewed Reviewed by Product Manager QA Reviewed Reviewed by Quality Assurance Ready For Refinement

Comments

@kalbfled
Copy link
Member

kalbfled commented Mar 5, 2025

User Story - Business Goal

  • Ticket is understood, and QA has been contacted (if the ticket has a QA label).

User Story(ies)

As a Notify developer,
I want test database transactions to be atomic by default
So that development is not unnecessarily impeded and I don't have an aneurysm.

Additional Info and Resources

A unit test that manipulates a database generally needs to rollback its changes so they don't affect other tests. In notification-api, we do this with factory fixtures that include teardown (example) and, unfortunately often, with manual teardown in the unit test code. This is laborious and somewhat error prone.

We want to avoid manual test isolation and clean-up with ENP testing. Some web application frameworks, like Django, have built-in support for atomic testing. notification-api, which runs on Flask, used to use a pytest add-on that made tests atomic. However, we removed it because it wasn't maintained and didn't necessarily play well with pytest-xdist, which is used to run tests concurrently.

What options do we have for FastAPI?

Acceptance Criteria & Checklist

  • Technical Documentation has been created and linked in the glossary
  • Learnings have been shared with the team, and decisions have been documented
  • Tickets for next steps have been identified and created

Completed research addresses the problems and/or answers the questions below:

  1. How can we implement unit testing in FastAPI in a way that is atomic? (Changes to the database are rolled back automatically after each test.)
  2. How do various options impact our ability to execute tests in parallel? For example, using pytest-xdist, which we use with notification-api.

Out of scope

Do not worry about preseeding the test database.

@kalbfled kalbfled added the Notify Board trigger label Mar 5, 2025
@cris-oddball cris-oddball added the QA Reviewed Reviewed by Quality Assurance label Mar 5, 2025
@kbelikova-oddball kbelikova-oddball added the PM Reviewed Reviewed by Product Manager label Mar 5, 2025
@k-macmillan k-macmillan added the Dev Reviewed Reviewed by Tech Lead label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dev Reviewed Reviewed by Tech Lead Notify Board trigger PM Reviewed Reviewed by Product Manager QA Reviewed Reviewed by Quality Assurance Ready For Refinement
Projects
None yet
Development

No branches or pull requests

5 participants