From 313def717c4c3f77311d209f1070a14723b0e690 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 29 Feb 2024 16:39:41 +0100 Subject: [PATCH] Issue #11463 Fix flaky session tests --- .../jetty/ee10/session/DuplicateCookieTest.java | 14 +++++++------- .../jetty/ee10/session/SessionRenewTest.java | 8 +++++--- .../jetty/ee9/session/DuplicateCookieTest.java | 15 ++++++--------- .../jetty/ee9/session/SessionRenewTest.java | 7 ++++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java index 42bcc133ea5..a32496a8b0e 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/DuplicateCookieTest.java @@ -190,7 +190,7 @@ public class DuplicateCookieTest assertEquals("1122", response.getContentAsString()); //check valid session is drained of requests - assertEquals(0, s1122.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1122::getRequests, Matchers.is(0L)); } finally { @@ -251,7 +251,7 @@ public class DuplicateCookieTest assertEquals("1122", response.getContentAsString()); //check valid session drained of requests - assertEquals(0, s1122.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1122::getRequests, Matchers.is(0L)); } finally { @@ -311,7 +311,7 @@ public class DuplicateCookieTest assertEquals("1122", response.getContentAsString()); //check valid session drained of requests - assertEquals(0, s1122.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1122::getRequests, Matchers.is(0L)); } finally { @@ -368,9 +368,9 @@ public class DuplicateCookieTest assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus()); //check that all sessions have their request counts decremented correctly after the request, back to 0 - assertEquals(0, s1234.getRequests()); - assertEquals(0, s5678.getRequests()); - assertEquals(0, s9111.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1234::getRequests, Matchers.is(0L)); + await().atMost(5, TimeUnit.SECONDS).until(s5678::getRequests, Matchers.is(0L)); + await().atMost(5, TimeUnit.SECONDS).until(s9111::getRequests, Matchers.is(0L)); } finally { @@ -419,7 +419,7 @@ public class DuplicateCookieTest assertEquals(HttpServletResponse.SC_OK, response.getStatus()); //check that all valid sessions have their request counts decremented correctly after the request, back to 0 - assertEquals(0, s1234.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1234::getRequests, Matchers.is(0L)); } finally { diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java index d07d1981860..85ed9c8b0b6 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-sessions/jetty-ee10-test-sessions-common/src/test/java/org/eclipse/jetty/ee10/session/SessionRenewTest.java @@ -42,8 +42,10 @@ import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; import org.eclipse.jetty.session.test.TestSessionDataStore; import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -190,10 +192,10 @@ public class SessionRenewTest ManagedSession sessiona = ((TestSessionCache)contextA.getSessionHandler().getSessionCache()).getWithoutReferenceCount(updatedId); ManagedSession sessionb = ((TestSessionCache)contextB.getSessionHandler().getSessionCache()).getWithoutReferenceCount(updatedId); - //sessions should nor have any usecounts - assertEquals(0, sessiona.getRequests()); - assertEquals(0, sessionb.getRequests()); + //sessions should nor have any usecounts + await().atMost(5, TimeUnit.SECONDS).until(sessiona::getRequests, Matchers.is(0L)); + await().atMost(5, TimeUnit.SECONDS).until(sessionb::getRequests, Matchers.is(0L)); } finally { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java index 94401ab8d4d..48ccf5f2337 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/DuplicateCookieTest.java @@ -52,7 +52,6 @@ public class DuplicateCookieTest { public class TestSession extends ManagedSession { - public TestSession(SessionManager manager, SessionData data) { super(manager, data); @@ -66,7 +65,6 @@ public class DuplicateCookieTest public class TestSessionCache extends DefaultSessionCache { - public TestSessionCache(SessionManager manager) { super(manager); @@ -81,7 +79,6 @@ public class DuplicateCookieTest public class TestSessionCacheFactory extends DefaultSessionCacheFactory { - @Override public SessionCache newSessionCache(SessionManager manager) { @@ -190,7 +187,7 @@ public class DuplicateCookieTest assertEquals("1122", response.getContentAsString()); //check valid session is drained of requests - assertEquals(0, s1122.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1122::getRequests, Matchers.is(0L)); } finally { @@ -251,7 +248,7 @@ public class DuplicateCookieTest assertEquals("1122", response.getContentAsString()); //check valid session drained of requests - assertEquals(0, s1122.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1122::getRequests, Matchers.is(0L)); } finally { @@ -311,7 +308,7 @@ public class DuplicateCookieTest assertEquals("1122", response.getContentAsString()); //check valid session drained of requests - assertEquals(0, s1122.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1122::getRequests, Matchers.is(0L)); } finally { @@ -368,9 +365,9 @@ public class DuplicateCookieTest assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus()); //check that all sessions have their request counts decremented correctly after the request, back to 0 - assertEquals(0, s1234.getRequests()); - assertEquals(0, s5678.getRequests()); - assertEquals(0, s9111.getRequests()); + await().atMost(5, TimeUnit.SECONDS).until(s1234::getRequests, Matchers.is(0L)); + await().atMost(5, TimeUnit.SECONDS).until(s5678::getRequests, Matchers.is(0L)); + await().atMost(5, TimeUnit.SECONDS).until(s9111::getRequests, Matchers.is(0L)); } finally { diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java index a54e83ff867..2443af49a6e 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-sessions/jetty-ee9-test-sessions-common/src/test/java/org/eclipse/jetty/ee9/session/SessionRenewTest.java @@ -42,8 +42,10 @@ import org.eclipse.jetty.session.SessionDataStoreFactory; import org.eclipse.jetty.session.SessionManager; import org.eclipse.jetty.session.test.TestSessionDataStore; import org.eclipse.jetty.session.test.TestSessionDataStoreFactory; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; +import static org.awaitility.Awaitility.await; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -192,9 +194,8 @@ public class SessionRenewTest ManagedSession sessionb = ((TestSessionCache)contextB.getSessionHandler().getSessionManager().getSessionCache()).getWithoutReferenceCount(updatedId); //sessions should nor have any usecounts - assertEquals(0, sessiona.getRequests()); - assertEquals(0, sessionb.getRequests()); - + await().atMost(5, TimeUnit.SECONDS).until(sessiona::getRequests, Matchers.is(0L)); + await().atMost(5, TimeUnit.SECONDS).until(sessionb::getRequests, Matchers.is(0L)); } finally {