Skip to content

Commit d22969a

Browse files
committed
Tolerate race condition in shouldStopKeepAliveThreadIfContextIsClosed
See gh-37736
1 parent 4161eb1 commit d22969a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot;
1818

19+
import java.time.Duration;
1920
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.HashMap;
@@ -31,6 +32,7 @@
3132

3233
import jakarta.annotation.PostConstruct;
3334
import org.assertj.core.api.Condition;
35+
import org.awaitility.Awaitility;
3436
import org.junit.jupiter.api.AfterEach;
3537
import org.junit.jupiter.api.BeforeEach;
3638
import org.junit.jupiter.api.Test;
@@ -1423,7 +1425,11 @@ void shouldStopKeepAliveThreadIfContextIsClosed() {
14231425
assertThat(threadsBeforeClose).filteredOn((thread) -> thread.getName().equals("keep-alive")).isNotEmpty();
14241426
this.context.close();
14251427
Set<Thread> threadsAfterClose = getCurrentThreads();
1426-
assertThat(threadsAfterClose).filteredOn((thread) -> thread.getName().equals("keep-alive")).isEmpty();
1428+
Awaitility.await()
1429+
.atMost(Duration.ofSeconds(30))
1430+
.untilAsserted(
1431+
() -> assertThat(threadsAfterClose).filteredOn((thread) -> thread.getName().equals("keep-alive"))
1432+
.isEmpty());
14271433
}
14281434

14291435
private <S extends AvailabilityState> ArgumentMatcher<ApplicationEvent> isAvailabilityChangeEventWithState(

0 commit comments

Comments
 (0)