Files
mtusi2026lab7-safronov/bench/k6/plan_cursors.js
T
ricoromaandClaude Opus 5.5 089d78609d chore: port lab 6 solution into the lab 7 skeleton
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>
2026-11-16 03:59:04 +03:00

52 lines
1.8 KiB
JavaScript

// Курсоры страниц плана фоновых чатов (трек 2): проход истории каждого чата
// из plan_chats.json страницами по WALK_LIMIT, позиция и курсор после каждой
// страницы. Идёт до включения auto_explain, поэтому в журнал не попадает;
// заодно прогревает страницы этих чатов, как cursors.js — читаемого.
import http from "k6/http";
import { fail } from "k6";
import { API, WORK_DIR, authHeaders } from "./lib.js";
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
const chats = JSON.parse(open(`${WORK_DIR}/plan_chats.json`));
const WALK_LIMIT = Number(__ENV.WALK_LIMIT || 100);
export const options = {
vus: 1,
iterations: 1,
setupTimeout: "10m",
};
export function setup() {
const params = { headers: authHeaders(fixture.tokens[fixture.readerId]) };
return chats.map((chat) => {
const url = `${API}/chats/${chat.id}/messages`;
const positions = [];
let cursor = null;
let walked = 0;
for (;;) {
const query = cursor === null
? `?limit=${WALK_LIMIT}`
: `?limit=${WALK_LIMIT}&cursor=${encodeURIComponent(cursor)}`;
const res = http.get(url + query, params);
if (res.status !== 200) {
fail(`chat ${chat.id} after ${walked}: ${res.status} ${res.body}`);
}
const body = res.json();
walked += body.items.length;
if (body.next_cursor === null) {
break;
}
positions.push({ after: walked, cursor: body.next_cursor });
cursor = body.next_cursor;
}
return { id: chat.id, walked, positions };
});
}
export default function () {}
export function handleSummary(data) {
return { [`${WORK_DIR}/plan_walks.json`]: JSON.stringify(data.setup_data) };
}