Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add k6 testing #116

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ orbs:
aws-cli: circleci/[email protected]
aws_assume_role: lbh-hackit/[email protected]
sonarcloud: sonarsource/[email protected]
grafana: grafana/[email protected]

executors:
docker-python:
Expand Down Expand Up @@ -234,6 +235,10 @@ jobs:
workflows:
check-and-deploy-development:
jobs:
- grafana/k6:
context: api-load-testing
arguments: --env TOKEN=$API_DEVELOPMENT_TOKEN --env API_URL=$TENURE_API_URL
script: scripts/performance-testing-script.js
- check-code-formatting:
context: api-nuget-token-context
- build-and-test:
Expand Down
39 changes: 39 additions & 0 deletions scripts/performance-testing-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Rate } from "k6/metrics";


var failureRate = new Rate("check_failure_rate");

export const options = {
vus: 5, //default value, can be overwritten by passing the --vus CLI option
duration: '10s', //default value, can be overwritten by passing the --duration CLI option
thresholds: {
// We want the 95th percentile of all HTTP request durations to be less than 500ms
"http_req_duration": ["p(95)<1000"],
// Thresholds based on the custom metric we defined and use to track application failures
"check_failure_rate": [
// Global failure rate should be less than 1%
"rate<0.01",
// Abort the test early if it climbs over 5%
{ threshold: "rate<=0.05", abortOnFail: true },
],
}
};
export const params = {
headers: { 'Authorization': `${__ENV.TOKEN}`},
};
export default function () {
var apiUrl = `${__ENV.API_URL}`
if (!apiUrl.includes('https://'))
{
apiUrl = "https://" + apiUrl;
}
const res = http.get(apiUrl, params);

let checkRes = check(res, { 'status was 200': (r) => r.status == 200 });

failureRate.add(!checkRes);

sleep(1);
}