Skip to content

Commit de3d467

Browse files
Merge branch 'master' into alexeyk/protocol-v1-1
2 parents 944e533 + dbb0729 commit de3d467

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

dd-java-agent/instrumentation/spring/spring-scheduling-3.1/src/latestDepTest/groovy/SpringSchedulingTest.groovy

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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"() {

dd-java-agent/instrumentation/spring/spring-scheduling-3.1/src/test/groovy/SpringSchedulingTest.groovy

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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"() {

0 commit comments

Comments
 (0)