- carry the lab 3 solution over from mtusi2026lab3-safronov (solution/bvt2301-safronov, ce89eba): src, migrations, student-tests, bench, openspec, .claude, infra/haproxy and infra/valkey, own scripts, Dockerfile, compose, pyproject and uv lock - merge Makefile, .gitignore and .dockerignore (the lab 3 versions only add lines to the skeleton, which is the same in lab 4) and .env.example (lab 4 skeleton names listed in the header) - rename the compose project to mtusi-lab4 and the image to :lab4 so the stand does not reuse the lab 3 containers and volumes - update AGENTS.md for lab 4: current lab, origin commit, contract and test files of the new skeleton Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
2.1 KiB
JavaScript
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);
|
|
}
|