Skip to content

Commit

Permalink
Issue #11463 Fix flaky session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janbartel authored and sbordet committed Feb 29, 2024
1 parent 4155e7b commit 313def7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void testMultipleSessionCookiesValidFirst() throws Exception
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
{
Expand Down Expand Up @@ -251,7 +251,7 @@ public void testMultipleSessionCookiesInvalidFirst() throws Exception
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
{
Expand Down Expand Up @@ -311,7 +311,7 @@ public void testMultipleSessionCookiesInvalidValidInvalid() throws Exception
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
{
Expand Down Expand Up @@ -368,9 +368,9 @@ public void testMultipleSessionCookiesMultipleExists() throws Exception
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
{
Expand Down Expand Up @@ -419,7 +419,7 @@ public void testMultipleIdenticalSessionCookies() throws Exception
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
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;
Expand Down Expand Up @@ -190,10 +192,10 @@ public void testSessionRenewalMultiContext() throws Exception
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class DuplicateCookieTest
{
public class TestSession extends ManagedSession
{

public TestSession(SessionManager manager, SessionData data)
{
super(manager, data);
Expand All @@ -66,7 +65,6 @@ public void makeInvalid()

public class TestSessionCache extends DefaultSessionCache
{

public TestSessionCache(SessionManager manager)
{
super(manager);
Expand All @@ -81,7 +79,6 @@ public ManagedSession newSession(SessionData data)

public class TestSessionCacheFactory extends DefaultSessionCacheFactory
{

@Override
public SessionCache newSessionCache(SessionManager manager)
{
Expand Down Expand Up @@ -190,7 +187,7 @@ public void testMultipleSessionCookiesValidFirst() throws Exception
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
{
Expand Down Expand Up @@ -251,7 +248,7 @@ public void testMultipleSessionCookiesInvalidFirst() throws Exception
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
{
Expand Down Expand Up @@ -311,7 +308,7 @@ public void testMultipleSessionCookiesInvalidValidInvalid() throws Exception
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
{
Expand Down Expand Up @@ -368,9 +365,9 @@ public void testMultipleSessionCookiesMultipleExists() throws Exception
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
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;
Expand Down Expand Up @@ -192,9 +194,8 @@ public void testSessionRenewalMultiContext() throws Exception
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
{
Expand Down

0 comments on commit 313def7

Please sign in to comment.