add k6 benchmark script
This commit is contained in:
parent
deb8c49354
commit
0e871aeffa
4 changed files with 12239 additions and 0 deletions
52
bench.js
Normal file
52
bench.js
Normal 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.");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue