forked from mtusi2026/mtusi2026lab5
lab5: e2e, fault suite и доказательства
This commit is contained in:
@@ -134,6 +134,35 @@ export function upload(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lab5 uploads answer 202 before the worker runs. Poll metadata until ready;
|
||||
* a failed attachment is a test failure, never a silent timeout.
|
||||
*/
|
||||
export async function waitReady(
|
||||
token: string,
|
||||
attachmentId: string,
|
||||
timeoutMs = 60_000,
|
||||
): Promise<Attachment> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
for (;;) {
|
||||
const result = await http<Attachment>(
|
||||
`/api/v1/attachments/${attachmentId}`,
|
||||
{ headers: bearer(token) },
|
||||
);
|
||||
expect(result.response.status).toBe(200);
|
||||
if (result.body.status === 'failed')
|
||||
throw new Error(
|
||||
`attachment ${attachmentId} failed: ${result.body.error_code ?? 'unknown'}`,
|
||||
);
|
||||
if (result.body.status === 'ready') return result.body;
|
||||
if (Date.now() >= deadline)
|
||||
throw new Error(
|
||||
`attachment ${attachmentId} did not become ready within ${timeoutMs}ms`,
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
}
|
||||
}
|
||||
|
||||
export async function download(
|
||||
token: string,
|
||||
attachmentId: string,
|
||||
|
||||
Reference in New Issue
Block a user