2016-11-02 20:03:22 +08:00
|
|
|
require('../../helper');
|
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var BatchTestClient = require('../../support/batch-test-client');
|
2016-11-24 23:21:28 +08:00
|
|
|
var JobStatus = require('../../../batch/job_status');
|
2016-11-02 20:03:22 +08:00
|
|
|
|
|
|
|
describe('batch work in progress endpoint happy cases', function() {
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
this.batchTestClient = new BatchTestClient();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function(done) {
|
|
|
|
this.batchTestClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
function jobPayload(query) {
|
|
|
|
return {
|
|
|
|
query: query
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should get a list of work in progress jobs group by user', function (done) {
|
|
|
|
var self = this;
|
|
|
|
var user = 'vizzuality';
|
2016-11-24 23:21:28 +08:00
|
|
|
var queries = ['select pg_sleep(3)'];
|
2016-11-02 20:03:22 +08:00
|
|
|
var payload = jobPayload(queries);
|
|
|
|
|
|
|
|
self.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-11-24 23:21:28 +08:00
|
|
|
jobResult.getStatus(JobStatus.RUNNING, function (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-11-02 20:03:22 +08:00
|
|
|
self.batchTestClient.getWorkInProgressJobs(function (err, workInProgressJobs) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-24 23:21:28 +08:00
|
|
|
|
|
|
|
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);
|
2016-11-02 20:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 23:21:28 +08:00
|
|
|
|
|
|
|
return done(new Error('Job should not be in work-in-progress list'));
|
2016-11-02 20:03:22 +08:00
|
|
|
});
|
2016-11-24 23:21:28 +08:00
|
|
|
});
|
2016-11-02 20:03:22 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get a list of work in progress jobs w/o the finished ones', function (done) {
|
|
|
|
var self = this;
|
|
|
|
var user = 'vizzuality';
|
2016-11-24 23:21:28 +08:00
|
|
|
var queries = ['select pg_sleep(0)'];
|
2016-11-02 20:03:22 +08:00
|
|
|
var payload = jobPayload(queries);
|
|
|
|
|
|
|
|
self.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-22 21:06:32 +08:00
|
|
|
|
2016-11-24 23:21:28 +08:00
|
|
|
jobResult.getStatus(function (err) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-11-02 20:03:22 +08:00
|
|
|
self.batchTestClient.getWorkInProgressJobs(function (err, workInProgressJobs) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2016-11-22 21:06:32 +08:00
|
|
|
|
|
|
|
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) {
|
|
|
|
return done(new Error('Job should not be in work-in-progress list'));
|
|
|
|
}
|
2016-11-02 20:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 23:21:28 +08:00
|
|
|
done();
|
2016-11-02 20:03:22 +08:00
|
|
|
});
|
2016-11-24 23:21:28 +08:00
|
|
|
});
|
2016-11-02 20:03:22 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|