Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(job): add case when using custom error #2360

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/test_job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,29 @@ describe('Job', function () {
expect(isFailed2).to.be.equal(true);
expect(job.stacktrace).not.be.equal(null);
expect(job.stacktrace.length).to.be.equal(1);
expect(job.stacktrace[0]).to.include('test_job.ts');
await worker.close();
});

describe('when using a custom error', function () {
it('marks the job as failed', async function () {
class CustomError extends Error {}
const worker = new Worker(queueName, null, { connection, prefix });
const token = 'my-token';
await Job.create(queue, 'test', { foo: 'bar' });
const job = (await worker.getNextJob(token)) as Job;
const isFailed = await job.isFailed();
expect(isFailed).to.be.equal(false);
await job.moveToFailed(new CustomError('test error'), '0', true);
const isFailed2 = await job.isFailed();
expect(isFailed2).to.be.equal(true);
expect(job.stacktrace).not.be.equal(null);
expect(job.stacktrace.length).to.be.equal(1);
expect(job.stacktrace[0]).to.include('test_job.ts');
await worker.close();
});
});

it('moves the job to wait for retry if attempts are given', async function () {
const queueEvents = new QueueEvents(queueName, { connection, prefix });
await queueEvents.waitUntilReady();
Expand Down