Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions packages/browser-pay/src/interceptor.protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,18 +1110,31 @@ describe("interceptor CDP decisions", () => {
...paused,
params: { ...paused.params, requestId: "req-b" },
});
await new Promise((resolve) => setTimeout(resolve, 40));
expect(calls).toBe(1);
release();
await waitFor(
() =>
stub.commands.filter(
(command) => command.method === "Fetch.failRequest",
(command) =>
command.method === "Runtime.evaluate" &&
command.params.expression === "location.origin",
).length >= 2,
"both failed",
"second origin",
);
// The stub writes this reply before the command is visible. setImmediate
// runs after the poll that applies it, which is when req-b joins.
await new Promise((resolve) => setImmediate(resolve));
Comment thread
cursor[bot] marked this conversation as resolved.
expect(calls).toBe(1);
release();
await waitFor(
() => events.filter((event) => event.type === "refused").length >= 2,
"both refused",
);
expect(calls).toBe(1);
expect(warnings).toEqual(["payment relay refused the paused request"]);
expect(
stub.commands.filter(
(command) => command.method === "Fetch.failRequest",
),
).toHaveLength(2);
expect(events.filter((event) => event.type === "refused")).toHaveLength(
2,
);
Expand Down
16 changes: 8 additions & 8 deletions packages/browser-pay/src/interceptor.relay-in-progress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,9 @@ describe("relay_in_progress", () => {
},
placeholder: HELD,
profileId: "shopify-card-vault",
timeoutMs: 500,
// The later waiter starts after the retry post, so its deadline trails
// the first by about one poll backoff. 1.5s keeps that gap if a timer fires late.
timeoutMs: 1_500,
});
handle.on((event) => events.push(event));
try {
Expand All @@ -812,8 +814,7 @@ describe("relay_in_progress", () => {
"Fetch.enable",
);
emitPaused(cdp, "req-early-deadline");
await waitFor(() => calls === 1, "first post");
await new Promise((resolve) => setTimeout(resolve, 40));
await waitFor(() => calls === 2, "retry posted");
emitPaused(cdp, "req-later-deadline");
await waitFor(
() =>
Expand Down Expand Up @@ -1111,8 +1112,8 @@ describe("relay retry before the deadline", () => {
},
placeholder: HELD,
profileId: "shopify-card-vault",
timeoutMs: 2_000,
attemptTimeoutMs: 120,
timeoutMs: 5_000,
attemptTimeoutMs: 400,
});
try {
armPage(cdp);
Expand All @@ -1122,16 +1123,15 @@ describe("relay retry before the deadline", () => {
);
emitPaused(cdp, "req-shared-a");
await waitFor(() => calls === 1, "first attempt");
await new Promise((resolve) => setTimeout(resolve, 80));
emitPaused(cdp, "req-shared-b");
await waitFor(
() => count(cdp.commands, "Fetch.fulfillRequest") === 2,
"both fulfilled",
);
expect(calls).toBe(2);
expect(aborts).toHaveLength(1);
expect(aborts[0]).toBeGreaterThanOrEqual(100);
expect(aborts[0]).toBeLessThan(160);
expect(aborts[0]).toBeGreaterThanOrEqual(300);
expect(aborts[0]).toBeLessThan(2_000);
expect(count(cdp.commands, "Fetch.failRequest")).toBe(0);
} finally {
await handle.detach();
Expand Down
Loading