diff --git a/.github/linters/codespell.txt b/.github/linters/codespell.txt index 3459c9359c..6ae8a35cf1 100644 --- a/.github/linters/codespell.txt +++ b/.github/linters/codespell.txt @@ -2,6 +2,7 @@ afile afterall aline atleast +atmost bais bu crypted diff --git a/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java b/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java index 0e3a09c96e..3b0d65a0ca 100644 --- a/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java +++ b/core/src/test/java/org/apache/shiro/session/mgt/ExecutorServiceSessionValidationSchedulerTest.java @@ -23,7 +23,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.time.Duration; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; @SuppressWarnings("checkstyle:MagicNumber") public class ExecutorServiceSessionValidationSchedulerTest { @@ -47,8 +49,9 @@ void timeoutSessionValidate() throws InterruptedException { Session session = new SimpleSession(); session.setTimeout(2000L); defaultSessionManager.create(session); - Thread.sleep(5000L); - assertThat(defaultSessionManager.getActiveSessions()).isEmpty(); + await().atMost(Duration.ofSeconds(10)) + .pollInterval(Duration.ofMillis(100)) + .untilAsserted(() -> assertThat(defaultSessionManager.getActiveSessions()).isEmpty()); assertThat(executorServiceSessionValidationScheduler.isEnabled()).isTrue(); } @@ -59,8 +62,9 @@ void stopSessionValidate() throws InterruptedException { defaultSessionManager.create(session); Thread.sleep(1000L); session.stop(); - Thread.sleep(3000L); - assertThat(defaultSessionManager.getActiveSessions()).isEmpty(); + await().atMost(Duration.ofSeconds(10)) + .pollInterval(Duration.ofMillis(100)) + .untilAsserted(() -> assertThat(defaultSessionManager.getActiveSessions()).isEmpty()); assertThat(executorServiceSessionValidationScheduler.isEnabled()).isTrue(); } @@ -88,8 +92,9 @@ void threadException() throws InterruptedException { defaultSessionManager.create(session); Thread.sleep(2000L); session.stop(); - Thread.sleep(2000L); - assertThat(defaultSessionManager.getActiveSessions()).isNotEmpty(); + await().atMost(Duration.ofSeconds(10)) + .pollInterval(Duration.ofMillis(100)) + .untilAsserted(() -> assertThat(defaultSessionManager.getActiveSessions()).isNotEmpty()); assertThat(executorServiceSessionValidationScheduler.isEnabled()).isTrue(); }