Skip to content

Avoid resetting repository beans #2578

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

Merged
merged 1 commit into from
Sep 8, 2023

Conversation

IlyaMuravjov
Copy link
Collaborator

Description

Fixes #2577

When generating Spring-specific integration tests (that are tests that start real Spring application and inject dependencies, e.g. repositories), to avoid executions affecting each other we reset relevant beans between executions.

However, bean factories in Spring may themselves be tasteful and allow certain beans to be created only once, such is factory for springSecurityFilterChain. Oftentimes springSecurityFilterChain depends on some UserRepository that is directly or indirectly used by the good portion of the controllers in the application under test.

When we test the controller that depends on that UserRepository and try to reset it we also invalidate springSecurityFilterChain bean, which depends on the reset UserRepository, causing all later executions to fail with AlreadyBuiltException indicating that springSecurityFilterChain can't be created a second time (see #2577).

Resetting bean factories is to be discussed later.

For now, this PR deals with said problem by not resetting spring-data repository beans (i.e. implementers of org.springframework.data.repository.Repository), since repository content should be reset anyway, because we run each execution in a separate transaction, that is rolled back when execution ends.

How to test

Manual tests

Issue #2577 should no longer reproduce.

Self-check list

  • I've set the proper labels for my PR (at least, for category and component).
  • PR title and description are clear and intelligible.
  • I've added enough comments to my code, particularly in hard-to-understand areas.
  • The functionality I've repaired, changed or added is covered with automated tests.
  • Manual tests have been provided optionally.
  • The documentation for the functionality I've been working on is up-to-date.

@IlyaMuravjov IlyaMuravjov added comp-instrumented-process Issue is related to Instrumented process ctg-bug-fix PR is fixing a bug comp-spring Issue is related to Spring projects support labels Sep 5, 2023
@IlyaMuravjov IlyaMuravjov merged commit 1a605eb into main Sep 8, 2023
@IlyaMuravjov IlyaMuravjov deleted the ilya_m/avoid-repository-bean-reset branch September 8, 2023 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-instrumented-process Issue is related to Instrumented process comp-spring Issue is related to Spring projects support ctg-bug-fix PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AlreadyBuiltException when generating integration tests for UserController
2 participants