Skip to content

Commit

Permalink
test(worker): add fixed backoff type test case (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Jan 20, 2024
1 parent cd3034f commit b289819
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/test_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,55 @@ describe('workers', function () {
});
});

describe('when backoff type is fixed', () => {
it("updates job's delay property and respects fixed delay value", async () => {
const worker = new Worker(
queueName,
async () => {
throw new Error('error');
},
{ connection, prefix },
);
await worker.waitUntilReady();

await queue.add(
'test',
{ bar: 'baz' },
{
attempts: 4,
backoff: {
type: 'fixed',
delay: 750,
},
},
);

const now = Date.now();
const failed = new Promise<void>((resolve, reject) => {
worker.on('failed', async job => {
try {
const attemptsMade = job?.attemptsMade;
if (attemptsMade! > 3) {
expect(job!.delay).to.be.eql(0);
const gotJob = await queue.getJob(job.id!);
expect(gotJob!.delay).to.be.eql(0);
const timeDiff = Date.now() - now;
expect(timeDiff).to.be.greaterThanOrEqual(2250);
expect(timeDiff).to.be.lessThanOrEqual(2750);
resolve();
}
} catch (err) {
reject(err);
}
});
});

await failed;

await worker.close();
});
});

describe('when attempts is 1 and job fails', () => {
it('should execute job only once and emits retries-exhausted event', async () => {
const worker = new Worker(
Expand Down

0 comments on commit b289819

Please sign in to comment.