lab4: исправления второго ревью (40 Мп в tmpfs, таймауты S3, параллельный complete, auth до Content-Type, лимит на пользователя, бюджет памяти декода)

This commit is contained in:
2026-10-23 17:09:49 +03:00
parent a06471a6c6
commit 4b53e03fd6
27 changed files with 642 additions and 141 deletions
+60
View File
@@ -602,6 +602,10 @@ describe.skipIf(!enabled)('dependency outages', () => {
await compose('start', redisService);
await compose('start', postgresService);
await compose('start', s3Service);
const s3Container = (await compose('ps', '-q', s3Service)).split(
'\n',
)[0];
await docker('unpause', s3Container).catch(() => undefined);
await waitForReadiness(200);
await restoreDatabaseAccess();
const expected = (await apiContainers()).length;
@@ -986,6 +990,62 @@ describe.skipIf(!enabled)('dependency outages', () => {
outagedRequestBudgetMs,
);
it(
'bounds requests by S3_REQUEST_TIMEOUT_MS when S3 hangs instead of refusing',
async () => {
const created = await request<{ id: string }>(
uploadPath(chat.id, `hang-${runId}.png`),
{
method: 'POST',
headers: { ...bearer(token), 'content-type': 'image/png' },
body: samplePng as unknown as BodyInit,
},
);
expect(created.response.status).toBe(201);
// A paused container keeps its TCP port open but never answers: the
// failure mode a stopped container (connection refused) does not show.
const container = (await compose('ps', '-q', s3Service)).split(
'\n',
)[0];
await docker('pause', container);
try {
const started = Date.now();
const content = await request<ApiErrorBody>(
`/api/v1/attachments/${created.body.id}/content`,
{ headers: bearer(token) },
);
const elapsed = Date.now() - started;
expectBoundedOutage(content);
// S3_REQUEST_TIMEOUT_MS is 15 s in the stand; HAProxy gives up at 30 s.
expect(elapsed).toBeLessThan(20_000);
expect(
(
await request(
`/api/v1/attachments/${created.body.id}`,
{
headers: bearer(token),
},
)
).response.status,
).toBe(200);
expect((await request('/health/ready')).response.status).toBe(
200,
);
} finally {
await docker('unpause', container);
}
const bytes = await fetch(
`${baseUrl}/api/v1/attachments/${created.body.id}/content`,
{ headers: bearer(token) },
);
expect(bytes.status).toBe(200);
expect(
Buffer.from(await bytes.arrayBuffer()).equals(samplePng),
).toBe(true);
},
outagedRequestBudgetMs,
);
it(
'keeps the object while PostgreSQL is down before ready and sweeps it afterwards',
async () => {