Browse Source

Polish d22969ae

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

See gh-37736
pull/37984/head
Andy Wilkinson 2 years ago
parent
commit
9897576562
  1. 9
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

9
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

@ -1421,15 +1421,12 @@ class SpringApplicationTests { @@ -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(

Loading…
Cancel
Save