2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-13 04:40:09 +08:00
|
|
|
require('../../helper');
|
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
2019-10-04 00:24:39 +08:00
|
|
|
var redisUtils = require('../../support/redis-utils');
|
2016-10-17 18:28:01 +08:00
|
|
|
var TestClient = require('../../support/test-client');
|
2016-10-13 04:40:09 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('max queued jobs', function () {
|
|
|
|
before(function (done) {
|
2016-10-13 04:40:09 +08:00
|
|
|
this.batch_max_queued_jobs = global.settings.batch_max_queued_jobs;
|
|
|
|
global.settings.batch_max_queued_jobs = 1;
|
2019-10-04 00:24:39 +08:00
|
|
|
this.server = require('../../../lib/server')();
|
2016-10-17 18:28:01 +08:00
|
|
|
this.testClient = new TestClient();
|
|
|
|
this.testClient.getResult(
|
|
|
|
'drop table if exists max_queued_jobs_inserts; create table max_queued_jobs_inserts (status numeric)',
|
|
|
|
done
|
|
|
|
);
|
2016-10-13 04:40:09 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
global.settings.batch_max_queued_jobs = this.batch_max_queued_jobs;
|
2016-11-22 21:09:16 +08:00
|
|
|
redisUtils.clean('batch:*', done);
|
2016-10-13 04:40:09 +08:00
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
function createJob (server, status, callback) {
|
2016-10-13 04:40:09 +08:00
|
|
|
assert.response(
|
|
|
|
server,
|
|
|
|
{
|
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
|
|
|
headers: {
|
|
|
|
host: 'vizzuality.cartodb.com',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
method: 'POST',
|
|
|
|
data: JSON.stringify({
|
2019-12-24 01:19:08 +08:00
|
|
|
query: 'insert into max_queued_jobs_inserts values (1)'
|
2016-10-13 04:40:09 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
status: status
|
|
|
|
},
|
2019-12-24 01:19:08 +08:00
|
|
|
function (err, res) {
|
2016-10-13 04:40:09 +08:00
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return callback(null, JSON.parse(res.body));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
it('POST /api/v2/sql/job should respond with 200 and the created job', function (done) {
|
|
|
|
var self = this;
|
2019-12-24 01:19:08 +08:00
|
|
|
createJob(this.server, 201, function (err) {
|
2016-10-13 04:40:09 +08:00
|
|
|
assert.ok(!err);
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
createJob(self.server, 400, function (err, res) {
|
2016-10-13 04:40:09 +08:00
|
|
|
assert.ok(!err);
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(res.error[0], 'Failed to create job. Max number of jobs (' +
|
2019-12-24 01:19:08 +08:00
|
|
|
global.settings.batch_max_queued_jobs + ') queued reached');
|
2016-10-13 04:40:09 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|