chore: do not retry the model request if the user has aborted the request (#11224)

This commit is contained in:
Adam Weidman
2025-10-20 17:21:49 +02:00
committed by GitHub
parent a788a6df48
commit 8731309d7c
5 changed files with 199 additions and 12 deletions

View File

@@ -500,4 +500,25 @@ describe('retryWithBackoff', () => {
expect(fallbackCallback).toHaveBeenCalledWith('oauth-personal');
});
});
it('should abort the retry loop when the signal is aborted', async () => {
const abortController = new AbortController();
const mockFn = vi.fn().mockImplementation(async () => {
const error: HttpError = new Error('Server error');
error.status = 500;
throw error;
});
const promise = retryWithBackoff(mockFn, {
maxAttempts: 5,
initialDelayMs: 100,
signal: abortController.signal,
});
await vi.advanceTimersByTimeAsync(50);
abortController.abort();
await expect(promise).rejects.toThrow(
expect.objectContaining({ name: 'AbortError' }),
);
expect(mockFn).toHaveBeenCalledTimes(1);
});
});