Skip to content

Commit

Permalink
test: support AbortSignal
Browse files Browse the repository at this point in the history
  • Loading branch information
BerkliumBirb committed Oct 14, 2024
1 parent 4d7c5d5 commit a2e92f5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ test('should default to 3 attempts with 200 delay', async (t) => {
handleError: null,
handleTimeout: null,
beforeAttempt: null,
calculateDelay: null
calculateDelay: null,
signal: null
});

attemptCount++;
Expand Down Expand Up @@ -530,6 +531,21 @@ test('should allow attempts to be aborted via handleError', async (t) => {
t.is(err.retryable, false);
});

test('should allow attempts to be aborted via AbortSignal', async (t) => {
const contoller = new AbortController();
const err = await t.throws(retry(async (context) => {
if (context.attemptNum === 1) {
contoller.abort();
}
throw new Error('try again');
}, {
delay: 0,
maxAttempts: 4,
signal: contoller.signal
}));
t.is(err.code, 'ATTEMPT_ABORTED');
});

test('should wait for async handleError to resolve before retrying', async (t) => {
let promiseHasResolved = false;
await t.notThrows(retry(async ({ attemptNum }) => {
Expand Down

0 comments on commit a2e92f5

Please sign in to comment.