Fixed issues in batch tests:

- Wait for batch is ready before testing it
 - Remove batch keys in redis after testing every suit
 - Fixed issue creating jobs with same id in job service integration test
This commit is contained in:
Daniel García Aubert 2016-07-22 14:27:18 +02:00
parent 0586f45413
commit 2e8382eeff
21 changed files with 132 additions and 65 deletions

View File

@ -34,14 +34,16 @@ describe('batch module', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -96,18 +96,20 @@ describe('Batch API callback templates', function () {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
describe.skip('should use templates for error_message and job_id onerror callback', function () {
describe('should use templates for error_message and job_id onerror callback', function () {
var jobResponse;
before(function(done) {
getQueryResult('create table test_batch_errors (job_id text, error_message text)', function(err) {

View File

@ -37,14 +37,16 @@ describe('Batch API fallback job', function () {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -46,7 +46,10 @@ describe('job query limit', function() {
after(function (done) {
// batch services is not activate, so we need empty the queue to avoid unexpected
// behaviour in further tests
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
it('POST /api/v2/sql/job with a invalid query size should respond with 400 query too long', function (done){

View File

@ -31,7 +31,10 @@ describe('job module', function() {
after(function (done) {
// batch services is not activate, so we need empty the queue to avoid unexpected
// behaviour in further tests
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
it('POST /api/v2/sql/job should respond with 200 and the created job', function (done){

View File

@ -73,14 +73,16 @@ describe('Batch API query timing', function () {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,17 @@ describe('Use case 1: cancel and modify a done job', function () {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 10: cancel and modify a done multiquery job', function () {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 2: cancel a running job', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 3: cancel a pending job', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 4: modify a pending job', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 5: modify a running job', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 6: modify a done job', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 7: cancel a job with quotes', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 8: cancel a running multiquery job', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -32,14 +32,16 @@ describe('Use case 9: modify a pending multiquery job', function() {
var batch = batchFactory(metadataBackend, redisConfig);
before(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
after(function (done) {
batch.stop();
batch.drain(function () {
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});

View File

@ -35,7 +35,6 @@ var jobQueue = new JobQueue(metadataBackend, jobPublisher);
var userIndexer = new UserIndexer(metadataBackend);
var jobBackend = new JobBackend(metadataBackend, jobQueue, userIndexer);
var USER = 'vizzuality';
var HOST = 'localhost';
@ -68,16 +67,21 @@ function assertJob(job, expectedStatus, done) {
};
}
describe.skip('batch multiquery', function() {
describe('batch multiquery', function() {
var batch = batchFactory(metadataBackend, redisConfig, statsdClient);
beforeEach(function () {
before(function (done) {
batch.start();
batch.on('ready', done);
});
afterEach(function () {
after(function (done) {
batch.removeAllListeners();
batch.stop();
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
it('should perform one multiquery job with two queries', function (done) {

View File

@ -47,6 +47,13 @@ function createWadusJob() {
describe('job backend', function() {
var jobBackend = new JobBackend(metadataBackend, jobQueue, userIndexer);
after(function (done) {
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
it('.create() should persist a job', function (done) {
var job = createWadusJob();

View File

@ -85,6 +85,14 @@ function createWadusJob(query) {
describe('job canceller', function() {
var jobCanceller = new JobCanceller(userDatabaseMetadataService);
after(function (done) {
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
it('.cancel() should cancel a job', function (done) {
var job = createWadusJob('select pg_sleep(1)');

View File

@ -53,6 +53,13 @@ var JOB = {
describe('job runner', function() {
var jobRunner = new JobRunner(jobService, jobQueue, queryRunner, statsdClient);
after(function (done) {
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
it('.run() should run a job', function (done) {
jobService.create(JOB, function (err, job) {
if (err) {

View File

@ -45,6 +45,10 @@ var JOB = {
host: HOST
};
function createWadusDataJob() {
return JSON.parse(JSON.stringify(JOB));
}
// sets job to running, run its query and returns inmediatly (don't wait for query finishes)
// in order to test query cancelation/draining
function runQueryHelper(job, callback) {
@ -82,8 +86,15 @@ function runQueryHelper(job, callback) {
describe('job service', function() {
var jobService = new JobService(jobBackend, jobCanceller);
after(function (done) {
metadataBackend.redisCmd(5, 'KEYS', [ 'batch:*'], function (err, keys) {
if (err) { return done(err); }
metadataBackend.redisCmd(5, 'DEL', keys, done);
});
});
it('.get() should return a job', function (done) {
jobService.create(JOB, function (err, jobCreated) {
jobService.create(createWadusDataJob(), function (err, jobCreated) {
if (err) {
return done(err);
}
@ -108,7 +119,7 @@ describe('job service', function() {
});
it('.create() should persist a job', function (done) {
jobService.create(JOB, function (err, jobCreated) {
jobService.create(createWadusDataJob(), function (err, jobCreated) {
if (err) {
return done(err);
}
@ -120,7 +131,7 @@ describe('job service', function() {
});
it('.create() should return error with invalid job data', function (done) {
var job = JSON.parse(JSON.stringify(JOB));
var job = createWadusDataJob();
delete job.query;
@ -132,7 +143,7 @@ describe('job service', function() {
});
it('.list() should return a list of user\'s jobs', function (done) {
jobService.create(JOB, function (err, jobCreated) {
jobService.create(createWadusDataJob(), function (err, jobCreated) {
if (err) {
return done(err);
}
@ -164,7 +175,7 @@ describe('job service', function() {
});
it('.update() should update a job', function (done) {
jobService.create(JOB, function (err, jobCreated) {
jobService.create(createWadusDataJob(), function (err, jobCreated) {
if (err) {
return done(err);
}
@ -184,7 +195,8 @@ describe('job service', function() {
});
it('.update() should return error when updates a nonexistent job', function (done) {
var job = JSON.parse(JSON.stringify(JOB));
var job = createWadusDataJob();
job.job_id = 'wadus_job_id';
jobService.update(job, function (err) {
@ -196,11 +208,8 @@ describe('job service', function() {
});
it('.cancel() should cancel a running job', function (done) {
var job = {
user: USER,
query: 'select pg_sleep(3)',
host: HOST
};
var job = createWadusDataJob();
job.query = 'select pg_sleep(3)';
jobService.create(job, function (err, job) {
if (err) {
@ -235,11 +244,8 @@ describe('job service', function() {
});
it('.drain() should draing a running job', function (done) {
var job = {
user: USER,
query: 'select pg_sleep(3)',
host: HOST
};
var job = createWadusDataJob();
job.query = 'select pg_sleep(3)';
jobService.create(job, function (err, job) {
if (err) {