Skip to content

Commit

Permalink
KEYCLOAK-9869 Fix stability of cluster tests on EAP6
Browse files Browse the repository at this point in the history
  • Loading branch information
mhajas authored and hmlnarik committed Mar 27, 2019
1 parent ad1a72e commit 0d0eec8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,30 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
req.logout();
return;
}
String counter = increaseAndGetCounter(req);

String counter;
if (req.getRequestURI().endsWith("/donotincrease")) {
counter = getCounter(req);
} else {
counter = increaseAndGetCounter(req);
}

resp.setContentType("text/html");
PrintWriter pw = resp.getWriter();
pw.printf("<html><head><title>%s</title></head><body>", "Session Test");
pw.printf("Counter=%s", counter);
pw.printf("Node name=%s", System.getProperty("jboss.node.name", "property not specified"));
pw.print("</body></html>");
pw.flush();


}

private String getCounter(HttpServletRequest req) {
HttpSession session = req.getSession();
return String.valueOf(session.getAttribute("counter"));
}

private String increaseAndGetCounter(HttpServletRequest req) {
HttpSession session = req.getSession();
Integer counter = (Integer)session.getAttribute("counter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertThat;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad;

import java.net.URI;
import java.net.URL;
Expand All @@ -44,6 +45,8 @@
import org.keycloak.testsuite.arquillian.containers.ContainerConstants;
import org.keycloak.testsuite.auth.page.AuthRealm;
import org.keycloak.testsuite.auth.page.login.OIDCLogin;
import org.keycloak.testsuite.util.DroneUtils;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
Expand Down Expand Up @@ -136,9 +139,26 @@ public void testSuccessfulLoginAndProgrammaticLogout(@ArquillianResource
assertCurrentUrlStartsWith(loginPage);
}

private void waitForCacheReplication(String appUrl, int expectedCount) {
new WebDriverWait(DroneUtils.getCurrentDriver(), 5) // Check every 500ms of 5 seconds
.until((driver) -> {
driver.navigate().to(appUrl + "/donotincrease");
waitForPageToLoad();

return driver.getPageSource().contains("Counter=" + expectedCount);
});
}

private void assertSessionCounter(String hostToPointToName, URI hostToPointToUri, URI hostToRemove, String appUrl, int expectedCount) {
updateProxy(hostToPointToName, hostToPointToUri, hostToRemove);

// Wait for cache replication, this is necessary due to https://access.redhat.com/solutions/20861
waitForCacheReplication(appUrl, expectedCount - 1); // Not increased yet therefore -1

driver.navigate().to(appUrl);
waitForPageToLoad();

assertThat(driver.getPageSource(), containsString("Counter=" + expectedCount));
assertThat(driver.getPageSource(), containsString("Node name=" + hostToPointToName));
}
}

0 comments on commit 0d0eec8

Please sign in to comment.