- carry the lab 2 solution over and plan lab 3 (PLAN.md, OpenSpec change instance-id-idempotency) - rename the compose project to mtusi-lab3 and the image to :lab3 - add X-Instance-Id to every response and instance_id to every log record ([app] instance_id, hostname by default) - require Idempotency-Key on POST messages: keys table in Postgres, key and message in one transaction, replay returns the same 201, another body gets 409, TTL from [idempotency] ttl_seconds - send the key from student-tests, k6 scenarios and the skill driver; add idempotency, X-Instance-Id, key race and fault tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.8 KiB
JavaScript
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) };
|
|
}
|