From fe2ae6ec680093aba8bd37ffc2965bd4791d5d0d Mon Sep 17 00:00:00 2001 From: Tomas Kyjovsky Date: Mon, 23 Apr 2018 14:12:08 +0200 Subject: [PATCH] KEYCLOAK-7199 Optional logout step in registration perfromance test --- testsuite/performance/README.md | 1 + .../org/keycloak/performance/TestConfig.java | 9 ++++-- .../scala/keycloak/OIDCScenarioBuilder.scala | 28 +++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/testsuite/performance/README.md b/testsuite/performance/README.md index 0fcd6ff683..0ccc4503ff 100644 --- a/testsuite/performance/README.md +++ b/testsuite/performance/README.md @@ -199,6 +199,7 @@ When running the tests it is necessary to define the dataset to be used. | `filterResults` | Whether to filter out requests which are outside of the `measurementPeriod`. | `false` | | `userThinkTime` | Pause between individual scenario steps. | `5` | | `refreshTokenPeriod`| Period after which token should be refreshed. | `10` | +| `logoutPct`| Percentage of users who should log out at the end of scenario. | `100` | | Test Assertion | Description | Default Value | | --- | --- | --- | diff --git a/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java b/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java index cba6b72ccc..5b6a11a4b8 100644 --- a/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java +++ b/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java @@ -70,6 +70,7 @@ public class TestConfig { public static final boolean filterResults = Boolean.getBoolean("filterResults"); // filter out results outside of measurementPeriod public static final int userThinkTime = Integer.getInteger("userThinkTime", 0); public static final int refreshTokenPeriod = Integer.getInteger("refreshTokenPeriod", 0); + public static final double logoutPct = Double.valueOf(System.getProperty("logoutPct", "100")); // Computed timestamps public static final long simulationStartTime = System.currentTimeMillis(); @@ -139,8 +140,9 @@ public class TestConfig { " measurementPeriod: %s\n"+ " filterResults: %s\n"+ " userThinkTime: %s\n"+ - " refreshTokenPeriod: %s", - usersPerSec, rampUpPeriod, warmUpPeriod, measurementPeriod, filterResults, userThinkTime, refreshTokenPeriod); + " refreshTokenPeriod: %s\n"+ + " logoutPct: %s", + usersPerSec, rampUpPeriod, warmUpPeriod, measurementPeriod, filterResults, userThinkTime, refreshTokenPeriod, logoutPct); } public static SimpleDateFormat SIMPLE_TIME = new SimpleDateFormat("HH:mm:ss"); @@ -307,6 +309,9 @@ public class TestConfig { if (sequentialUsersFrom < -1 || sequentialUsersFrom >= usersPerRealm) { throw new RuntimeException("The folowing condition must be met: (-1 <= sequentialUsersFrom < usersPerRealm)."); } + if (logoutPct < 0 || logoutPct > 100) { + throw new RuntimeException("The `logoutPct` needs to be between 0 and 100."); + } } } diff --git a/testsuite/performance/tests/src/test/scala/keycloak/OIDCScenarioBuilder.scala b/testsuite/performance/tests/src/test/scala/keycloak/OIDCScenarioBuilder.scala index d868a89807..951b99544c 100644 --- a/testsuite/performance/tests/src/test/scala/keycloak/OIDCScenarioBuilder.scala +++ b/testsuite/performance/tests/src/test/scala/keycloak/OIDCScenarioBuilder.scala @@ -62,9 +62,7 @@ object OIDCScenarioBuilder { .refreshTokenSeveralTimes() .thinkPause() - .logout() - - .thinkPause() + .randomLogout() val registerAndLogoutScenario = new OIDCScenarioBuilder() .browserOpensLoginPage() @@ -74,8 +72,7 @@ object OIDCScenarioBuilder { .browserPostsRegistrationDetails() .adapterExchangesCodeForTokens() .thinkPause() - .logout() - .thinkPause() + .randomLogout() } @@ -119,7 +116,7 @@ class OIDCScenarioBuilder { def newThinkPause() : ChainBuilder = { pause(TestConfig.userThinkTime, Normal(TestConfig.userThinkTime * 0.2)) } - + def browserOpensLoginPage() : OIDCScenarioBuilder = { chainBuilder = chainBuilder .exec(http("Browser to Log In Endpoint") @@ -225,14 +222,27 @@ class OIDCScenarioBuilder { this } - def logout() : OIDCScenarioBuilder = { - chainBuilder = chainBuilder - .exec(http("Browser logout") + def logoutChain() : ChainBuilder = { + exec(http("Browser logout") .get(LOGOUT_ENDPOINT) .headers(UI_HEADERS) .queryParam("redirect_uri", "${appUrl}") .check(status.is(302), header("Location").is("${appUrl}"))) + } + + def logout() : OIDCScenarioBuilder = { + chainBuilder = chainBuilder.exec(logoutChain) this } + + def randomLogout() : OIDCScenarioBuilder = { + chainBuilder = chainBuilder + .randomSwitch( + // logout randomly based on logoutPct param + TestConfig.logoutPct -> exec(logoutChain) + ) + this + } + }