Skip to content

Commit 072361c

Browse files
bm1549claude
andcommitted
Fix ConditionNotSatisfiedError by capturing cron tasks before context close
The scheduledTaskEndpoint.scheduledTasks() call fails after context.close() because the endpoint is no longer available. Capture the cron tasks list in setup: before closing the context so the and: assertion block uses the pre-captured value. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent aa57bcf commit 072361c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SpringSchedulingTest extends InstrumentationSpecification {
2828
def scheduledTaskEndpoint = context.getBean(ScheduledTasksEndpoint)
2929

3030
task.blockUntilExecute()
31+
// Capture cron tasks before closing the context (endpoint is unavailable after close).
32+
def cronTasks = scheduledTaskEndpoint.scheduledTasks().getCron()
3133
// Close the context immediately after the first execution to prevent a second cron
3234
// firing before assertions complete, which would produce extra traces and cause flakiness.
3335
context.close()
@@ -59,7 +61,7 @@ class SpringSchedulingTest extends InstrumentationSpecification {
5961
}
6062
and:
6163
assert scheduledTaskEndpoint != null
62-
scheduledTaskEndpoint.scheduledTasks().getCron().each {
64+
cronTasks.each {
6365
it.getRunnable().getTarget() == TriggerTask.getName()
6466
}
6567
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SpringSchedulingTest extends InstrumentationSpecification {
2828
def scheduledTaskEndpoint = context.getBean(ScheduledTasksEndpoint)
2929

3030
task.blockUntilExecute()
31+
// Capture cron tasks before closing the context (endpoint is unavailable after close).
32+
def cronTasks = scheduledTaskEndpoint.scheduledTasks().getCron()
3133
// Close the context immediately after the first execution to prevent a second cron
3234
// firing before assertions complete, which would produce extra traces and cause flakiness.
3335
context.close()
@@ -59,7 +61,7 @@ class SpringSchedulingTest extends InstrumentationSpecification {
5961
}
6062
and:
6163
assert scheduledTaskEndpoint != null
62-
scheduledTaskEndpoint.scheduledTasks().getCron().each {
64+
cronTasks.each {
6365
it.getRunnable().getTarget() == TriggerTask.getName()
6466
}
6567
}

0 commit comments

Comments
 (0)