- carry the lab 3 solution over from mtusi2026lab3-safronov (solution/bvt2301-safronov, ce89eba): src, migrations, student-tests, bench, openspec, .claude, infra/haproxy and infra/valkey, own scripts, Dockerfile, compose, pyproject and uv lock - merge Makefile, .gitignore and .dockerignore (the lab 3 versions only add lines to the skeleton, which is the same in lab 4) and .env.example (lab 4 skeleton names listed in the header) - rename the compose project to mtusi-lab4 and the image to :lab4 so the stand does not reuse the lab 3 containers and volumes - update AGENTS.md for lab 4: current lab, origin commit, contract and test files of the new skeleton Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
2.9 KiB
JavaScript
88 lines
2.9 KiB
JavaScript
// Проверки восстановления через HTTP (трек 2), фаза — PHASE:
|
|
// - source: исходная база до восстановления;
|
|
// - stale: API на восстановленной базе, кэш ещё не очищен;
|
|
// - restored: после FLUSHALL.
|
|
// Во всех фазах — страницы этапа плана (plan_pages.json) и /users/me
|
|
// читателя; в stale и restored — ещё чат и пользователь «после backup».
|
|
// Ответы не проверяются здесь: статусы и элементы страниц пишутся в
|
|
// check-<фаза>.json, сверяет оркестратор. Токенов в итоге нет.
|
|
import http from "k6/http";
|
|
|
|
import {
|
|
API,
|
|
PAGE_LIMIT,
|
|
WORK_DIR,
|
|
authHeaders,
|
|
messageHeaders,
|
|
} from "./lib.js";
|
|
|
|
const PHASE = __ENV.PHASE;
|
|
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
|
|
const pages = JSON.parse(open(`${WORK_DIR}/plan_pages.json`));
|
|
// after.json появляется только после активности «после backup»
|
|
const after = PHASE === "source"
|
|
? null
|
|
: JSON.parse(open(`${WORK_DIR}/after.json`));
|
|
|
|
export const options = {
|
|
vus: 1,
|
|
iterations: 1,
|
|
setupTimeout: "5m",
|
|
};
|
|
|
|
function status(res) {
|
|
return res.status;
|
|
}
|
|
|
|
export function setup() {
|
|
const reader = { headers: authHeaders(fixture.tokens[fixture.readerId]) };
|
|
const result = {
|
|
phase: PHASE,
|
|
reader_me: status(http.get(`${API}/users/me`, reader)),
|
|
pages: pages.map((page) => {
|
|
const query = page.cursor === null
|
|
? `?limit=${PAGE_LIMIT}`
|
|
: `?limit=${PAGE_LIMIT}&cursor=${encodeURIComponent(page.cursor)}`;
|
|
const res = http.get(
|
|
`${API}/chats/${page.chat_id}/messages${query}`,
|
|
reader,
|
|
);
|
|
return {
|
|
chat: page.chat,
|
|
page: page.page,
|
|
status: res.status,
|
|
items: res.status === 200 ? res.json("items") : null,
|
|
};
|
|
}),
|
|
};
|
|
if (after !== null) {
|
|
const late = { headers: authHeaders(after.token) };
|
|
result.late_me = status(http.get(`${API}/users/me`, late));
|
|
result.after_chat_get = status(
|
|
http.get(`${API}/chats/${after.chatId}`, reader),
|
|
);
|
|
}
|
|
if (PHASE === "stale") {
|
|
// запись в чат, которого нет в восстановленной базе, а карточка — в
|
|
// кэше; с ключом, иначе 400 пришёл бы раньше проверки членства
|
|
result.after_chat_post = status(
|
|
http.post(
|
|
`${API}/chats/${after.chatId}/messages`,
|
|
JSON.stringify({ text: "written to a stale chat" }),
|
|
{
|
|
headers: messageHeaders(fixture.tokens[fixture.readerId]),
|
|
},
|
|
),
|
|
);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export default function () {}
|
|
|
|
export function handleSummary(data) {
|
|
return {
|
|
[`${WORK_DIR}/check-${PHASE}.json`]: JSON.stringify(data.setup_data),
|
|
};
|
|
}
|