From 0f7a22439c363a797ccef37c1a14c080e53b969e Mon Sep 17 00:00:00 2001 From: Mn Date: Thu, 19 Nov 2026 23:33:42 +0800 Subject: [PATCH] Synchronize browser test request assertions Advancing fake time does not guarantee a result poll has reached its Playwright route handler. An enabled Practice editor also does not prove the asynchronous room join has completed. Both tests can check their counts before setup is ready. Wait for the intercepted poll and the existing room-join observable before checking pending-result and cache-restoration behavior. Keep the count, result, editor and unload-warning assertions, and bound the poll wait with the test timeout. Change-Id: I95ae4339a0f0e4f7c4f39e1aa0b9b1e1e72463b1 --- tests/browser/strict-selection.test.js | 1 + tests/browser/task-workspace.test.js | 87 +++++++++++++++----------- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/tests/browser/strict-selection.test.js b/tests/browser/strict-selection.test.js index eeaf67170..ecc1ddbe7 100644 --- a/tests/browser/strict-selection.test.js +++ b/tests/browser/strict-selection.test.js @@ -1975,6 +1975,7 @@ for (const selection of ["strict", "practice"]) { if (!page) return; await preflight(page); await page.locator("#editor:not([disabled])").waitFor(); + await page.waitForFunction(() => window.roomJoins.length === 1); await page.locator("#editor").fill("active attempt must survive"); await page.waitForFunction(() => { const event = new Event("beforeunload", { cancelable: true }); diff --git a/tests/browser/task-workspace.test.js b/tests/browser/task-workspace.test.js index 41b49d5c0..eccec2552 100644 --- a/tests/browser/task-workspace.test.js +++ b/tests/browser/task-workspace.test.js @@ -3224,44 +3224,57 @@ test("a Finish dialog open when the attempt ends closes and finishes nothing", a } }); -test("a result poll still on its way neither repeats nor replaces the delivered result", async (t) => { - const ctx = await pageFor(t); - if (!ctx) return; - const { page } = ctx; - let held = 0; - const releases = []; - try { - await start(page); - await page.route("**/api/task-reviews/**", async (route) => { - held += 1; - await new Promise((resolve) => releases.push(resolve)); - await route.fulfill({ - status: 202, - contentType: "application/json", - body: JSON.stringify({ pending: true }), - }); +test( + "a result poll still on its way neither repeats nor replaces the delivered result", + { timeout: 30000 }, + async (t) => { + const ctx = await pageFor(t); + if (!ctx) return; + const { page } = ctx; + let held = 0; + const releases = []; + let polling; + const pollStarted = new Promise((resolve) => { + polling = resolve; }); - await page.evaluate(() => document.exitFullscreen()); - // Past the delivery window, with the first poll still unanswered. - await page.clock.runFor(301000); - assert.equal(held, 1); - await page.evaluate( - (value) => globalThis.taskHarness.publish("task_review", value), - result("invalid", "fullscreen"), - ); - await page.locator("#review").waitFor({ state: "visible" }); - for (const release of releases) release(); - await page.clock.runFor(1000); - assert.match(await page.locator("#outcome").textContent(), /invalid/); - assert.doesNotMatch( - await page.locator("#review-content").textContent(), - /still being finalized|unavailable/i, - ); - } finally { - for (const release of releases) release(); - await page.close(); - } -}); + try { + await start(page); + await page.route("**/api/task-reviews/**", async (route) => { + held += 1; + polling(); + await new Promise((resolve) => releases.push(resolve)); + await route.fulfill({ + status: 202, + contentType: "application/json", + body: JSON.stringify({ pending: true }), + }); + }); + await page.evaluate(() => document.exitFullscreen()); + // Past the delivery window, with the first poll still unanswered. + await page.clock.runFor(301000); + // Advancing the page clock does not flush Playwright's network events. + await pollStarted; + assert.equal(held, 1); + await page.evaluate( + (value) => globalThis.taskHarness.publish("task_review", value), + result("invalid", "fullscreen"), + ); + await page.locator("#review").waitFor({ state: "visible" }); + const answered = page.waitForResponse("**/api/task-reviews/**"); + for (const release of releases) release(); + await answered; + await page.clock.runFor(1000); + assert.match(await page.locator("#outcome").textContent(), /invalid/); + assert.doesNotMatch( + await page.locator("#review-content").textContent(), + /still being finalized|unavailable/i, + ); + } finally { + for (const release of releases) release(); + await page.close(); + } + }, +); test("an ended attempt lets go of a wake lock granted late and of its detector", async (t) => { const ctx = await pageFor(t);