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

test: Change test isolation model to 'database per test' #220

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Jan 2, 2024

Improve the reliability and performance of the test suite by moving the test isolation model from 'container per test' to 'database per test'.

The current test suite works well locally but is very flaky when run on Github Actions. The cause of the flakiness is the 'container per test' isolation model, under which each testcase in each test starts its own Postgres container. This model worked well initially but as the number of tests has increased the actions runner often fails to make available the required number of containers for such a large number of parallel tests.

This PR changes the isolation model to 'database per test'. Each package creates one Postgres container and then each testcase in each test creates a database within that container. This greatly reduces the number of simultaneous containers required, making the test suite faster and more reliable.

Each job in the test matrix sees a 60-70% reduction in duration and (anecdotally) far fewer failures with no failures observed in ~20 runs.

Add a `testutils` package containing a shared `TestMain` function and
the `with*` functions used by tests in other packages.

The `SharedTestMain` function creates a new postgres container.

Each of the `with*` functions then creates a new database in that
container for the purposes of the test.
Use the new `testutils.With*` functions in tests in all packages.
@andrew-farries andrew-farries requested a review from exekias January 2, 2024 16:48
@andrew-farries andrew-farries merged commit f4c37b8 into main Jan 8, 2024
22 checks passed
@andrew-farries andrew-farries deleted the db-per-test branch January 8, 2024 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants