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
4 changes: 2 additions & 2 deletions packages/rest/src/Requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 10 additions & 1 deletion packages/rest/test/unit/Requester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 () => {
Expand Down