Skip to content

Commit

Permalink
Merge pull request #126 from WeeverApps/master
Browse files Browse the repository at this point in the history
Fixes an issue where kue-scheduler would throw an error and die when `restore:true` was set and a downstream error occurred
  • Loading branch information
lykmapipo committed Apr 4, 2019
2 parents af47b9a + 9443e8d commit e59bab8
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -1467,7 +1467,7 @@ Queue.prototype.restore = function (done) {
this._getAllJobData(function (error, data) {
//backoff if error throw
if (error) {
done(error);
done.bind(this, error);
}

//restore job schedules
Expand Down
132 changes: 125 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -78,6 +78,7 @@
"grunt-mocha-test": "^0.13.3",
"jshint-stylish": "^2.2.1",
"mocha": "^5.2.0",
"moment": "^2.23.0"
"moment": "^2.23.0",
"sinon": "7.3.1"
}
}
21 changes: 21 additions & 0 deletions test/instatiation.spec.js
Expand Up @@ -3,6 +3,7 @@
//dependencies
var expect = require('chai').expect;
var path = require('path');
var sinon = require('sinon');
var kue = require(path.join(__dirname, '..', 'index'));
var Queue;

Expand Down Expand Up @@ -71,3 +72,23 @@ describe('Queue Job Scheduler & Listener', function () {
});

});

describe('Queue Job Scheduler & Listener Errors', function () {
var _getAllJobDataStub;
function fakeGetAllJobData (callback) {
callback(new Error('Some error occurred'));
}
beforeEach(function (done) {
_getAllJobDataStub = sinon.stub(kue.prototype, '_getAllJobData').callsFake(fakeGetAllJobData);
done();
});
afterEach(function (done) {
_getAllJobDataStub.restore();
done();
});
it('should not die with `TypeError: Cannot read property \'emit\' of undefined` when `restore:true`', function (done) {
Queue = kue.createQueue({restore: true});
expect(_getAllJobDataStub.called).to.be.true;
done();
});
});

0 comments on commit e59bab8

Please sign in to comment.