Dont use setInterval in work in progress test suite

This commit is contained in:
Daniel García Aubert 2016-11-24 16:21:28 +01:00
parent 9a63006719
commit 99a8b794dc

View File

@ -2,6 +2,7 @@ require('../../helper');
var assert = require('../../support/assert');
var BatchTestClient = require('../../support/batch-test-client');
var JobStatus = require('../../../batch/job_status');
describe('batch work in progress endpoint happy cases', function() {
@ -22,7 +23,7 @@ describe('batch work in progress endpoint happy cases', function() {
it('should get a list of work in progress jobs group by user', function (done) {
var self = this;
var user = 'vizzuality';
var queries = ['select pg_sleep(0.5)'];
var queries = ['select pg_sleep(3)'];
var payload = jobPayload(queries);
self.batchTestClient.createJob(payload, function(err, jobResult) {
@ -30,33 +31,38 @@ describe('batch work in progress endpoint happy cases', function() {
return done(err);
}
var interval = setInterval(function () {
jobResult.getStatus(JobStatus.RUNNING, function (err) {
if (err) {
return done(err);
}
self.batchTestClient.getWorkInProgressJobs(function (err, workInProgressJobs) {
if (err) {
clearInterval(interval);
return done(err);
}
if (workInProgressJobs[user]) {
assert.ok(Array.isArray(workInProgressJobs[user]));
assert.ok(workInProgressJobs[user].length >= 1);
for (var i = 0; i < workInProgressJobs[user].length; i++) {
if (workInProgressJobs[user][i] === jobResult.job.job_id) {
clearInterval(interval);
return done();
}
}
clearInterval(interval);
return done(new Error('Job should not be in work-in-progress list'));
if (!workInProgressJobs[user]) {
return done(new Error('User should be in work-in-progress list'));
}
assert.ok(Array.isArray(workInProgressJobs[user]));
assert.ok(workInProgressJobs[user].length >= 1);
for (var i = 0; i < workInProgressJobs[user].length; i++) {
if (workInProgressJobs[user][i] === jobResult.job.job_id) {
return jobResult.cancel(done);
}
}
return done(new Error('Job should not be in work-in-progress list'));
});
}, 50);
});
});
});
it('should get a list of work in progress jobs w/o the finished ones', function (done) {
var self = this;
var user = 'vizzuality';
var queries = ['select pg_sleep(0.05)'];
var queries = ['select pg_sleep(0)'];
var payload = jobPayload(queries);
self.batchTestClient.createJob(payload, function(err, jobResult) {
@ -64,10 +70,13 @@ describe('batch work in progress endpoint happy cases', function() {
return done(err);
}
var interval = setInterval(function () {
jobResult.getStatus(function (err) {
if (err) {
return done(err);
}
self.batchTestClient.getWorkInProgressJobs(function (err, workInProgressJobs) {
if (err) {
clearInterval(interval);
return done(err);
}
@ -76,15 +85,13 @@ describe('batch work in progress endpoint happy cases', function() {
assert.ok(workInProgressJobs[user].length >= 1);
for (var i = 0; i < workInProgressJobs[user].length; i++) {
if (workInProgressJobs[user][i] === jobResult.job.job_id) {
clearInterval(interval);
return done(new Error('Job should not be in work-in-progress list'));
}
}
}
clearInterval(interval);
return done();
done();
});
}, 50);
});
});
});
});