Files
mtusi2026lab7-safronov/bench/k6/queue_sweep.js
T
ricoromaandClaude Opus 5.5 089d78609d chore: port lab 6 solution into the lab 7 skeleton
Source: mtusi2026lab6-safronov, solution/bvt2301-safronov, 6c6a065.
Files follow AGENTS.md, "Переход в следующую лабу". Contracts, public
tests, README, REPORT and evidence of lab 6 are not carried over; infra
and scripts of the lab 7 skeleton stay as they are.
Makefile is the lab 6 one with the lab 7 skeleton part restored
(HTTPS BASE_URL on 8443, test-security); .gitignore and .dockerignore
are taken from lab 6 because both skeletons have the same files;
.env.example is the lab 6 one without changes.
The compose project, image and CI prefix are renamed to lab7, and
references to the previous lab now name lab6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 03:59:04 +03:00

82 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Обход принятых вложений профиля очереди (design change track1-queue-overload,
// решение 9): истина о готовности — метаданные GET /attachments/{id}, опрос в
// замере не нужен: updated_at у ready не меняется после фиксации. Строка на
// вложение «qs,<id>,<http>,<status>,<error_code>,<variants>,<updated_at>»; у
// выборки (первые SAMPLE ids, порядок задал оркестратор от зерна) — оригинал и
// варианты с SHA-256 из метаданных: «qv,<id>,<имя>,<1|0>».
import { sha256 } from "k6/crypto";
import exec from "k6/execution";
import http from "k6/http";
import { SharedArray } from "k6/data";
import { API, WORK_DIR, authHeaders, summaryFiles } from "./lib.js";
const fixture = JSON.parse(open(`${WORK_DIR}/fixture.json`));
const ids = new SharedArray("ids", () =>
JSON.parse(open(`${WORK_DIR}/${__ENV.IDS}`)),
);
const SAMPLE = Number(__ENV.SAMPLE || 10);
const READER = authHeaders(fixture.tokens[fixture.readerId]);
const VARIANTS = ["thumbnail", "crop", "optimized"];
export const options = {
scenarios: {
sweep: {
executor: "shared-iterations",
vus: 4,
iterations: Math.max(1, ids.length),
maxDuration: "10m",
},
},
thresholds: { iterations: ["count>=0"] },
};
function checkBytes(id, name, expected) {
const query = name === "original" ? "" : `?variant=${name}`;
const res = http.get(`${API}/attachments/${id}/content${query}`, {
headers: READER,
responseType: "binary",
timeout: "60s",
});
let good = 0;
if (res.status === 200) {
good = sha256(res.body, "hex") === expected ? 1 : 0;
}
console.log(`qv,${id},${name},${good}`);
}
export default function () {
const index = exec.scenario.iterationInTest;
if (index >= ids.length) {
return;
}
const id = ids[index];
const res = http.get(`${API}/attachments/${id}`, {
headers: READER,
timeout: "30s",
responseCallback: http.expectedStatuses(200, 404),
});
if (res.status !== 200) {
console.log(`qs,${id},${res.status},-,-,0,-`);
return;
}
const meta = res.json();
const variants = meta.variants || [];
console.log(
`qs,${id},200,${meta.status},${meta.error_code || "-"},` +
`${variants.length},${meta.updated_at}`,
);
if (index < SAMPLE && meta.status === "ready") {
checkBytes(id, "original", meta.sha256);
for (const item of variants) {
if (VARIANTS.includes(item.name)) {
checkBytes(id, item.name, item.sha256);
}
}
}
}
export function handleSummary(data) {
return summaryFiles(data);
}