mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-14 16:10:59 -07:00
refactor: set max retry attempts to 3 (#11072)
This commit is contained in:
@@ -96,34 +96,34 @@ describe('retryWithBackoff', () => {
|
|||||||
expect(mockFn).toHaveBeenCalledTimes(3);
|
expect(mockFn).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should default to 5 maxAttempts if no options are provided', async () => {
|
it('should default to 3 maxAttempts if no options are provided', async () => {
|
||||||
// This function will fail more than 5 times to ensure all retries are used.
|
// This function will fail more than 3 times to ensure all retries are used.
|
||||||
const mockFn = createFailingFunction(10);
|
const mockFn = createFailingFunction(10);
|
||||||
|
|
||||||
const promise = retryWithBackoff(mockFn);
|
const promise = retryWithBackoff(mockFn);
|
||||||
|
|
||||||
// Expect it to fail with the error from the 5th attempt.
|
// Expect it to fail with the error from the 5th attempt.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
expect(promise).rejects.toThrow('Simulated error attempt 10'),
|
expect(promise).rejects.toThrow('Simulated error attempt 3'),
|
||||||
vi.runAllTimersAsync(),
|
vi.runAllTimersAsync(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(mockFn).toHaveBeenCalledTimes(10);
|
expect(mockFn).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should default to 10 maxAttempts if options.maxAttempts is undefined', async () => {
|
it('should default to 3 maxAttempts if options.maxAttempts is undefined', async () => {
|
||||||
// This function will fail more than 5 times to ensure all retries are used.
|
// This function will fail more than 3 times to ensure all retries are used.
|
||||||
const mockFn = createFailingFunction(10);
|
const mockFn = createFailingFunction(10);
|
||||||
|
|
||||||
const promise = retryWithBackoff(mockFn, { maxAttempts: undefined });
|
const promise = retryWithBackoff(mockFn, { maxAttempts: undefined });
|
||||||
|
|
||||||
// Expect it to fail with the error from the 5th attempt.
|
// Expect it to fail with the error from the 5th attempt.
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
expect(promise).rejects.toThrow('Simulated error attempt 10'),
|
expect(promise).rejects.toThrow('Simulated error attempt 3'),
|
||||||
vi.runAllTimersAsync(),
|
vi.runAllTimersAsync(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(mockFn).toHaveBeenCalledTimes(10);
|
expect(mockFn).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not retry if shouldRetry returns false', async () => {
|
it('should not retry if shouldRetry returns false', async () => {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export interface RetryOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_RETRY_OPTIONS: RetryOptions = {
|
const DEFAULT_RETRY_OPTIONS: RetryOptions = {
|
||||||
maxAttempts: 10,
|
maxAttempts: 3,
|
||||||
initialDelayMs: 5000,
|
initialDelayMs: 5000,
|
||||||
maxDelayMs: 30000, // 30 seconds
|
maxDelayMs: 30000, // 30 seconds
|
||||||
shouldRetryOnError: defaultShouldRetry,
|
shouldRetryOnError: defaultShouldRetry,
|
||||||
|
|||||||
Reference in New Issue
Block a user