add tests for various failure types
This commit is contained in:
@@ -500,6 +500,7 @@ describe('Worker class', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('worker success', function () {
|
||||
it('should call the workerFn with the payload', function (done) {
|
||||
const workerFn = function (jobPayload) {
|
||||
expect(jobPayload).to.eql(payload);
|
||||
@@ -551,7 +552,9 @@ describe('Worker class', function () {
|
||||
expect(completedTimestamp).to.be.greaterThan(startTime);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('worker failure', function () {
|
||||
it('should append error output to job', function () {
|
||||
const workerFn = function () {
|
||||
throw new Error('test error');
|
||||
@@ -565,6 +568,61 @@ describe('Worker class', function () {
|
||||
sinon.assert.calledWith(failStub, job, 'Error: test error');
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle async errors', function () {
|
||||
const workerFn = function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject(new Error('test error'));
|
||||
});
|
||||
};
|
||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||
const failStub = sinon.stub(worker, '_failJob');
|
||||
|
||||
return worker._performJob(job)
|
||||
.then(() => {
|
||||
sinon.assert.calledOnce(failStub);
|
||||
sinon.assert.calledWith(failStub, job, 'Error: test error');
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle rejecting with strings', function () {
|
||||
const errorMessage = 'this is a string error';
|
||||
const workerFn = function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject(errorMessage);
|
||||
});
|
||||
};
|
||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||
const failStub = sinon.stub(worker, '_failJob');
|
||||
|
||||
return worker._performJob(job)
|
||||
.then(() => {
|
||||
sinon.assert.calledOnce(failStub);
|
||||
sinon.assert.calledWith(failStub, job, errorMessage);
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle empty rejection', function (done) {
|
||||
const workerFn = function () {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject();
|
||||
});
|
||||
};
|
||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||
const failStub = sinon.stub(worker, '_failJob');
|
||||
|
||||
worker.once('job_error', (err) => {
|
||||
try {
|
||||
expect(err).to.have.property('type', 'UnspecifiedWorkerError');
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
|
||||
worker._performJob(job);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('job timing', function () {
|
||||
|
||||
Reference in New Issue
Block a user