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

Application Context initialized twice during test when exception thrown during initialization #31793

Closed
wilkinsona opened this issue Jul 19, 2022 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

SpringBootDependencyInjectionTestExecutionListener tries to do this today but it doesn't work as calling testContext.getApplicationContext() after the failure results in a second attempt to create the context which also fails. #24888 hopes to fix this in 2.x. In 3.0, we can use a new SPI that's been proposed in the test context framework to process the failure.

@wilkinsona wilkinsona added the type: task A general task label Jul 19, 2022
@wilkinsona wilkinsona added this to the 3.0.x milestone Jul 19, 2022
@wilkinsona wilkinsona added the status: blocked An issue that's blocked on an external project change label Jul 19, 2022
@philwebb philwebb modified the milestones: 3.0.x, 3.1.x Oct 5, 2022
@sbrannen
Copy link
Member

sbrannen commented Oct 18, 2022

This issue is no longer blocked since spring-projects/spring-framework#28826 has been pushed to main for inclusion in Spring Framework 6.0 RC2.

As stated in the Javadoc for SmartContextLoader.loadContext(MergedContextConfiguration), the SpringBootContextLoader will need to be updated with a try-catch block in order to throw the newly introduced org.springframework.test.context.ContextLoadException.

In addition, SpringBootTestContextBootstrapper will need to override the newly introduced getApplicationContextFailureProcessor() method to return an ApplicationContextFailureProcessor that replaces the logic currently in SpringBootDependencyInjectionTestExecutionListener.outputConditionEvaluationReport(...).

@wilkinsona
Copy link
Member Author

While DefaultTestExecutionListenersPostProcessor remains in a deprecated form, I think that SpringBootTestContextBootstrapper should continue to discover them via spring.factories and call them.

@wilkinsona wilkinsona reopened this Nov 1, 2022
scottfrederick added a commit that referenced this issue Nov 1, 2022
This commit partially reverts c81ebf6,
so that `DefaultTestExecutionListenersPostProcessor`s are invoked
even though deprecated.

See gh-31793
@sbrannen
Copy link
Member

sbrannen commented Nov 4, 2022

Since this and #32995 effectively fix #24888 (which is a bug), I'm wondering if it wouldn't be better to use a label other than task so that the fix shows up in the automatically generated change log.

@scottfrederick scottfrederick changed the title Use the new SPI for processing ApplicationContext failures to log condition evaluation report Application Context initialized twice during test when exception thrown during initialization Nov 4, 2022
@scottfrederick scottfrederick added type: bug A general bug and removed type: task A general task labels Nov 4, 2022
@scottfrederick scottfrederick reopened this Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants