forked from mtusi2026/mtusi2026lab7
Source: mtusi2026lab6-safronov, solution/bvt2301-safronov, 6c6a065. Files follow AGENTS.md, "Переход в следующую лабу". Contracts, public tests, README, REPORT and evidence of lab 6 are not carried over; infra and scripts of the lab 7 skeleton stay as they are. Makefile is the lab 6 one with the lab 7 skeleton part restored (HTTPS BASE_URL on 8443, test-security); .gitignore and .dockerignore are taken from lab 6 because both skeletons have the same files; .env.example is the lab 6 one without changes. The compose project, image and CI prefix are renamed to lab7, and references to the previous lab now name lab6. 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);
|
|
}
|