Skip to content

Commit

Permalink
chore: load
Browse files Browse the repository at this point in the history
this test was used to help with load testing
  • Loading branch information
thegentlemanphysicist committed Oct 19, 2022
1 parent 5d47076 commit 050998e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions k6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
58 changes: 58 additions & 0 deletions k6/singleRealmActiveSessionsMulitpleAttempts.js
Original file line number Diff line number Diff line change
@@ -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);
});
}

0 comments on commit 050998e

Please sign in to comment.