2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-21 20:35:24 +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');
|
|
|
|
var redisUtils = require('../../support/redis-utils');
|
2016-10-21 20:35:24 +08:00
|
|
|
var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() });
|
2018-07-19 23:30:05 +08:00
|
|
|
const db_utils = require('../../support/db_utils');
|
2016-10-21 20:35:24 +08:00
|
|
|
|
|
|
|
describe('batch query statement_timeout limit', function() {
|
|
|
|
|
|
|
|
before(function(done) {
|
|
|
|
this.batchTestClient = new BatchTestClient();
|
|
|
|
this.batchQueryTimeout = global.settings.batch_query_timeout;
|
|
|
|
global.settings.batch_query_timeout = 15000;
|
|
|
|
metadataBackend.redisCmd(5, 'HMSET', ['limits:batch:vizzuality', 'timeout', 100], done);
|
|
|
|
});
|
2018-07-19 23:30:05 +08:00
|
|
|
before(db_utils.resetPgBouncerConnections);
|
2016-10-21 20:35:24 +08:00
|
|
|
after(function(done) {
|
|
|
|
global.settings.batch_query_timeout = this.batchQueryTimeout;
|
|
|
|
redisUtils.clean('limits:batch:*', function() {
|
|
|
|
this.batchTestClient.drain(done);
|
|
|
|
}.bind(this));
|
|
|
|
});
|
2018-07-19 23:30:05 +08:00
|
|
|
after(db_utils.resetPgBouncerConnections);
|
2016-10-21 20:35:24 +08:00
|
|
|
|
|
|
|
function jobPayload(query) {
|
|
|
|
return {
|
|
|
|
query: query
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should cancel with user statement_timeout limit', function (done) {
|
|
|
|
var payload = jobPayload('select pg_sleep(10)');
|
|
|
|
this.batchTestClient.createJob(payload, function(err, jobResult) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
jobResult.getStatus(function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
assert.equal(job.status, JobStatus.FAILED);
|
|
|
|
assert.ok(job.failed_reason.match(/statement.*timeout/));
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|