-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from bcgov/sso-team-880
feat: k6-tests
- Loading branch information
Showing
20 changed files
with
3,330 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ yarn-error.log* | |
*.key | ||
*.cert | ||
k6/env.js | ||
venv | ||
|
||
##### Terraform-specific ignores. | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { sleep } from 'k6'; | ||
import { createRealm, deleteRealm, createUser, generateRealms, getAccessToken } from './helpers.js'; | ||
import { user } from './constants.js'; | ||
import { username, password, clientId } from './env.js'; | ||
|
||
// Alter configuration to run separate tests. See this test in the readme for configuration details. | ||
const CONCURRENT_LOOPS = 5; | ||
const ITERATIONS_PER_LOOP = 50; | ||
const TOTAL_REALMS = 3; | ||
const MAX_ALLOWED_FAILURE_RATE = '0.01'; | ||
const OFFLINE = false; | ||
const LOOP_DELAY = 0.1 | ||
|
||
export const options = { | ||
scenarios: { | ||
synchronousExecutions: { | ||
executor: 'per-vu-iterations', | ||
vus: CONCURRENT_LOOPS, | ||
iterations: ITERATIONS_PER_LOOP, | ||
}, | ||
}, | ||
thresholds: { | ||
http_req_failed: [ | ||
{ | ||
threshold: `rate<${MAX_ALLOWED_FAILURE_RATE}`, | ||
// Set true if you want to exit at this threshold. Can be useful for heavy tests where you want to save the poor server if its failing. | ||
// abortOnFail: true, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export function setup() { | ||
const accessToken = getAccessToken({ username, password, clientId, confidential: true }); | ||
const emptyRealms = generateRealms(TOTAL_REALMS); | ||
emptyRealms.forEach((realm, i) => { | ||
createRealm(realm, accessToken); | ||
// No spread operators allowed in k6, only es5 :( | ||
const newUser = Object.assign({}, user, { username: `${user.username}_${i}` }) | ||
createUser(newUser, realm.realm, accessToken); | ||
}); | ||
return emptyRealms; | ||
} | ||
|
||
export default function (realms) { | ||
realms.forEach((realm, i) => { | ||
sleep(LOOP_DELAY) | ||
getAccessToken({ | ||
username: `${user.username}_${i}`, | ||
password: user.credentials[0].value, | ||
clientId, | ||
confidential: true, | ||
realm: realm.realm, | ||
offline: OFFLINE | ||
}); | ||
}) | ||
} | ||
|
||
export function teardown(realms) { | ||
const accessToken = getAccessToken({ username, password, clientId, confidential: true }); | ||
realms.forEach((realm, i) => { | ||
deleteRealm(realm.realm, accessToken); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { sleep } from 'k6'; | ||
import { createRealm, deleteRealm, createUser, generateRealms, getAccessToken, hitIntrospectionRoute, hitUserInfoRoute, createClient } from './helpers.js'; | ||
import { user, client } from './constants.js'; | ||
import { username, password, clientId } from './env.js'; | ||
|
||
// Alter configuration to run separate tests. See this test in the readme for configuration details. | ||
const TOTAL_REALMS = 1; | ||
// This essentially just means no dropped requests allowed since we dont get to 10000 on the peak profile. | ||
const MAX_ALLOWED_FAILURE_RATE = '0.0001'; | ||
const OFFLINE = false; | ||
|
||
// Peak requests per minutes we've seen on the system | ||
const BASELINE_RATE = 34; | ||
|
||
export const options = { | ||
scenarios: { | ||
peakProfile: { | ||
executor: 'constant-arrival-rate', | ||
duration: '2h', | ||
timeUnit: '1m', | ||
rate: 34, | ||
preAllocatedVUs: 5, | ||
}, | ||
// stress: { | ||
// executor: 'ramping-arrival-rate', //Assure load increase if the system slows | ||
// startRate: BASELINE_RATE, | ||
// timeUnit: '1m', | ||
// preAllocatedVUs: 20000, | ||
// stages: [ | ||
// { duration: '1m', target: BASELINE_RATE }, // just slowly ramp-up to a HUGE load | ||
// // just slowly ramp-up to an EPIC load. | ||
// { duration: '1h', target: 20000 }, | ||
// ], | ||
// } | ||
}, | ||
thresholds: { | ||
http_req_failed: [ | ||
{ | ||
threshold: `rate<${MAX_ALLOWED_FAILURE_RATE}`, | ||
// Leave this in! Don't keep hammering the poor server after its failing, requests will queue | ||
abortOnFail: true, | ||
}, | ||
], | ||
// Requests tend to drop after 60 second timeout. Can use below to fail earlier | ||
// http_req_duration: [ | ||
// { | ||
// threshold: `p(95)<15000`, | ||
// abortOnFail: true, | ||
// }, | ||
// ] | ||
}, | ||
}; | ||
|
||
export function setup() { | ||
const accessToken = getAccessToken({ username, password, clientId, confidential: true }); | ||
const emptyRealms = generateRealms(TOTAL_REALMS); | ||
emptyRealms.forEach((realm, i) => { | ||
createRealm(realm, accessToken); | ||
const newUser = Object.assign({}, user, { username: `${user.username}_${i}` }) | ||
createUser(newUser, realm.realm, accessToken); | ||
// Create a confidential client to be able to use the introspection endpoint with this realm | ||
createClient(realm.realm, accessToken) | ||
}); | ||
return emptyRealms; | ||
} | ||
|
||
export default function (realms) { | ||
realms.forEach((realm, i) => { | ||
const accessToken = getAccessToken({ | ||
username: `${user.username}_${i}`, | ||
password: user.credentials[0].value, | ||
clientId, | ||
confidential: true, | ||
realm: realm.realm, | ||
offline: OFFLINE | ||
}); | ||
hitUserInfoRoute(accessToken, realm.realm) | ||
hitIntrospectionRoute(accessToken, realm.realm, client.clientId, client.secret) | ||
}) | ||
} | ||
|
||
export function teardown(realms) { | ||
// When stress testing, the enqueued requests can block teardown api requests from succeeding. Adding in a sleep to let the system recover a bit before trying to cleaunup. | ||
sleep(45) | ||
console.log('tearing down...') | ||
const accessToken = getAccessToken({ username, password, clientId, confidential: true }); | ||
realms.forEach((realm, i) => { | ||
deleteRealm(realm.realm, accessToken); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.