- 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.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
// Одна порция наполнения: COUNT сообщений от участников по кругу. Чат
|
|
// сообщения n берётся из расписания оркестратора (schedule.json: 0 —
|
|
// читаемый чат, дальше фоновые в порядке фикстуры), так что сообщения всех
|
|
// чатов идут вперемешку. OFFSET — сколько сообщений уже отправлено.
|
|
import exec from "k6/execution";
|
|
import { SharedArray } from "k6/data";
|
|
|
|
import {
|
|
SUMMARY_THRESHOLDS,
|
|
SUMMARY_TREND_STATS,
|
|
WORK_DIR,
|
|
sendMessage,
|
|
summaryFiles,
|
|
syntheticText,
|
|
} from "./lib.js";
|
|
|
|
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
|
|
const schedule = new SharedArray(
|
|
"schedule",
|
|
() => JSON.parse(open(`${WORK_DIR}/schedule.json`)),
|
|
);
|
|
const chats = [fixture.readChatId, ...fixture.bgChats.map((c) => c.id)];
|
|
const OFFSET = Number(__ENV.OFFSET || 0);
|
|
|
|
export const options = {
|
|
scenarios: {
|
|
prefill: {
|
|
executor: "shared-iterations",
|
|
vus: Number(__ENV.VUS || 32),
|
|
iterations: Number(__ENV.COUNT),
|
|
maxDuration: "30m",
|
|
},
|
|
},
|
|
discardResponseBodies: true,
|
|
summaryTrendStats: SUMMARY_TREND_STATS,
|
|
thresholds: SUMMARY_THRESHOLDS,
|
|
};
|
|
|
|
export default function () {
|
|
const n = OFFSET + exec.scenario.iterationInTest;
|
|
const sender = fixture.memberIds[n % fixture.memberIds.length];
|
|
sendMessage(
|
|
chats[schedule[n]],
|
|
fixture.tokens[sender],
|
|
syntheticText("p", n),
|
|
);
|
|
}
|
|
|
|
export function handleSummary(data) {
|
|
return summaryFiles(data);
|
|
}
|