mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-12 18:15:48 +00:00
fix: tolerate null retryable check
This commit is contained in:
1 parent
c21f589247
commit
54f3b6860a
2 files changed
+21
-1
No files matched your search
@@ -25,6 +25,26 @@ describe('withRetry', () => {
|
|||||||
expect(fn).toHaveBeenCalledTimes(3);
|
expect(fn).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses the default retryability check when retryableCheck is null at runtime', async () => {
|
||||||
|
let attempt = 0;
|
||||||
|
const fn = mock(() => {
|
||||||
|
attempt++;
|
||||||
|
if (attempt < 2) {
|
||||||
|
return Promise.reject(new RetryableError('transient failure'));
|
||||||
|
}
|
||||||
|
return Promise.resolve('ok');
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await withRetry(fn, {
|
||||||
|
maxRetries: 3,
|
||||||
|
baseDelayMs: 1,
|
||||||
|
retryableCheck: null,
|
||||||
|
} as unknown as RetryOptions);
|
||||||
|
|
||||||
|
expect(result).toBe('ok');
|
||||||
|
expect(fn).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
it('throws after max retries exhausted', async () => {
|
it('throws after max retries exhausted', async () => {
|
||||||
const fn = mock(() => Promise.reject(new RetryableError('always fails')));
|
const fn = mock(() => Promise.reject(new RetryableError('always fails')));
|
||||||
await expect(withRetry(fn, { maxRetries: 2, baseDelayMs: 1 })).rejects.toThrow('always fails');
|
await expect(withRetry(fn, { maxRetries: 2, baseDelayMs: 1 })).rejects.toThrow('always fails');
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export async function withRetry<T>(fn: () => Promise<T>, options: RetryOptions):
|
|||||||
throw new Error('withRetry: baseDelayMs must be >= 0');
|
throw new Error('withRetry: baseDelayMs must be >= 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
const isRetryable = retryableCheck;
|
const isRetryable = retryableCheck ?? defaultRetryableCheck;
|
||||||
let lastError: unknown;
|
let lastError: unknown;
|
||||||
|
|
||||||
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
||||||
|
|||||||
Reference in new issue
Block a user