Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't wait for retries in tests #7433

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ describe("versions upload", () => {
const { setIsTTY } = useMockIsTTY();
const std = mockConsoleMethods();

beforeEach(() => {
vi.stubGlobal("setTimeout", (fn: () => void) => {
setImmediate(fn);
});
});

afterEach(() => {
vi.unstubAllGlobals();
});

function mockGetScript() {
msw.use(
http.get(
Expand Down
10 changes: 6 additions & 4 deletions packages/wrangler/src/utils/retry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { setTimeout } from "node:timers/promises";

export async function retryOnError<T>(
action: () => T | Promise<T>,
backoff = 2_000,
Expand All @@ -12,7 +10,11 @@ export async function retryOnError<T>(
throw err;
}

await setTimeout(backoff);
return retryOnError(action, backoff, attempts - 1);
return new Promise((accept) => {
setTimeout(
() => accept(retryOnError(action, backoff, attempts - 1)),
backoff
);
});
}
}
Loading