2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-11-02 20:03:22 +08:00
|
|
|
require('../../helper');
|
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var BatchTestClient = require('../../support/batch-test-client');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobStatus = require('../../../lib/batch/job-status');
|
2016-11-02 20:03:22 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('batch work in progress endpoint happy cases', function () {
|
|
|
|
before(function () {
|
2016-11-02 20:03:22 +08:00
|
|
|
this.batchTestClient = new BatchTestClient();
|
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
after(function (done) {
|
2016-11-02 20:03:22 +08:00
|
|
|
this.batchTestClient.drain(done);
|
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
function jobPayload (query) {
|
2016-11-02 20:03:22 +08:00
|
|
|
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);
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
self.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-02 20:03:22 +08:00
|
|
|
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);
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
self.batchTestClient.createJob(payload, function (err, jobResult) {
|
2016-11-02 20:03:22 +08:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|