-
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
Introduce NoOpTaskScheduler for disabling @Scheduled tasks in test setups #28073
Comments
Boot has no control over whether or not scheduling is enabled as it's done in your code via In the meantime, you could structure your code so that your |
I have tried to create this, please look at the patch I am sending. Thank you |
Prior to this commit, only cron @scheduled tasks can be disabled with the special cron expression value that indicates a disabled trigger: "-". This commit enables this configuration to fixedDelay and fixedRate @scheduled tasks. Fixes spring-projectsgh-28073
Spring Framework has support for a no-op cache so I wonder if offering a no-op @wilkinsona if we did that, would you be ok to introduce a similar support in Spring Boot? I am asking as the example of caching is similar and yet Spring Boot is able to provide such a feature. The only difference is the lack of a no-op implementation. |
That sounds fine, I think. I guess we'd do it through a new |
paging @jhoeller to see what he thinks of that idea. |
Introduced |
Thanks, @jhoeller. I've opened spring-projects/spring-boot#38954 on the Boot side. |
If an application defines a
@Scheduled(fixedRateString = "PT6H")
tasks, then this task will be running on any@SpringBootTest
junit
test that does not explicit mock the bean containing the scheduled task.This gets tedious if there are many more
@Scheduled
tasks in the application that launch on startup by usage offixedRate
orfixedRateString
.It would be great if there could be a possibility to completely deactivate the execution of
@Scheduled
tasks in junit.Just like it is possible to deactivate any
@Cacheable
annotation by simply settingspring.cache.type=none
dring junit tests.Something like:
spring.enable.scheduling=false
(default: true)The text was updated successfully, but these errors were encountered: