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

Migrate all tests to use Postgres testcontainers instead of H2 #573

Merged
merged 9 commits into from
Feb 14, 2024

Conversation

nscuro
Copy link
Member

@nscuro nscuro commented Feb 13, 2024

Description

Switches all tests to use Postgres testcontainers instead of H2.

Avoids having to deal with differences between Postgres and H2. Just adds friction considering the application will never run with H2 in production.

Addressed Issue

Contributes to DependencyTrack/hyades#1074

Additional Details

Test execution times in CI only get a minor hit of 3-5min. Containers are re-used across test classes such that container restarts and database migration executions are kept to a minimum.

During this switch, multiple tests started failing due to assumptions that are true for H2 not being true for PostgreSQL. This is a win in my books, as our tests will now be closer to what is running in production.

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@nscuro nscuro added the enhancement New feature or request label Feb 13, 2024
@nscuro nscuro changed the title Switch all tests to use Postgres testcontainers instead of H2 Migrate all tests to use Postgres testcontainers instead of H2 Feb 13, 2024
@nscuro nscuro marked this pull request as ready for review February 13, 2024 18:28
Avoids having to deal with differences between Postgres and H2. Just adds friction considering the application will never run with H2 in production.

Might even be faster since the same container is reused across all test methods in a class, whereas the previous H2 way would re-create the entire database for each test method.

Signed-off-by: nscuro <[email protected]>
Copy link
Collaborator

@sahibamittal sahibamittal left a comment

Choose a reason for hiding this comment

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

LGTM.

@sahibamittal sahibamittal merged commit 3416c4b into main Feb 14, 2024
6 checks passed
@sahibamittal sahibamittal deleted the remove-h2 branch February 14, 2024 13:51
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants