Fixed unit test for job queue and moved isJobFound function as private method in job backend

This commit is contained in:
Daniel García Aubert 2016-01-22 12:43:41 +01:00
parent 0ad83e0051
commit 5c4d239467
5 changed files with 43 additions and 40 deletions

View File

@ -1,5 +1,5 @@
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
4. Drop npm-shrinkwrap.json
5. Run npm shrinkwrap to recreate npm-shrinkwrap.json

View File

@ -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) {
var self = this;
var redisParams = [
this.redisPrefix + job_id,
'user',
@ -162,11 +167,7 @@ JobBackend.prototype.get = function (job_id, callback) {
return callback(err);
}
function isJobFound(jobValues) {
return jobValues[0] && jobValues[1] && jobValues[2] && jobValues[3] && jobValues[4];
}
if (!isJobFound(jobValues)) {
if (!self._isJobFound(jobValues)) {
var notFoundError = new Error('Job with id ' + job_id + ' not found');
notFoundError.name = 'NotFoundError';
return callback(notFoundError);

View File

@ -1,8 +1,10 @@
'use strict';
var errorCodes = require('../app/postgresql/error_codes');
var PSQL = require('cartodb-psql');
var QUERY_CANCELED = '57014';
function JobRunner(jobBackend, userDatabaseMetadataService) {
this.jobBackend = jobBackend;
this.userDatabaseMetadataService = userDatabaseMetadataService;
@ -58,7 +60,7 @@ JobRunner.prototype._query = function (job, userDatabaseMetadata, callback) {
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 (err.code === QUERY_CANCELED) {
if (errorCodes[err.code] === 'query_canceled') {
return self.jobBackend.get(job.job_id, callback);
}

View 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();
});
});
});

View File

@ -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();
});
});
});