'spring delay/pause @Scheduled in integration tests until trigger
We have several @Scheduled tasks in our project. In integration tests they throw an exception, because tables cannot be found - which is true, because the integrtion tests clean + set up a database only in @BeforeEach when spring already was started.
We now workaround this issue by using initialDelayString to set a delay if the test profile is active:
@Scheduled(
initialDelayString = "\${scheduler.initialDelay}",
fixedDelay = DELAY_BETWEEN_SCHEDULES
)
However, this is buggy, because we cannot guarantee how long it takes to setup the schema. Setting the initialDelay to e.g. 20 seconds feels very odd.
Is there any way to delay the initial run of @Scheduled until a trigger is set (e.g. db schema created, initial data loaded etc)? And is it possible to stop the schedulers in between tests to wait again for that trigger?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
