File tree Expand file tree Collapse file tree
dd-java-agent/instrumentation/spring/spring-scheduling-3.1/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,8 +25,14 @@ class SpringSchedulingTest extends InstrumentationSpecification {
2525 setup :
2626 def context = new AnnotationConfigApplicationContext (TriggerTaskConfig , SchedulingConfig )
2727 def task = context. getBean(TriggerTask )
28+ def scheduledTaskEndpoint = context. getBean(ScheduledTasksEndpoint )
2829
2930 task. blockUntilExecute()
31+ // Capture cron tasks before closing the context (endpoint is unavailable after close).
32+ def cronTasks = scheduledTaskEndpoint. scheduledTasks(). getCron()
33+ // Close the context immediately after the first execution to prevent a second cron
34+ // firing before assertions complete, which would produce extra traces and cause flakiness.
35+ context. close()
3036
3137 expect :
3238 assert task != null
@@ -54,13 +60,10 @@ class SpringSchedulingTest extends InstrumentationSpecification {
5460 }
5561 }
5662 and :
57- def scheduledTaskEndpoint = context. getBean(ScheduledTasksEndpoint )
5863 assert scheduledTaskEndpoint != null
59- scheduledTaskEndpoint . scheduledTasks() . getCron() . each {
64+ cronTasks . each {
6065 it. getRunnable(). getTarget() == TriggerTask . getName()
6166 }
62- cleanup :
63- context. close()
6467 }
6568
6669 def " schedule interval test" () {
Original file line number Diff line number Diff line change @@ -25,8 +25,14 @@ class SpringSchedulingTest extends InstrumentationSpecification {
2525 setup :
2626 def context = new AnnotationConfigApplicationContext (TriggerTaskConfig , SchedulingConfig )
2727 def task = context. getBean(TriggerTask )
28+ def scheduledTaskEndpoint = context. getBean(ScheduledTasksEndpoint )
2829
2930 task. blockUntilExecute()
31+ // Capture cron tasks before closing the context (endpoint is unavailable after close).
32+ def cronTasks = scheduledTaskEndpoint. scheduledTasks(). getCron()
33+ // Close the context immediately after the first execution to prevent a second cron
34+ // firing before assertions complete, which would produce extra traces and cause flakiness.
35+ context. close()
3036
3137 expect :
3238 assert task != null
@@ -54,13 +60,10 @@ class SpringSchedulingTest extends InstrumentationSpecification {
5460 }
5561 }
5662 and :
57- def scheduledTaskEndpoint = context. getBean(ScheduledTasksEndpoint )
5863 assert scheduledTaskEndpoint != null
59- scheduledTaskEndpoint . scheduledTasks() . getCron() . each {
64+ cronTasks . each {
6065 it. getRunnable(). getTarget() == TriggerTask . getName()
6166 }
62- cleanup :
63- context. close()
6467 }
6568
6669 def " schedule interval test" () {
You can’t perform that action at this time.
0 commit comments