simplify job error tests
This commit is contained in:
@@ -220,6 +220,21 @@ describe('Worker class', function () {
|
|||||||
sinon.stub(mockQueue.client, 'update').returns(Promise.reject({ statusCode: 409 }));
|
sinon.stub(mockQueue.client, 'update').returns(Promise.reject({ statusCode: 409 }));
|
||||||
return worker._failJob(job);
|
return worker._failJob(job);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set completed time and status to failed', function () {
|
||||||
|
const startTime = moment().valueOf();
|
||||||
|
const msg = 'test message';
|
||||||
|
clock.tick(100);
|
||||||
|
|
||||||
|
worker._failJob(job, msg);
|
||||||
|
const doc = updateSpy.firstCall.args[0].body.doc;
|
||||||
|
expect(doc).to.have.property('output');
|
||||||
|
expect(doc).to.have.property('status', JOB_STATUS_FAILED);
|
||||||
|
expect(doc).to.have.property('completed_at');
|
||||||
|
const completedTimestamp = moment(doc.completed_at).valueOf();
|
||||||
|
expect(completedTimestamp).to.be.greaterThan(startTime);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('performing a job', function () {
|
describe('performing a job', function () {
|
||||||
@@ -311,49 +326,19 @@ describe('Worker class', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append erorr output to job', function (done) {
|
it('should append error output to job', function (done) {
|
||||||
const workerFn = function (jobPayload, cb) {
|
|
||||||
cb(new Error('test error'));
|
|
||||||
};
|
|
||||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
|
||||||
|
|
||||||
worker._performJob(job)
|
|
||||||
.then(() => done(new Error('should not resolve')))
|
|
||||||
.catch((err) => {
|
|
||||||
try {
|
|
||||||
sinon.assert.calledOnce(updateSpy);
|
|
||||||
const query = updateSpy.firstCall.args[0];
|
|
||||||
expect(query).to.have.property('index', job._index);
|
|
||||||
expect(query).to.have.property('type', job._type);
|
|
||||||
expect(query).to.have.property('id', job._id);
|
|
||||||
expect(query).to.have.property('version', job._version);
|
|
||||||
expect(query.body.doc).to.have.property('output');
|
|
||||||
expect(query.body.doc.output).to.have.property('content_type', false);
|
|
||||||
expect(query.body.doc.output).to.have.property('content', err.toString());
|
|
||||||
done();
|
|
||||||
} catch (e) {
|
|
||||||
done(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set completed time and status to failed', function (done) {
|
|
||||||
const startTime = moment().valueOf();
|
|
||||||
const workerFn = function (jobPayload, cb) {
|
const workerFn = function (jobPayload, cb) {
|
||||||
cb(new Error('test error'));
|
cb(new Error('test error'));
|
||||||
};
|
};
|
||||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||||
|
const failStub = sinon.stub(worker, '_failJob');
|
||||||
|
|
||||||
worker._performJob(job)
|
worker._performJob(job)
|
||||||
.then(() => done(new Error('should not resolve')))
|
.then(() => done(new Error('should not resolve')))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
try {
|
try {
|
||||||
sinon.assert.calledOnce(updateSpy);
|
sinon.assert.calledOnce(failStub);
|
||||||
const doc = updateSpy.firstCall.args[0].body.doc;
|
sinon.assert.calledWith(failStub, job, 'Error: test error');
|
||||||
expect(doc).to.have.property('status', JOB_STATUS_FAILED);
|
|
||||||
expect(doc).to.have.property('completed_at');
|
|
||||||
const completedTimestamp = moment(doc.completed_at).valueOf();
|
|
||||||
expect(completedTimestamp).to.be.greaterThan(startTime);
|
|
||||||
done();
|
done();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user