Skip to content

Commit 845b5c6

Browse files
committed
Close thread pool executor in observationShouldNotLeakToFutureCompletionThread test
Signed-off-by: Maksim Petelin <[email protected]>
1 parent e14c501 commit 845b5c6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

samples/micrometer-samples-spring-framework6/src/test/java/io/micrometer/samples/spring6/aop/ObservedAspectTests.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,16 @@ void observationShouldNotLeakToFutureCompletionThread() {
178178

179179
ObservedService service = pf.getProxy();
180180
FakeAsyncTask fakeAsyncTask = new FakeAsyncTask("test-result");
181-
Executor sameThreadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
182-
CompletableFuture<String> asyncResult = service
183-
.parent(() -> service.asyncChild(fakeAsyncTask, sameThreadExecutor));
184-
CompletableFuture<Void> asyncAssertion = asyncResult
185-
.thenRunAsync(() -> assertThat(registry).doesNotHaveAnyRemainingCurrentObservation(), sameThreadExecutor);
186-
fakeAsyncTask.proceed();
187-
fakeAsyncTask.get();
188181

189-
assertThat(asyncAssertion).succeedsWithin(Duration.ofMillis(200));
182+
try (var sameThreadExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>())) {
183+
CompletableFuture<String> asyncResult = service
184+
.parent(() -> service.asyncChild(fakeAsyncTask, sameThreadExecutor));
185+
CompletableFuture<Void> asyncAssertion = asyncResult.thenRunAsync(
186+
() -> assertThat(registry).doesNotHaveAnyRemainingCurrentObservation(), sameThreadExecutor);
187+
fakeAsyncTask.proceed();
188+
189+
assertThat(asyncAssertion).succeedsWithin(Duration.ofMillis(200));
190+
}
190191
}
191192

192193
@Test

0 commit comments

Comments
 (0)