spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Make use of NoOpTaskScheduler to disable task scheduling in tests

Open wilkinsona opened this issue 2 years ago • 6 comments

A NoOpTaskScheduler has been added to Spring Framework. We should look at how we can use it to disable scheduled tasks in integration tests (and perhaps at runtime as well) probably via some opt-in mechanism.

wilkinsona avatar Jan 02 '24 14:01 wilkinsona

Hey, I'd like to start working on this enhancement. Would you be able to assign it to me @wilkinsona?

breader124 avatar Mar 21 '24 23:03 breader124

Thanks for the offer, @breader124, but I don't think we know how we want to implement this one yet. Unfortunately, other higher priority work means that we don't have the cycles to figure that out right now. If you have some time to sketch out some ideas when that would be great, but please be aware that it may be wasted effort if we decide to take a different direction.

wilkinsona avatar Mar 22 '24 08:03 wilkinsona

I'm happy to help. I'll try to think about possible solutions and will post them here to review when I'm ready

breader124 avatar Mar 25 '24 16:03 breader124

@wilkinsona, I did some investigation and it seems that a reasonable solution would be to introduce spring.task.scheduling.enabled property and based on its value:

  • create either ThreadPoolTaskScheduler or SimpleAsyncTaskScheduler bean when the new property is not explicitly set to false or when it's missing
  • create the bean of type NoOpTaskScheduler when the property is explicitly set to false

I also propose to leave the creation of all beans of TaskSchedulerBuilder type when scheduling is disabled. If anyone injects them for any reason, it'd be problematic when they disappear after setting the spring.task.scheduling.enabled to false.

How does it sound to you? Do you see more aspects to consider?

breader124 avatar Apr 18 '24 20:04 breader124

Hey @philwebb, is there any news on the topic?

breader124 avatar May 07 '24 20:05 breader124

@breader124 We discussed the issue and would like to do something in 3.4. We can't really start work on it until 3.3 is out.

philwebb avatar May 08 '24 17:05 philwebb