diff --git a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java index 8c448692..e39e7c15 100644 --- a/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java +++ b/spring-cloud-task-core/src/test/java/org/springframework/cloud/task/listener/TaskLifecycleListenerTests.java @@ -24,6 +24,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import io.micrometer.observation.Observation; +import io.micrometer.observation.ObservationRegistry; +import io.micrometer.observation.tck.TestObservationRegistry; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -86,6 +89,12 @@ public class TaskLifecycleListenerTests { if (this.context != null && this.context.isActive()) { this.context.close(); } + ObservationRegistry observationRegistry = TestObservationRegistry.create(); + if (observationRegistry.getCurrentObservationScope() != null) { + Observation.Scope scope = observationRegistry.getCurrentObservationScope(); + scope.close(); + scope.getCurrentObservation().stop(); + } } @Test