update tests with sync or promise workers
This commit is contained in:
@@ -313,9 +313,8 @@ describe('Worker class', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call the workerFn with the payload', function (done) {
|
it('should call the workerFn with the payload', function (done) {
|
||||||
const workerFn = function (jobPayload, cb) {
|
const workerFn = function (jobPayload) {
|
||||||
expect(jobPayload).to.eql(payload);
|
expect(jobPayload).to.eql(payload);
|
||||||
cb();
|
|
||||||
};
|
};
|
||||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||||
|
|
||||||
@@ -324,9 +323,9 @@ describe('Worker class', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update the job with the workerFn output', function () {
|
it('should update the job with the workerFn output', function () {
|
||||||
const workerFn = function (jobPayload, cb) {
|
const workerFn = function (jobPayload) {
|
||||||
expect(jobPayload).to.eql(payload);
|
expect(jobPayload).to.eql(payload);
|
||||||
cb(null, payload);
|
return payload;
|
||||||
};
|
};
|
||||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||||
|
|
||||||
@@ -346,9 +345,11 @@ describe('Worker class', function () {
|
|||||||
|
|
||||||
it('should update the job status and completed time', function () {
|
it('should update the job status and completed time', function () {
|
||||||
const startTime = moment().valueOf();
|
const startTime = moment().valueOf();
|
||||||
const workerFn = function (jobPayload, cb) {
|
const workerFn = function (jobPayload) {
|
||||||
expect(jobPayload).to.eql(payload);
|
expect(jobPayload).to.eql(payload);
|
||||||
setTimeout(() => cb(null, payload), 10);
|
return new Promise(function (resolve) {
|
||||||
|
setTimeout(() => resolve(payload), 10);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||||
|
|
||||||
@@ -364,8 +365,8 @@ describe('Worker class', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should append error output to job', function () {
|
it('should append error output to job', function () {
|
||||||
const workerFn = function (jobPayload, cb) {
|
const workerFn = function () {
|
||||||
cb(new Error('test error'));
|
throw new Error('test error');
|
||||||
};
|
};
|
||||||
const worker = new Worker(mockQueue, 'test', workerFn);
|
const worker = new Worker(mockQueue, 'test', workerFn);
|
||||||
const failStub = sinon.stub(worker, '_failJob');
|
const failStub = sinon.stub(worker, '_failJob');
|
||||||
@@ -386,10 +387,12 @@ describe('Worker class', function () {
|
|||||||
const timeoutPadding = 10;
|
const timeoutPadding = 10;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
const workerFn = function (jobPayload, cb) {
|
const workerFn = function () {
|
||||||
|
return new Promise(function (resolve) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
cb();
|
resolve();
|
||||||
}, timeout + timeoutPadding);
|
}, timeout + timeoutPadding);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
worker = new Worker(mockQueue, 'test', workerFn);
|
worker = new Worker(mockQueue, 'test', workerFn);
|
||||||
job = {
|
job = {
|
||||||
|
|||||||
Reference in New Issue
Block a user