feat: carry lab 2 over and add X-Instance-Id and idempotency keys
- 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>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// Пользователи и чаты стенда: читаемый (сценарий read), чат записи
|
||||
// (сценарий write) и фоновые чаты неравномерных размеров (трек 2). Каждый
|
||||
// пользователь регистрируется с паролем и входит по Basic; в фикстуру идут
|
||||
// id и Bearer-токены, пароли — нет. Итог — fixture.json в рабочем каталоге:
|
||||
// оркестратор удаляет его в конце прогона.
|
||||
import { WORK_DIR, createChat, register } from "./lib.js";
|
||||
|
||||
const MEMBERS = Number(__ENV.MEMBERS || 10);
|
||||
// уровни фоновых чатов: «10x5000,100x400» — число чатов x сообщений в чате
|
||||
const BACKGROUND = (__ENV.BACKGROUND || "")
|
||||
.split(",")
|
||||
.filter((tier) => tier !== "")
|
||||
.map((tier) => tier.split("x").map(Number));
|
||||
|
||||
export const options = {
|
||||
vus: 1,
|
||||
iterations: 1,
|
||||
setupTimeout: "5m",
|
||||
};
|
||||
|
||||
export function setup() {
|
||||
// размер начинается с пустой базы, поэтому имени хватает времени
|
||||
const stamp = Date.now().toString(36);
|
||||
const tokens = {};
|
||||
const reader = register(`b${stamp}_reader`, "Bench reader");
|
||||
tokens[reader.id] = reader.token;
|
||||
const memberIds = [];
|
||||
for (let i = 0; i < MEMBERS; i++) {
|
||||
const member = register(`b${stamp}_m${i}`, `Bench member ${i}`);
|
||||
tokens[member.id] = member.token;
|
||||
memberIds.push(member.id);
|
||||
}
|
||||
const everyone = [reader.id, ...memberIds];
|
||||
// фоновые чаты в порядке уровней: номер чата в расписании наполнения —
|
||||
// 1 + индекс в этом списке (0 — читаемый чат)
|
||||
const bgChats = [];
|
||||
for (const [count, size] of BACKGROUND) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const title = `bench bg ${size} #${i}`;
|
||||
bgChats.push({ id: createChat(reader.token, title, everyone), size });
|
||||
}
|
||||
}
|
||||
return {
|
||||
readerId: reader.id,
|
||||
memberIds,
|
||||
tokens,
|
||||
readChatId: createChat(reader.token, "bench read", everyone),
|
||||
writeChatId: createChat(reader.token, "bench write", everyone),
|
||||
bgChats,
|
||||
};
|
||||
}
|
||||
|
||||
export default function () {}
|
||||
|
||||
export function handleSummary(data) {
|
||||
return { [`${WORK_DIR}/fixture.json`]: JSON.stringify(data.setup_data) };
|
||||
}
|
||||
Reference in New Issue
Block a user