Files
mtusi2026lab6/bench/k6/read.js
T
ricoromaandClaude Opus 5.5 9cc6c0c7a6 chore: port lab 5 solution into the lab 6 skeleton
Source: mtusi2026lab5-safronov, solution/bvt2301-safronov, 046ec9e.
Contracts, public tests and evidence of lab 5 are not carried over.
The compose project, image and CI prefix are renamed to lab6; the first
broker start defect is recorded in KNOWN_ISSUES.md; PLAN.md outlines the
OpenSpec changes of lab 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 04:46:56 +03:00

70 lines
2.1 KiB
JavaScript

// Сценарий read: страница истории читаемого чата с курсором, случайно
// выбранным из пула. У каждого VU свой генератор с зерном SEED + номер VU:
// последовательность одинакова в разных метках и различна у клиентов.
import exec from "k6/execution";
import http from "k6/http";
import { check } from "k6";
import { SharedArray } from "k6/data";
import {
API,
PAGE_LIMIT,
SUMMARY_THRESHOLDS,
SUMMARY_TREND_STATS,
WORK_DIR,
authHeaders,
mulberry32,
summaryFiles,
} from "./lib.js";
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
const cursors = new SharedArray(
"cursors",
() => JSON.parse(open(`${WORK_DIR}/cursors.json`)).cursors,
);
const SEED = Number(__ENV.SEED || 0);
// отладка стенда: напечатать первые TRACE выборов каждого VU
const TRACE = Number(__ENV.TRACE || 0);
const URL = `${API}/chats/${fixture.readChatId}/messages`;
const PARAMS = {
headers: authHeaders(fixture.tokens[fixture.readerId]),
responseCallback: http.expectedStatuses(200),
};
export const options = {
scenarios: {
read: {
executor: "constant-vus",
vus: Number(__ENV.VUS),
duration: __ENV.DURATION,
gracefulStop: "5s",
},
},
summaryTrendStats: SUMMARY_TREND_STATS,
thresholds: SUMMARY_THRESHOLDS,
};
let random = null;
let picks = 0;
export default function () {
if (random === null) {
random = mulberry32(SEED + exec.vu.idInTest);
}
const index = Math.floor(random() * cursors.length);
if (picks < TRACE) {
console.log(`trace vu=${exec.vu.idInTest} pick=${picks} index=${index}`);
}
picks += 1;
const cursor = encodeURIComponent(cursors[index]);
const res = http.get(`${URL}?limit=${PAGE_LIMIT}&cursor=${cursor}`, PARAMS);
check(res, {
"status 200": (r) => r.status === 200,
"full page": (r) => r.status === 200 && r.json("items.#") === PAGE_LIMIT,
});
}
export function handleSummary(data) {
return summaryFiles(data);
}