2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-10 18:01:36 +08:00
|
|
|
require('../../helper');
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
|
2016-10-10 21:22:50 +08:00
|
|
|
var BatchTestClient = require('../../support/batch-test-client');
|
2019-10-04 00:24:39 +08:00
|
|
|
var JobStatus = require('../../../lib/batch/job-status');
|
2016-10-10 18:01:36 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
describe('job query timeout', function () {
|
|
|
|
before(function () {
|
2016-10-10 18:01:36 +08:00
|
|
|
this.batchQueryTimeout = global.settings.batch_query_timeout;
|
|
|
|
this.batchTestClient = new BatchTestClient();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (done) {
|
|
|
|
global.settings.batch_query_timeout = this.batchQueryTimeout;
|
|
|
|
return this.batchTestClient.drain(done);
|
|
|
|
});
|
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
function createTimeoutQuery (query, timeout) {
|
2016-10-10 18:01:36 +08:00
|
|
|
return {
|
|
|
|
query: {
|
|
|
|
query: [
|
|
|
|
{
|
|
|
|
timeout: timeout,
|
|
|
|
query: query
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should run query with higher user timeout', function (done) {
|
2019-12-24 01:19:08 +08:00
|
|
|
var jobRequest = createTimeoutQuery('select pg_sleep(0.1)', 200);
|
|
|
|
this.batchTestClient.createJob(jobRequest, function (err, jobResult) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-24 01:19:08 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(job.status, JobStatus.DONE);
|
2016-10-10 18:01:36 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail to run query with lower user timeout', function (done) {
|
2019-12-24 01:19:08 +08:00
|
|
|
var jobRequest = createTimeoutQuery('select pg_sleep(0.1)', 50);
|
|
|
|
this.batchTestClient.createJob(jobRequest, function (err, jobResult) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-24 01:19:08 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(job.status, JobStatus.FAILED);
|
2016-10-10 18:01:36 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail to run query with user timeout if it is higher than config', function (done) {
|
|
|
|
global.settings.batch_query_timeout = 100;
|
2019-12-24 01:19:08 +08:00
|
|
|
var jobRequest = createTimeoutQuery('select pg_sleep(1)', 2000);
|
|
|
|
this.batchTestClient.createJob(jobRequest, function (err, jobResult) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-24 01:19:08 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(job.status, JobStatus.FAILED);
|
2016-10-10 18:01:36 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail to run query with user timeout if set to 0 (ignored timeout)', function (done) {
|
|
|
|
global.settings.batch_query_timeout = 100;
|
2019-12-24 01:19:08 +08:00
|
|
|
var jobRequest = createTimeoutQuery('select pg_sleep(1)', 0);
|
|
|
|
this.batchTestClient.createJob(jobRequest, function (err, jobResult) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-24 01:19:08 +08:00
|
|
|
jobResult.getStatus(function (err, job) {
|
2016-10-10 18:01:36 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-26 21:01:18 +08:00
|
|
|
assert.strictEqual(job.status, JobStatus.FAILED);
|
2016-10-10 18:01:36 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|