tune benchmark
This commit is contained in:
parent
0e871aeffa
commit
744e379379
3 changed files with 2027 additions and 8077 deletions
61
bench.js
61
bench.js
|
|
@ -2,51 +2,42 @@ import http from "k6/http";
|
|||
import { check } from "k6";
|
||||
import { SharedArray } from "k6/data";
|
||||
|
||||
const testData = new SharedArray("test requests", function () {
|
||||
return JSON.parse(open("fuzzy.json"));
|
||||
});
|
||||
|
||||
export const options = {
|
||||
discardResponseBodies: true,
|
||||
scenarios: {
|
||||
sequential_test: {
|
||||
executor: "per-vu-iterations",
|
||||
vus: 1,
|
||||
iterations: 1,
|
||||
fuzzy_test: {
|
||||
executor: "shared-iterations",
|
||||
vus: 16,
|
||||
iterations: testData.length,
|
||||
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.`);
|
||||
const requestBody = testData[__ITER];
|
||||
|
||||
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",
|
||||
});
|
||||
if (!requestBody) {
|
||||
return;
|
||||
}
|
||||
const url = "http://localhost:7007/api/image/generate";
|
||||
const payload = JSON.stringify(requestBody);
|
||||
const params = {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "image/png",
|
||||
},
|
||||
timeout: "200s",
|
||||
};
|
||||
|
||||
console.log("Sequential test run finished.");
|
||||
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",
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue