From 05b553dbde18d386256ea8103113bed087a2d2ae Mon Sep 17 00:00:00 2001 From: Glenn Renfro Date: Wed, 5 Jul 2023 15:05:22 -0400 Subject: [PATCH] Closed an observation left open in TaskListener task This caused observation tests to fail after test reshuffling. --- .../task/listener/TaskLifecycleListenerTests.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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..db25e0da 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 @@ -183,6 +192,7 @@ public class TaskLifecycleListenerTests { @Test public void testRestartExistingTask(CapturedOutput capturedOutput) { this.context.refresh(); + TaskLifecycleListener taskLifecycleListener = this.context.getBean(TaskLifecycleListener.class); taskLifecycleListener.start(); String output = capturedOutput.toString();