From 050998eb52469b9409657302151620085c41ce01 Mon Sep 17 00:00:00 2001 From: Jonathan Sharman Date: Wed, 19 Oct 2022 08:53:23 -0700 Subject: [PATCH] chore: load this test was used to help with load testing --- k6/README.md | 6 ++ ...ngleRealmActiveSessionsMulitpleAttempts.js | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 k6/singleRealmActiveSessionsMulitpleAttempts.js diff --git a/k6/README.md b/k6/README.md index 478945fe..d85c1a0c 100644 --- a/k6/README.md +++ b/k6/README.md @@ -31,3 +31,9 @@ number of empty realms. To configure, set the following variables at the top of - **TOTAL_REALMS**: The total realms to create (any additional realms will be left empty) - **RAMP_UP_TIME_SECONDS**: The time to ramp up to the total number of sessions - **HOLD_TIME_SECONDS**: The time to hold those sessions before ending the test + +## K6 issues + +A recurrent issue with Linus users is that the bash terminal has a low default on the number of files the terminal can open. + +`ulimit -Sa` and `ulimit -Ha` shows the soft and hard limits on the number of files. Running the command `ulimit -n 5000` ups the limit to `5000` allowing the tests to run in that bash session. diff --git a/k6/singleRealmActiveSessionsMulitpleAttempts.js b/k6/singleRealmActiveSessionsMulitpleAttempts.js new file mode 100644 index 00000000..45baeab1 --- /dev/null +++ b/k6/singleRealmActiveSessionsMulitpleAttempts.js @@ -0,0 +1,58 @@ +import { sleep, check } from 'k6'; +import { createRealm, deleteRealm, createUser, generateRealms, getAccessToken, clearRealmSessions } from './helpers.js'; +import { user, realm } from './constants.js'; +import { username, password, clientId } from './env.js'; + +const TOTAL_ACTIVE_SESSIONS = 3000; +const TOTAL_REALMS = 30; +const MAX_ALLOWED_FAILURE_RATE = '0.01'; + +const RAMP_UP_TIME_SECONDS = 60; +const HOLD_TIME_SECONDS = 300; +// SESSION_TIME determines how long a user sleeps before requesting a new token. +const SESSION_TIME = 10; + + +export const options = { + stages: [ + { + target: TOTAL_ACTIVE_SESSIONS, + duration: `${RAMP_UP_TIME_SECONDS}s`, + }, + { + target: TOTAL_ACTIVE_SESSIONS, + duration: `${HOLD_TIME_SECONDS}s`, + }, + ], + thresholds: { + http_req_failed: [ + { + threshold: `rate<${MAX_ALLOWED_FAILURE_RATE}`, + // abortOnFail: true, + }, + ], + }, +}; + +export function setup() { + const accessToken = getAccessToken(username, password, clientId); + const emptyRealms = generateRealms(TOTAL_REALMS); + emptyRealms.forEach((realm, i) => { + createRealm(realm, accessToken); + if (i === 0) createUser(user, realm.realm, accessToken); + }); + return emptyRealms; +} + +export default function (realms) { + getAccessToken(user.username, user.credentials[0].value, clientId, realms[0].realm); + sleep(SESSION_TIME); + return realms; +} + +export function teardown(realms) { + const accessToken = getAccessToken(username, password, clientId); + realms.forEach((realm, i) => { + deleteRealm(realm.realm, accessToken); + }); +}