The current threads must be retrieved each time so that we can see
the keep-alive thread dying.

See gh-37736
This commit is contained in:
Andy Wilkinson 2023-10-20 12:57:17 +01:00
parent d13d38a141
commit 9897576562

View File

@ -1421,15 +1421,12 @@ class SpringApplicationTests {
application.setWebApplicationType(WebApplicationType.NONE);
application.setKeepAlive(true);
this.context = application.run();
Set<Thread> threadsBeforeClose = getCurrentThreads();
assertThat(threadsBeforeClose).filteredOn((thread) -> thread.getName().equals("keep-alive")).isNotEmpty();
assertThat(getCurrentThreads()).filteredOn((thread) -> thread.getName().equals("keep-alive")).isNotEmpty();
this.context.close();
Set<Thread> threadsAfterClose = getCurrentThreads();
Awaitility.await()
.atMost(Duration.ofSeconds(30))
.untilAsserted(
() -> assertThat(threadsAfterClose).filteredOn((thread) -> thread.getName().equals("keep-alive"))
.isEmpty());
.untilAsserted(() -> assertThat(getCurrentThreads())
.filteredOn((thread) -> thread.getName().equals("keep-alive")));
}
private <S extends AvailabilityState> ArgumentMatcher<ApplicationEvent> isAvailabilityChangeEventWithState(