From 69b328eec8904ecd40eb713b09d0cd523951cdc0 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Tue, 27 Oct 2026 08:04:29 +0800 Subject: [PATCH] test(browser): verify out-of-order response correlation --- tests/boundary/browser/cdpConnection.test.ts | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/boundary/browser/cdpConnection.test.ts b/tests/boundary/browser/cdpConnection.test.ts index 2ec08c8e49..f57a1ad702 100644 --- a/tests/boundary/browser/cdpConnection.test.ts +++ b/tests/boundary/browser/cdpConnection.test.ts @@ -107,7 +107,7 @@ describe("CDP connection admission cancellation", () => { describe("CDP connection response correlation", () => { it("correlates concurrent command responses over a real WebSocket", async () => { - const browser = await startFakeCdpBrowser(); + const browser = await startFakeCdpBrowser({ hangOnMethod: "Page.enable" }); browsers.push(browser); const connection = await CdpConnection.connect( browser.browserWebSocketUrl, @@ -124,6 +124,28 @@ describe("CDP connection response correlation", () => { }); browser.emitRawMessage(JSON.stringify({ id: 999 })); await expect(connection.send("Runtime.enable")).resolves.toEqual({}); + const first = connection.send("Page.enable", { selected: "first" }); + const second = connection.send("Page.enable", { selected: "second" }); + const replies = Promise.all([first, second]); + await vi.waitFor(() => expect(browser.commands).toHaveLength(5)); + const firstCommand = browser.commands[3]; + const secondCommand = browser.commands[4]; + if (firstCommand === undefined || secondCommand === undefined) + throw new Error("Fake browser did not receive both pending commands"); + browser.emitRawMessage( + JSON.stringify({ + id: secondCommand.id, + result: { selected: "second" }, + }), + ); + browser.emitRawMessage( + JSON.stringify({ id: firstCommand.id, result: { selected: "first" } }), + ); + await expect(replies).resolves.toEqual([ + { selected: "first" }, + { selected: "second" }, + ]); + await expect(connection.send("Runtime.enable")).resolves.toEqual({}); } finally { await connection.close(); }