stitch-a-ton-answer/bench.js

44 lines
1,006 B
JavaScript
Raw Permalink Normal View History

2025-11-19 18:06:34 +07:00
import http from "k6/http";
import { check } from "k6";
import { SharedArray } from "k6/data";
2025-11-19 18:41:14 +07:00
const url = __ENV.TARGET_URL || "http://localhost:7007/api/image/generate";
2025-11-19 18:25:07 +07:00
const testData = new SharedArray("test requests", function () {
return JSON.parse(open("fuzzy.json"));
});
2025-11-19 18:06:34 +07:00
export const options = {
discardResponseBodies: true,
scenarios: {
2025-11-19 18:25:07 +07:00
fuzzy_test: {
executor: "shared-iterations",
vus: 16,
iterations: testData.length,
2025-11-19 18:06:34 +07:00
maxDuration: "30m",
},
},
};
export default function () {
2025-11-19 18:25:07 +07:00
const requestBody = testData[__ITER];
2025-11-19 18:06:34 +07:00
2025-11-19 18:25:07 +07:00
if (!requestBody) {
return;
2025-11-19 18:06:34 +07:00
}
2025-11-19 18:25:07 +07:00
const payload = JSON.stringify(requestBody);
const params = {
headers: {
"Content-Type": "application/json",
Accept: "image/png",
},
timeout: "200s",
};
2025-11-19 18:06:34 +07:00
2025-11-19 18:25:07 +07:00
const res = http.post(url, payload, params);
check(res, {
[`status is 200 (OK)`]: (r) => r.status === 200,
[`content-type is image/png`]: (r) =>
r.headers["Content-Type"] === "image/png",
});
2025-11-19 18:06:34 +07:00
}