lab4: компенсация без потери объекта при потере ответа COMMIT, полный декод изображений (sharp) в proxy и direct complete

This commit is contained in:
2026-10-23 16:37:13 +03:00
parent b32ce9a75d
commit 4badd5a7b9
33 changed files with 1932 additions and 861 deletions
+24 -11
View File
@@ -944,12 +944,13 @@ describe.skipIf(!enabled)('dependency outages', () => {
expect((await request('/health/ready')).response.status).toBe(
200,
);
// Compensation could not reach S3, so the row stays for the sweeper.
// Compensation claimed the row but could not delete the object:
// the row stays in `deleting`, tracked for the sweeper.
expect(
await psql(
`select count(*) from attachments where chat_id = '${chat.id}' and status = 'pending' and filename = 's3down-${runId}.png'`,
`select status from attachments where chat_id = '${chat.id}' and filename = 's3down-${runId}.png'`,
),
).toBe('1');
).toBe('deleting');
} finally {
await compose('start', s3Service);
}
@@ -966,18 +967,27 @@ describe.skipIf(!enabled)('dependency outages', () => {
const after = await upload(samplePng, `s3after-${runId}.png`);
expect(after.response.status).toBe(201);
const filter = `chat_id = '${chat.id}' and status = 'pending' and filename = 's3down-${runId}.png'`;
await waitUntilExpired(filter);
await sweepNow();
expect(
await psql(`select count(*) from attachments where ${filter}`),
).toBe('0');
// A `deleting` row is re-claimed one minute after its last change
// (an in-flight compensation is never raced), then swept.
const filter = `chat_id = '${chat.id}' and filename = 's3down-${runId}.png'`;
await waitFor(
async () => {
await sweepNow();
return (
(await psql(
`select count(*) from attachments where ${filter}`,
)) === '0'
);
},
async () => 'deleting row was not swept',
90_000,
);
},
outagedRequestBudgetMs,
);
it(
'compensates the S3 write when PostgreSQL fails before ready',
'keeps the object while PostgreSQL is down before ready and sweeps it afterwards',
async () => {
const data = noisePng(1024 * 1024);
const filename = `pgfault-${runId}.png`;
@@ -1017,13 +1027,16 @@ describe.skipIf(!enabled)('dependency outages', () => {
`select object_key from attachments where ${filter}`,
);
expect(key).toMatch(/^attachments\/[0-9a-f-]{36}\/original$/u);
expect(await objectExists(key)).toBe(false);
// Without PostgreSQL the API cannot tell a lost commit from a failed
// one, so it deletes nothing; the pending row keeps the object tracked.
expect(await objectExists(key)).toBe(true);
await waitUntilExpired(filter);
await sweepNow();
expect(
await psql(`select count(*) from attachments where ${filter}`),
).toBe('0');
expect(await objectExists(key)).toBe(false);
},
outagedRequestBudgetMs,
);