Avoid resetting repository beans #2578
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
. OftentimesspringSecurityFilterChain
depends on someUserRepository
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 invalidatespringSecurityFilterChain
bean, which depends on the resetUserRepository
, causing all later executions to fail withAlreadyBuiltException
indicating thatspringSecurityFilterChain
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 oforg.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