Created
July 29, 2023 03:49
-
-
Save mrrizal/ad23ce42bd6eed9a2e1e196966ca8878 to your computer and use it in GitHub Desktop.
sample api load test
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 { 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