chore: carry over lab 1 solution into lab 2 skeleton
Copy the committed lab 1 sources as-is: src/, student-tests/, bench/, Dockerfile, docker-compose.yml, pyproject.toml, uv.lock, .python-version, config_example.toml, AGENTS.md, CLAUDE.md, .claude/, openspec/, .graphifyignore and KNOWN_ISSUES.md. Lab 1 evidence stays in the lab 1 repository. Merge the new skeleton files with own sections: Makefile (lab 2 targets plus own run, docker, bench and common targets), .gitignore, .dockerignore and .env.example. Rename the image to mtusi-messenger:lab2 and point AGENTS.md at lab 2. The application is still the in-memory lab 1 implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// Пул курсоров сценария read: проход истории читаемого чата страницами по
|
||||
// WALK_LIMIT и равномерная выборка до POOL_SIZE курсоров. В пул идут
|
||||
// только позиции, после которых есть ещё PAGE_LIMIT сообщений, чтобы
|
||||
// каждая страница read была полной.
|
||||
import http from "k6/http";
|
||||
import { fail } from "k6";
|
||||
|
||||
import { API, PAGE_LIMIT, WORK_DIR, authHeaders } from "./lib.js";
|
||||
|
||||
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
|
||||
const WALK_LIMIT = Number(__ENV.WALK_LIMIT || 100);
|
||||
const POOL_SIZE = Number(__ENV.POOL_SIZE || 1000);
|
||||
|
||||
export const options = {
|
||||
vus: 1,
|
||||
iterations: 1,
|
||||
setupTimeout: "30m",
|
||||
};
|
||||
|
||||
export function setup() {
|
||||
const url = `${API}/chats/${fixture.readChatId}/messages`;
|
||||
const params = { headers: authHeaders(fixture.readerId) };
|
||||
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(`history page 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;
|
||||
}
|
||||
const eligible = positions.filter((p) => walked - p.after >= PAGE_LIMIT);
|
||||
const step = Math.max(1, eligible.length / POOL_SIZE);
|
||||
const pool = [];
|
||||
for (let i = 0; i < eligible.length && pool.length < POOL_SIZE; i += step) {
|
||||
pool.push(eligible[Math.floor(i)]);
|
||||
}
|
||||
return {
|
||||
walked,
|
||||
eligible: eligible.length,
|
||||
first_after: pool.length ? pool[0].after : null,
|
||||
last_after: pool.length ? pool[pool.length - 1].after : null,
|
||||
cursors: pool.map((p) => p.cursor),
|
||||
};
|
||||
}
|
||||
|
||||
export default function () {}
|
||||
|
||||
export function handleSummary(data) {
|
||||
return { [`${WORK_DIR}/cursors.json`]: JSON.stringify(data.setup_data) };
|
||||
}
|
||||
Reference in New Issue
Block a user