fix(rest): correct exponential backoff delay from seconds to milliseconds (#3806)

Co-authored-by: Adam Dickinson <adickinson@demandbase.com>
This commit is contained in:
adickinson72 2025-12-28 13:41:33 -06:00 committed by GitHub
parent dabdba7702
commit fcd2cb40ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -115,9 +115,9 @@ export async function defaultRequestHandler(endpoint: string, options?: RequestO
if (response.ok) return parseResponse(response, asStream);
if (!retryCodes.includes(response.status)) await throwFailedRequestError(request, response);
// Retry
// Retry with exponential backoff (in milliseconds)
lastStatus = response.status;
await delay(2 ** i * 0.25);
await delay(2 ** i * 250);
continue;
}

View File

@ -377,6 +377,8 @@ describe('defaultRequestHandler', () => {
});
it('should return a default error if retries are unsuccessful', async () => {
jest.useFakeTimers();
const responseContent = { error: 'msg' };
const fakeReturnValue = Promise.resolve(
Promise.resolve(
@ -392,14 +394,21 @@ describe('defaultRequestHandler', () => {
mockFetch.mockReturnValue(fakeReturnValue);
const error = await getError<GitbeakerRetryError>(() =>
const errorPromise = getError<GitbeakerRetryError>(() =>
defaultRequestHandler('http://test.com', {} as RequestOptions),
);
// Fast-forward through all retry delays
await jest.runAllTimersAsync();
const error = await errorPromise;
expect(error.message).toBe(
'Could not successfully complete this request after 10 retries, last status code: 429. Check the applicable rate limits for this endpoint.',
);
expect(error).toBeInstanceOf(GitbeakerRetryError);
jest.useRealTimers();
});
it('should return correct properties if request is valid', async () => {