Skip to content

Instantly share code, notes, and snippets.

@mrrizal
Created July 29, 2023 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrrizal/ad23ce42bd6eed9a2e1e196966ca8878 to your computer and use it in GitHub Desktop.
Save mrrizal/ad23ce42bd6eed9a2e1e196966ca8878 to your computer and use it in GitHub Desktop.
sample api load test
import http from 'k6/http';
import { sleep } from 'k6';
export let options = {
stages: [
{ duration: '1m', target: 100 },
{ duration: '2m', target: 500 },
{ duration: '2m', target: 1000 },
],
};
const urls = [
"http://localhost/v1/api/like",
"http://localhost/v1/api/unlike",
];
export default function () {
const payload = JSON.stringify({});
const headers = { 'Content-Type': 'application/json' };
const url = urls[Math.floor(Math.random() * urls.length)];
const response = http.post(url, payload, { headers: headers });
if (response.status != 204) {
console.log("Request failed " + response.status)
}
sleep(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment