add k6 benchmark script

This commit is contained in:
Adien Akhmad 2025-11-19 18:06:34 +07:00
parent deb8c49354
commit 0e871aeffa
4 changed files with 12239 additions and 0 deletions

52
bench.js Normal file
View file

@ -0,0 +1,52 @@
import http from "k6/http";
import { check } from "k6";
import { SharedArray } from "k6/data";
export const options = {
discardResponseBodies: true,
scenarios: {
sequential_test: {
executor: "per-vu-iterations",
vus: 1,
iterations: 1,
maxDuration: "30m",
},
},
};
const testData = new SharedArray("test requests", function () {
return JSON.parse(open("answer.json")).tests;
});
export default function () {
console.log(`Starting sequential test run with ${testData.length} requests.`);
for (const testCase of testData) {
const requestBody = testCase.request;
const testName = testCase.name;
const url = "http://localhost:7007/api/image/generate";
const payload = JSON.stringify(requestBody);
const params = {
headers: {
"Content-Type": "application/json",
Accept: "image/png",
},
tags: {
name: testName,
},
timeout: "200s",
};
console.log(`'${testName}'`);
const res = http.post(url, payload, params);
console.log(`'${testName}' duration=${res.timings.duration}ms`);
check(res, {
"status is 200 (OK)": (r) => r.status === 200,
"content-type is image/png": (r) =>
r.headers["Content-Type"] === "image/png",
});
}
console.log("Sequential test run finished.");
}