CartoDB-SQL-API/test/acceptance/export/timeout-test.js

203 lines
6.3 KiB
JavaScript
Raw Normal View History

2018-10-24 21:42:33 +08:00
'use strict';
const TestClient = require('../../support/test-client');
require('../../support/assert');
var assert = require('assert');
var querystring = require('querystring');
const db_utils = require('../../support/db_utils');
2017-08-09 18:53:59 +08:00
describe('timeout', function () {
describe('export database', function () {
before(db_utils.resetPgBouncerConnections);
after(db_utils.resetPgBouncerConnections);
2017-08-09 18:53:59 +08:00
const databaseTimeoutQuery = `
select
ST_SetSRID(ST_Point(0, 0), 4326) as the_geom,
pg_sleep(0.2) as sleep,
1 as value
`;
const scenarios = [
{
desc: 'CSV',
format: 'csv',
contentType: 'application/x-www-form-urlencoded',
parser: querystring.stringify,
// only: true,
skip: true
},
{
query: databaseTimeoutQuery,
desc: 'Geopackage',
format: 'gpkg'
},
{
query: databaseTimeoutQuery,
desc: 'KML',
format: 'kml'
},
{
query: databaseTimeoutQuery,
desc: 'Shapefile',
format: 'shp'
},
{
query: databaseTimeoutQuery,
desc: 'Spatialite',
format: 'spatialite'
},
{
query: databaseTimeoutQuery,
desc: 'Array Buffer',
format: 'arraybuffer'
},
{
query: databaseTimeoutQuery,
desc: 'GeoJSON',
format: 'geojson'
},
{
query: databaseTimeoutQuery,
desc: 'JSON',
format: 'json'
},
{
query: databaseTimeoutQuery,
desc: 'SVG',
format: 'svg'
},
{
query: databaseTimeoutQuery,
desc: 'TopoJSON',
format: 'topojson'
}
];
beforeEach(function (done) {
this.testClient = new TestClient();
this.testClient.setUserDatabaseTimeoutLimit('localhost', 100, done);
});
afterEach(function (done) {
this.testClient.setUserDatabaseTimeoutLimit('localhost', 2000, done);
});
2017-08-09 18:53:59 +08:00
scenarios.forEach((scenario) => {
const test = scenario.only ? it.only : scenario.skip ? it.skip : it;
test(`${scenario.desc} export exceeding statement timeout responds 429 Over Limits`, function (done) {
const override = {
'Content-Type': scenario.contentType,
parser: scenario.parser,
anonymous: true,
format: scenario.format,
response: {
status: 429
}
};
this.testClient.getResult(scenario.query, override, (err, res) => {
assert.ifError(err);
2019-12-26 21:01:18 +08:00
assert.deepStrictEqual(res, {
2017-08-09 18:53:59 +08:00
error: [
2018-06-29 19:19:32 +08:00
'You are over platform\'s limits: SQL query timeout error.' +
2019-12-24 01:19:08 +08:00
' Refactor your query before running again or contact CARTO support for more details.'
2018-03-26 21:56:50 +08:00
],
2018-03-27 21:49:38 +08:00
context: 'limit',
detail: 'datasource'
2017-08-09 18:53:59 +08:00
});
done();
});
2017-08-09 18:53:59 +08:00
});
});
});
describe('export ogr command timeout', function () {
const ogrCommandTimeoutQuery = `
select
ST_SetSRID(ST_Point(0, 0), 4326) as the_geom,
pg_sleep(0.2) as sleep,
1 as value
`;
const scenarios = [
{
query: ogrCommandTimeoutQuery,
desc: 'CSV',
format: 'csv',
contentType: 'application/x-www-form-urlencoded',
2019-12-24 01:19:08 +08:00
parser: querystring.stringify
2017-08-09 18:53:59 +08:00
// only: true,
// skip: true
},
{
query: ogrCommandTimeoutQuery,
filename: 'wadus_gpkg_filename',
desc: 'Geopackage',
format: 'gpkg'
},
{
query: ogrCommandTimeoutQuery,
desc: 'KML',
format: 'kml'
},
{
query: ogrCommandTimeoutQuery,
desc: 'Shapefile',
format: 'shp'
},
{
query: ogrCommandTimeoutQuery,
desc: 'Spatialite',
format: 'spatialite'
}
];
beforeEach(function (done) {
this.testClient = new TestClient();
this.testClient.setUserRenderTimeoutLimit('vizzuality', 100, done);
});
afterEach(function (done) {
this.testClient.setUserRenderTimeoutLimit('vizzuality', 0, done);
});
scenarios.forEach((scenario) => {
const test = scenario.only ? it.only : scenario.skip ? it.skip : it;
test(`${scenario.desc} export exceeding statement timeout responds 429 Over Limits`, function (done) {
const override = {
'Content-Type': scenario.contentType,
parser: scenario.parser,
anonymous: true,
format: scenario.format,
filename: scenario.filename,
response: {
status: 429
}
};
2017-08-09 18:53:59 +08:00
this.testClient.getResult(scenario.query, override, (err, res) => {
assert.ifError(err);
2019-12-26 21:01:18 +08:00
assert.deepStrictEqual(res, {
2017-08-09 18:53:59 +08:00
error: [
2018-06-29 19:19:32 +08:00
'You are over platform\'s limits: SQL query timeout error.' +
2019-12-24 01:19:08 +08:00
' Refactor your query before running again or contact CARTO support for more details.'
2018-03-26 21:56:50 +08:00
],
2018-03-27 21:49:38 +08:00
context: 'limit',
detail: 'datasource'
2017-08-09 18:53:59 +08:00
});
done();
});
});
});
});
});