-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Avoid repeated attempts to load a failing ApplicationContext
in the TestContext framework [SPR-9548]
#14182
Comments
muhamadto commented Is there any update on when this enhancement might be added? |
Michael Tecourt commented This feature would really speed up feedback of failing integration tests on a complete Spring (Boot) application. We also let Spring start embedded databases or TestContainers rather than JUnit rules because the same context is reused for all test classes, when a JUnit class rule is reloaded for each test class. |
Sam Brannen commented I've moved this to the 5.x Backlog in order to look into this in the 5.x time frame. |
Related discussion on Stack Overflow. |
Any progress on this would be highly appreciated as it unnecessarily prolongs build times and is hurting effectivity quite badly...
But that is not the same thing as it just stops after the first test vs. executing all tests (but doing this in a fast way if we know the context won't start) |
Update: current work on this feature can be viewed in the following feature branch. main...sbrannen:spring-framework:issues/gh-14182-TCF-context-load-failure-threshold |
ApplicationContext
in the TestContext framework [SPR-9548]
ApplicationContext
in the TestContext framework [SPR-9548]ApplicationContext
in the TestContext framework [SPR-9548]
This commit introduces initial support for a new "context failure threshold" feature in the Spring TestContext Framework (TCF). Specifically, DefaultCacheAwareContextLoaderDelegate now tracks how many times a failure occurs when attempting to load an ApplicationContext and preemptively throws an IllegalStateException for subsequent attempts to load the same context if the configured failure threshold has been exceeded. See spring-projectsgh-14182
This commit makes the failure threshold value configurable via a JVM system property or Spring property named "spring.test.context.failure.threshold". See spring-projectsgh-14182
If you've voted for this issue, you'll be happy to know that... Spring Framework 6.1 will finally have "test context failure threshold" support! 🍃 🥳 It's been a long time coming, but you can now rest assured that your test suite won't take forever due to failing For details, check out the documentation and the related commit. |
In the previous commit which introduced the new context failure threshold support in the TestContext framework, the context failure tracking was tied to an instance of DefaultCacheAwareContextLoaderDelegate. Consequently, the feature was only supported within a given test class. This commit therefore moves context failure tracking to the ContextCache SPI (and DefaultContextCache) so that the feature applies to all test classes within the current test suite (i.e., JVM). This commit also includes the total failure count in the statistics logged by the DefaultContextCache. See gh-14182
Mukarram Baig opened SPR-9548 and commented
Lets say I have a test class called
ServiceTest
with three test methodstest1
,test2
, andtest3
. All three methods use some resources which are provided by Spring. In the current state of affairs, if there is a problem with the loading of the spring context, the context load is retried for each test method.Is there a way that I can have it aborted on the first failure itself with existing hook-ins?
There might be good reasons behind it - but I fail to appreciate it. Any pointers would be helpful.
The real problem is that the context load takes a few minutes, and it is useless to keep reattempting to load the context if it has already failed for the first time and only seeks to prolong the time that the CI server takes to report failures.
I was thinking of having an
attemptMap
inContextCache
that theTestContext
modifies when it encounters a failedApplicationContext
. A repeated load will be (on an opt-in flag set) disallowed via an exception. I have attached a rudimentary patch to indicate what I meant. Sorry that I haven't tested it (don't have gradle installed or an IDE plugin that can do it for me - am still a maven boy :))Affects: 3.1 GA
Reference URL: http://stackoverflow.com/questions/11202535/ability-to-avoid-repeated-load-of-application-context-in-spring-testcontext-via
Attachments:
6 votes, 8 watchers
The text was updated successfully, but these errors were encountered: