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

Replaced @DirtiesContext with manual reset of H2 database #95

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

BrunoRosendo
Copy link
Member

@BrunoRosendo BrunoRosendo commented Feb 2, 2023

Since @DirtiesContext logic kept bringing issues in the tests, I replaced it with a listener that automatically truncates every table from the H2 test database. Additionally, I had to deactivate an optimization on the entity manager to ensure ID consistency.

Here are the 2 primary sources that inspired this implementation:

This means that the DB will be reset in EVERY single test, as opposed to only between endpoint tests like before. There was no need for an @EndpointTest in this implementation since it's the same as the @NestedTest, so I removed it.

Review checklist

  • Properly documents API changes in docs/openapi.yml
  • Contains enough appropriate tests
  • Behavior is as expected
  • Clean, well structured code

@BrunoRosendo BrunoRosendo force-pushed the feature/test-database-reset branch 2 times, most recently from 3aecafa to b951d94 Compare February 2, 2023 04:40

override fun beforeTestMethod(testContext: TestContext) {
super.beforeTestMethod(testContext)
println("Cleaning up database...")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this show up in the test log?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I change anything or can we merge? This is an important PR @DoStini

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for the delay, it might be a bit cluttered but we can merge

@BrunoRosendo BrunoRosendo force-pushed the feature/test-database-reset branch from b951d94 to 5263529 Compare February 2, 2023 15:28
Copy link
Member

@ttoino ttoino left a comment

Choose a reason for hiding this comment

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

LGTM!

@BrunoRosendo BrunoRosendo requested a review from DoStini February 5, 2023 18:15
@BrunoRosendo BrunoRosendo merged commit 271123e into feature/better-events Feb 6, 2023
@BrunoRosendo BrunoRosendo deleted the feature/test-database-reset branch February 6, 2023 19:02
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.

3 participants