Fixed unit test for job queue and moved isJobFound function as private method in job backend
This commit is contained in:
parent
0ad83e0051
commit
5c4d239467
@ -1,5 +1,5 @@
|
|||||||
1. Test (make clean all check), fix if broken before proceeding
|
1. Test (make clean all check), fix if broken before proceeding
|
||||||
2. Ensure proper version in package.json
|
2. Ensure proper version in package.json
|
||||||
3. Ensure NEWS section exists for the new version, review it, add release date
|
3. Ensure NEWS section exists for the new version, review it, add release date
|
||||||
4. Drop npm-shrinkwrap.json
|
4. Drop npm-shrinkwrap.json
|
||||||
5. Run npm shrinkwrap to recreate npm-shrinkwrap.json
|
5. Run npm shrinkwrap to recreate npm-shrinkwrap.json
|
||||||
|
@ -146,7 +146,12 @@ JobBackend.prototype._getIndexedJob = function (job_id, username, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
JobBackend.prototype._isJobFound = function (jobValues) {
|
||||||
|
return jobValues[0] && jobValues[1] && jobValues[2] && jobValues[3] && jobValues[4];
|
||||||
|
};
|
||||||
|
|
||||||
JobBackend.prototype.get = function (job_id, callback) {
|
JobBackend.prototype.get = function (job_id, callback) {
|
||||||
|
var self = this;
|
||||||
var redisParams = [
|
var redisParams = [
|
||||||
this.redisPrefix + job_id,
|
this.redisPrefix + job_id,
|
||||||
'user',
|
'user',
|
||||||
@ -162,11 +167,7 @@ JobBackend.prototype.get = function (job_id, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isJobFound(jobValues) {
|
if (!self._isJobFound(jobValues)) {
|
||||||
return jobValues[0] && jobValues[1] && jobValues[2] && jobValues[3] && jobValues[4];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isJobFound(jobValues)) {
|
|
||||||
var notFoundError = new Error('Job with id ' + job_id + ' not found');
|
var notFoundError = new Error('Job with id ' + job_id + ' not found');
|
||||||
notFoundError.name = 'NotFoundError';
|
notFoundError.name = 'NotFoundError';
|
||||||
return callback(notFoundError);
|
return callback(notFoundError);
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var errorCodes = require('../app/postgresql/error_codes');
|
||||||
var PSQL = require('cartodb-psql');
|
var PSQL = require('cartodb-psql');
|
||||||
var QUERY_CANCELED = '57014';
|
var QUERY_CANCELED = '57014';
|
||||||
|
|
||||||
|
|
||||||
function JobRunner(jobBackend, userDatabaseMetadataService) {
|
function JobRunner(jobBackend, userDatabaseMetadataService) {
|
||||||
this.jobBackend = jobBackend;
|
this.jobBackend = jobBackend;
|
||||||
this.userDatabaseMetadataService = userDatabaseMetadataService;
|
this.userDatabaseMetadataService = userDatabaseMetadataService;
|
||||||
@ -58,7 +60,7 @@ JobRunner.prototype._query = function (job, userDatabaseMetadata, callback) {
|
|||||||
|
|
||||||
query.on('error', function (err) {
|
query.on('error', function (err) {
|
||||||
// if query has been cancelled then it's going to get the current job status saved by query_canceller
|
// if query has been cancelled then it's going to get the current job status saved by query_canceller
|
||||||
if (err.code === QUERY_CANCELED) {
|
if (errorCodes[err.code] === 'query_canceled') {
|
||||||
return self.jobBackend.get(job.job_id, callback);
|
return self.jobBackend.get(job.job_id, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
test/unit/batch/job_queue.js
Normal file
33
test/unit/batch/job_queue.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
var JobQueue = require('../../../batch/job_queue');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
describe('batch API job queue', function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
this.metadataBackend = {
|
||||||
|
redisCmd: function () {
|
||||||
|
var callback = arguments[arguments.length -1];
|
||||||
|
process.nextTick(function () {
|
||||||
|
callback(null, 'irrelevantJob');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.jobQueue = new JobQueue(this.metadataBackend);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('.enqueue(username) should enqueue the provided job', function (done) {
|
||||||
|
this.jobQueue.enqueue('irrelevantJob', 'irrelevantHost', function (err, username) {
|
||||||
|
assert.ok(!err);
|
||||||
|
assert.equal(username, 'irrelevantJob');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('.dequeue(username) should dequeue the next job', function (done) {
|
||||||
|
this.jobQueue.dequeue('irrelevantHost', function (err, username) {
|
||||||
|
assert.ok(!err);
|
||||||
|
assert.equal(username, 'irrelevantJob');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -1,33 +0,0 @@
|
|||||||
var UsernameQueue = require('../../../batch/username_queue');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
describe('batch API username queue', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
this.metadataBackend = {
|
|
||||||
redisCmd: function () {
|
|
||||||
var callback = arguments[arguments.length -1];
|
|
||||||
process.nextTick(function () {
|
|
||||||
callback(null, 'irrelevantUsername');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.usernameQueue = new UsernameQueue(this.metadataBackend);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.enqueue(username) should enqueue the provided username', function (done) {
|
|
||||||
this.usernameQueue.enqueue('irrelevantUsername', function (err, username) {
|
|
||||||
assert.ok(!err);
|
|
||||||
assert.equal(username, 'irrelevantUsername');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('.dequeue(username) should dequeue the next username', function (done) {
|
|
||||||
this.usernameQueue.dequeue(function (err, username) {
|
|
||||||
assert.ok(!err);
|
|
||||||
assert.equal(username, 'irrelevantUsername');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user