Created
May 13, 2020 09:19
-
-
Save titenkov/6c455f17c36ed24fd25a3f40ac99457b to your computer and use it in GitHub Desktop.
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
import http from "k6/http"; | |
import { check, group, sleep } from "k6"; | |
import { Rate } from "k6/metrics"; | |
// A custom metric to track failure rates | |
var failureRate = new Rate("check_failure_rate"); | |
// Options | |
export let options = { | |
stages: [ | |
{ target: 50, duration: "5m" }, | |
], | |
thresholds: { | |
// We want the 95th percentile of all HTTP request durations to be less than 1s | |
"http_req_duration": ["p(95)<1000"], | |
"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.1", abortOnFail: true }, | |
], | |
}, | |
}; | |
let params = { | |
headers: { 'Authorization': `Bearer ${__ENV.TOKEN}` }, | |
}; | |
// Main function | |
export default function () { | |
let response = http.get(`https://ix.interaxo-stage.com/api/joint.no/user/-me-/profile`, params); | |
// check() returns false if any of the specified conditions fail | |
let checkRes = check(response, { | |
"status is 200": (r) => r.status === 200, | |
"content is present": (r) => r.body.indexOf('email') !== -1, | |
}); | |
if (!checkRes) { | |
console.log(`Failed with ${response.status} status`); | |
} | |
// We reverse the check() result since we want to count the failures | |
failureRate.add(!checkRes); | |
sleep(Math.random() * 2 + 1); // Random sleep between 1s and 3s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment