MCPcopy
hub / github.com/Comfy-Org/ComfyUI-Manager / waitForAllDone

Function waitForAllDone

tests/playwright/legacy-ui-install.spec.ts:16–77  ·  view source on GitHub ↗
(page: import('@playwright/test').Page, timeoutMs = 90_000)

Source from the content-addressed store, hash-verified

14const PACK_CNR_ID = 'comfyui_sigmoidoffsetscheduler';
15
16async function waitForAllDone(page: import('@playwright/test').Page, timeoutMs = 90_000): Promise<void> {
17 // Three-phase polling with DETERMINISTIC baseline:
18 // Phase 0 — snapshot baseline. To make the baseline deterministic across
19 // runs (and immune to leaking history from prior tests in the
20 // session), we FETCH the baseline immediately after the caller
21 // has triggered the UI action. The caller is expected to have
22 // called /v2/manager/queue/reset at the start of its test flow
23 // so that done_count starts at 0 for this test's session.
24 // Phase 1 — wait for task acceptance:
25 // total_count > 0 OR is_processing=true OR done_count > baseline
26 // Phase 2 — wait for drain (total_count === 0 && is_processing=false)
27 const deadline = Date.now() + timeoutMs;
28
29 // Phase 0: baseline. If fetch fails, treat as 0 but log so the test signal
30 // isn't silently degraded.
31 let baselineDone = 0;
32 const baselineResp = await page.request
33 .get('/v2/manager/queue/status')
34 .catch(() => null);
35 if (baselineResp && baselineResp.ok()) {
36 const baseline = await baselineResp.json();
37 baselineDone = baseline?.done_count ?? 0;
38 } else {
39 console.warn('[waitForAllDone] baseline fetch failed — treating as 0');
40 }
41
42 // Phase 1: task acceptance
43 const acceptDeadline = Math.min(Date.now() + 15_000, deadline);
44 let accepted = false;
45 while (Date.now() < acceptDeadline) {
46 const status = await page.request
47 .get('/v2/manager/queue/status')
48 .then((r) => r.json())
49 .catch(() => null);
50 if (
51 status &&
52 ((status.total_count ?? 0) > 0 ||
53 status.is_processing === true ||
54 (status.done_count ?? 0) > baselineDone)
55 ) {
56 accepted = true;
57 break;
58 }
59 await page.waitForTimeout(500);
60 }
61 if (!accepted) {
62 throw new Error('Queue never accepted the task (empty queue for 15s after UI action)');
63 }
64
65 // Phase 2: drain
66 while (Date.now() < deadline) {
67 const status = await page.request
68 .get('/v2/manager/queue/status')
69 .then((r) => r.json())
70 .catch(() => null);
71 if (status && status.is_processing === false && (status.total_count ?? 0) === 0) {
72 return;
73 }

Callers 1

Calls 1

getMethod · 0.45

Tested by

no test coverage detected