fix(core): increase default retry attempts and add quota error backoff (#19949)

This commit is contained in:
Sehoon Shon
2026-02-23 10:13:34 -05:00
committed by GitHub
parent ac04c388e0
commit ec0f23ae03
2 changed files with 27 additions and 16 deletions
+18 -12
View File
@@ -101,33 +101,33 @@ describe('retryWithBackoff', () => {
expect(mockFn).toHaveBeenCalledTimes(3);
});
it('should default to 3 maxAttempts if no options are provided', async () => {
// This function will fail more than 3 times to ensure all retries are used.
const mockFn = createFailingFunction(5);
it('should default to 10 maxAttempts if no options are provided', async () => {
// This function will fail more than 10 times to ensure all retries are used.
const mockFn = createFailingFunction(15);
const promise = retryWithBackoff(mockFn);
await Promise.all([
expect(promise).rejects.toThrow('Simulated error attempt 3'),
expect(promise).rejects.toThrow('Simulated error attempt 10'),
vi.runAllTimersAsync(),
]);
expect(mockFn).toHaveBeenCalledTimes(3);
expect(mockFn).toHaveBeenCalledTimes(10);
});
it('should default to 3 maxAttempts if options.maxAttempts is undefined', async () => {
// This function will fail more than 3 times to ensure all retries are used.
const mockFn = createFailingFunction(5);
it('should default to 10 maxAttempts if options.maxAttempts is undefined', async () => {
// This function will fail more than 10 times to ensure all retries are used.
const mockFn = createFailingFunction(15);
const promise = retryWithBackoff(mockFn, { maxAttempts: undefined });
// Expect it to fail with the error from the 3rd attempt.
// Expect it to fail with the error from the 10th attempt.
await Promise.all([
expect(promise).rejects.toThrow('Simulated error attempt 3'),
expect(promise).rejects.toThrow('Simulated error attempt 10'),
vi.runAllTimersAsync(),
]);
expect(mockFn).toHaveBeenCalledTimes(3);
expect(mockFn).toHaveBeenCalledTimes(10);
});
it('should not retry if shouldRetry returns false', async () => {
@@ -541,7 +541,13 @@ describe('retryWithBackoff', () => {
await vi.runAllTimersAsync();
await assertionPromise;
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 12345);
expect(setTimeoutSpy).toHaveBeenCalledWith(
expect.any(Function),
expect.any(Number),
);
const calledDelayMs = setTimeoutSpy.mock.calls[0][1];
expect(calledDelayMs).toBeGreaterThanOrEqual(12345);
expect(calledDelayMs).toBeLessThanOrEqual(12345 * 1.2);
});
it.each([[AuthType.USE_GEMINI], [AuthType.USE_VERTEX_AI], [undefined]])(