54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import http from "k6/http";
|
|||
|
|
import { check, sleep } from "k6";
|
||
|
|
|
||
|
|
const baseURL = __ENV.BASE_URL || "http://host.docker.internal:58080";
|
||
|
|
const accessToken = __ENV.ACCESS_TOKEN || "";
|
||
|
|
const smoke = (__ENV.PROFILE || "acceptance").toLowerCase() === "smoke";
|
||
|
|
const targetRate = Number(__ENV.RATE || (smoke ? 20 : 50));
|
||
|
|
const duration = __ENV.DURATION || (smoke ? "20s" : "30m");
|
||
|
|
|
||
|
|
export const options = {
|
||
|
|
scenarios: {
|
||
|
|
steady_read_traffic: {
|
||
|
|
executor: "constant-arrival-rate",
|
||
|
|
rate: targetRate,
|
||
|
|
timeUnit: "1s",
|
||
|
|
duration,
|
||
|
|
preAllocatedVUs: smoke ? 20 : 75,
|
||
|
|
maxVUs: smoke ? 50 : 200,
|
||
|
|
gracefulStop: "30s",
|
||
|
|
},
|
||
|
|
},
|
||
|
|
thresholds: {
|
||
|
|
http_req_failed: [smoke ? "rate<0.01" : "rate<0.001"],
|
||
|
|
http_req_duration: ["p(95)<500", "p(99)<1000"],
|
||
|
|
checks: ["rate>0.99"],
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
export default function () {
|
||
|
|
const ready = http.get(`${baseURL}/health/ready`, {
|
||
|
|
tags: { operation: "readiness" },
|
||
|
|
timeout: "3s",
|
||
|
|
});
|
||
|
|
check(ready, {
|
||
|
|
"readiness returns 200": (response) => response.status === 200,
|
||
|
|
"readiness dependencies are up": (response) =>
|
||
|
|
response.status === 200 && response.json("data.status") === "ready" &&
|
||
|
|
response.json("data.checks.postgres") === "up" && response.json("data.checks.redis") === "up" &&
|
||
|
|
response.json("data.checks.object_store") === "up",
|
||
|
|
});
|
||
|
|
|
||
|
|
if (accessToken) {
|
||
|
|
const households = http.get(`${baseURL}/api/v1/households`, {
|
||
|
|
headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/json" },
|
||
|
|
tags: { operation: "households" },
|
||
|
|
timeout: "3s",
|
||
|
|
});
|
||
|
|
check(households, {
|
||
|
|
"authenticated household read returns 200": (response) => response.status === 200,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if (smoke) sleep(0.02);
|
||
|
|
}
|