Browse Source

Tolerate race condition in shouldStopKeepAliveThreadIfContextIsClosed

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

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

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.boot;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -31,6 +32,7 @@ import java.util.function.Supplier; @@ -31,6 +32,7 @@ import java.util.function.Supplier;
import jakarta.annotation.PostConstruct;
import org.assertj.core.api.Condition;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -1423,7 +1425,11 @@ class SpringApplicationTests { @@ -1423,7 +1425,11 @@ class SpringApplicationTests {
assertThat(threadsBeforeClose).filteredOn((thread) -> thread.getName().equals("keep-alive")).isNotEmpty();
this.context.close();
Set<Thread> threadsAfterClose = getCurrentThreads();
assertThat(threadsAfterClose).filteredOn((thread) -> thread.getName().equals("keep-alive")).isEmpty();
Awaitility.await()
.atMost(Duration.ofSeconds(30))
.untilAsserted(
() -> assertThat(threadsAfterClose).filteredOn((thread) -> thread.getName().equals("keep-alive"))
.isEmpty());
}
private <S extends AvailabilityState> ArgumentMatcher<ApplicationEvent> isAvailabilityChangeEventWithState(

Loading…
Cancel
Save