2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2017-07-28 00:50:27 +08:00
|
|
|
|
|
|
|
const assert = require('../support/assert');
|
|
|
|
const TestClient = require('../support/test-client');
|
2019-10-07 16:10:51 +08:00
|
|
|
const serverOptions = require('../../lib/server-options');
|
2017-07-28 00:50:27 +08:00
|
|
|
|
2017-08-01 18:53:29 +08:00
|
|
|
const timeoutErrorTilePath = `${process.cwd()}/assets/render-timeout-fallback.png`;
|
|
|
|
|
2017-07-28 00:50:27 +08:00
|
|
|
const pointSleepSql = `
|
|
|
|
SELECT
|
2017-08-01 00:26:45 +08:00
|
|
|
pg_sleep(0.3),
|
2017-07-28 00:50:27 +08:00
|
|
|
'SRID=3857;POINT(0 0)'::geometry the_geom_webmercator,
|
|
|
|
1 cartodb_id,
|
|
|
|
2 val
|
|
|
|
`;
|
|
|
|
|
2017-08-01 16:21:39 +08:00
|
|
|
const validationPointSleepSql = `
|
|
|
|
SELECT
|
|
|
|
pg_sleep(0.3),
|
|
|
|
ST_Transform('SRID=4326;POINT(-180 85.05112877)'::geometry, 3857) the_geom_webmercator,
|
|
|
|
1 cartodb_id,
|
|
|
|
2 val
|
|
|
|
`;
|
|
|
|
|
2018-11-02 19:24:45 +08:00
|
|
|
const cartoCSSPoints = () => `
|
|
|
|
// cache buster: ${Date.now()}
|
|
|
|
#layer{
|
|
|
|
marker-placement: point;
|
|
|
|
marker-allow-overlap: true;
|
|
|
|
marker-line-opacity: 0.2;
|
|
|
|
marker-line-width: 0.5;
|
|
|
|
marker-opacity: 1;
|
|
|
|
marker-width: 5;
|
|
|
|
marker-fill: red;
|
|
|
|
}`;
|
|
|
|
|
2017-07-28 00:50:27 +08:00
|
|
|
const createMapConfig = ({
|
|
|
|
version = '1.6.0',
|
|
|
|
type = 'cartodb',
|
|
|
|
sql = pointSleepSql,
|
2018-11-02 19:24:45 +08:00
|
|
|
cartocss = cartoCSSPoints(),
|
2017-07-28 00:50:27 +08:00
|
|
|
cartocss_version = '2.3.0',
|
2017-08-01 16:21:39 +08:00
|
|
|
interactivity = 'cartodb_id',
|
2017-08-01 00:26:45 +08:00
|
|
|
countBy = 'cartodb_id',
|
|
|
|
attributes
|
2017-07-28 00:50:27 +08:00
|
|
|
} = {}) => ({
|
|
|
|
version,
|
|
|
|
layers: [{
|
|
|
|
type,
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'a0'
|
|
|
|
},
|
|
|
|
cartocss,
|
2017-08-01 00:26:45 +08:00
|
|
|
cartocss_version,
|
2017-08-01 16:21:39 +08:00
|
|
|
attributes,
|
|
|
|
interactivity
|
2017-07-28 00:50:27 +08:00
|
|
|
}
|
|
|
|
}],
|
|
|
|
analyses: [
|
|
|
|
{
|
|
|
|
id: 'a0',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: sql
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
dataviews: {
|
|
|
|
count: {
|
|
|
|
source: {
|
|
|
|
id: 'a0'
|
|
|
|
},
|
|
|
|
type: 'formula',
|
|
|
|
options: {
|
|
|
|
column: countBy,
|
|
|
|
operation: 'count'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-06 23:44:17 +08:00
|
|
|
const dbLimitErrorMessage = 'You are over platform\'s limits: SQL query timeout error.' +
|
2018-07-02 19:03:01 +08:00
|
|
|
' Refactor your query before running again or contact CARTO support for more details.';
|
|
|
|
|
2017-08-01 15:39:37 +08:00
|
|
|
const DATASOURCE_TIMEOUT_ERROR = {
|
2019-11-06 23:44:17 +08:00
|
|
|
errors: [dbLimitErrorMessage],
|
2017-08-01 15:39:37 +08:00
|
|
|
errors_with_context: [{
|
|
|
|
type: 'limit',
|
|
|
|
subtype: 'datasource',
|
2019-11-06 23:44:17 +08:00
|
|
|
message: dbLimitErrorMessage
|
2017-08-01 15:39:37 +08:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2018-11-06 02:10:08 +08:00
|
|
|
describe('user database timeout limit', function () {
|
2017-08-01 00:26:45 +08:00
|
|
|
describe('dataview', function () {
|
|
|
|
beforeEach(function (done) {
|
2017-07-28 00:50:27 +08:00
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-07-28 00:50:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
2017-08-01 00:52:09 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
2017-07-28 00:50:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('layergroup creation works but dataview request fails due to statement timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
response: {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-07-28 00:50:27 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-01 16:21:39 +08:00
|
|
|
this.testClient.getDataview('count', params, (err, timeoutError) => {
|
2017-07-28 00:50:27 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
|
2017-07-28 00:50:27 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-01 16:21:39 +08:00
|
|
|
describe('raster', function () {
|
|
|
|
describe('while validating in layergroup creation', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({ sql: validationPointSleepSql });
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
2017-08-01 16:21:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fails due to statement timeout', function (done) {
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, {
|
2019-11-06 23:44:17 +08:00
|
|
|
errors: [dbLimitErrorMessage],
|
2017-08-01 16:21:39 +08:00
|
|
|
errors_with_context: [{
|
|
|
|
type: 'limit',
|
|
|
|
subtype: 'datasource',
|
2019-11-06 23:44:17 +08:00
|
|
|
message: dbLimitErrorMessage,
|
2017-08-01 16:21:39 +08:00
|
|
|
layer: { id: 'layer0', index: 0, type: 'mapnik' }
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetching raster tiles', function () {
|
|
|
|
describe('with user\'s timeout of 200 ms', function () {
|
2017-08-01 18:53:29 +08:00
|
|
|
describe('with onTileErrorStrategy ENABLED', function () {
|
|
|
|
let onTileErrorStrategy;
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
|
|
|
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy;
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = true;
|
|
|
|
|
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 200,
|
2017-08-01 16:21:39 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
2017-08-01 18:53:29 +08:00
|
|
|
};
|
|
|
|
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, (err) => {
|
2017-08-01 18:53:29 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
|
2017-08-10 23:09:05 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2017-08-01 18:53:29 +08:00
|
|
|
|
2017-08-10 23:09:05 +08:00
|
|
|
this.layergroupid = res.layergroupid;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-08-01 18:53:29 +08:00
|
|
|
});
|
|
|
|
});
|
2017-08-01 16:21:39 +08:00
|
|
|
|
2017-08-01 18:53:29 +08:00
|
|
|
afterEach(function (done) {
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
2017-08-01 18:53:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('"png" fails due to statement timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
format: 'png',
|
2019-10-22 01:07:24 +08:00
|
|
|
layers: [0]
|
2017-08-01 18:53:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.imageIsSimilarToFile(tile, timeoutErrorTilePath, 0.05, (err) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-01 16:21:39 +08:00
|
|
|
|
2017-08-01 18:53:29 +08:00
|
|
|
it('"static png" fails due to statement timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
zoom: 0,
|
|
|
|
lat: 0,
|
|
|
|
lng: 0,
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
|
|
|
format: 'png'
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getStaticCenter(params, function (err, res, tile) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.imageIsSimilarToFile(tile, timeoutErrorTilePath, 0.05, (err) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
});
|
2017-08-01 17:58:43 +08:00
|
|
|
|
2017-08-01 18:53:29 +08:00
|
|
|
describe('with onTileErrorStrategy DISABLED', function () {
|
|
|
|
let onTileErrorStrategy;
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
|
|
|
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy;
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = false;
|
|
|
|
|
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 200,
|
2017-08-01 17:58:43 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
2017-08-01 18:53:29 +08:00
|
|
|
};
|
|
|
|
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, (err) => {
|
2017-08-01 18:53:29 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
|
2017-08-10 23:09:05 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2017-08-01 18:53:29 +08:00
|
|
|
|
2017-08-10 23:09:05 +08:00
|
|
|
this.layergroupid = res.layergroupid;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-08-01 18:53:29 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
|
|
|
|
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
2017-08-01 18:53:29 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('"png" fails due to statement timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
format: 'png',
|
2019-10-22 01:07:24 +08:00
|
|
|
layers: [0],
|
2017-08-01 18:53:29 +08:00
|
|
|
response: {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
|
2017-08-01 18:53:29 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('"static png" fails due to statement timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
zoom: 0,
|
|
|
|
lat: 0,
|
|
|
|
lng: 0,
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
|
|
|
format: 'png',
|
|
|
|
response: {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-08-01 17:58:43 +08:00
|
|
|
|
2017-08-01 18:53:29 +08:00
|
|
|
this.testClient.getStaticCenter(params, (err, res, timeoutError) => {
|
|
|
|
assert.ifError(err);
|
2017-08-01 17:58:43 +08:00
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
|
2017-08-01 17:58:43 +08:00
|
|
|
|
2017-08-01 18:53:29 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-08-01 17:58:43 +08:00
|
|
|
});
|
|
|
|
});
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('vector', function () {
|
|
|
|
describe('while validating in layergroup creation', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({ sql: validationPointSleepSql });
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
2017-08-01 16:21:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fails due to statement timeout', function (done) {
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, {
|
2019-11-06 23:44:17 +08:00
|
|
|
errors: [dbLimitErrorMessage],
|
2017-08-01 16:21:39 +08:00
|
|
|
errors_with_context: [{
|
|
|
|
type: 'limit',
|
|
|
|
subtype: 'datasource',
|
2019-11-06 23:44:17 +08:00
|
|
|
message: dbLimitErrorMessage,
|
2017-08-01 16:21:39 +08:00
|
|
|
layer: { id: 'layer0', index: 0, type: 'mapnik' }
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
describe('fetching vector tiles via mapnik renderer', () => testFetchingVectorTiles(false));
|
|
|
|
describe('fetching vector tiles via postgis renderer', () => testFetchingVectorTiles(true));
|
2018-10-17 01:51:22 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function testFetchingVectorTiles (usePostGIS) {
|
2018-10-17 01:51:22 +08:00
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = usePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
2017-08-01 16:21:39 +08:00
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
|
2017-08-01 16:21:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.layergroupid = res.layergroupid;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with user\'s timeout of 200 ms', function () {
|
|
|
|
beforeEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, done);
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
2018-11-02 20:57:56 +08:00
|
|
|
it('"mvt" fails due to statement timeout', function (done) {
|
2017-08-01 16:21:39 +08:00
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
format: 'mvt',
|
2019-10-22 01:07:24 +08:00
|
|
|
layers: [0],
|
2017-08-01 16:21:39 +08:00
|
|
|
response: {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
2017-11-07 18:08:01 +08:00
|
|
|
'Content-Type': 'application/x-protobuf'
|
2017-08-01 16:21:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-07 18:08:01 +08:00
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
|
2017-08-01 16:21:39 +08:00
|
|
|
assert.ifError(err);
|
2017-12-05 19:09:31 +08:00
|
|
|
|
2017-11-07 18:08:01 +08:00
|
|
|
var tileJSON = tile.toJSON();
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(Array.isArray(tileJSON), true);
|
|
|
|
assert.strictEqual(tileJSON.length, 2);
|
|
|
|
assert.strictEqual(tileJSON[0].name, 'errorTileSquareLayer');
|
|
|
|
assert.strictEqual(tileJSON[1].name, 'errorTileStripesLayer');
|
2017-12-05 19:09:31 +08:00
|
|
|
|
2017-08-01 16:21:39 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-17 01:51:22 +08:00
|
|
|
}
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('interactivity', function () {
|
|
|
|
describe('while validating in layergroup creation', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({ sql: validationPointSleepSql, interactivity: 'val' });
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
2017-08-01 16:21:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fails due to statement timeout', function (done) {
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, {
|
2019-11-06 23:44:17 +08:00
|
|
|
errors: [dbLimitErrorMessage],
|
2017-08-01 16:21:39 +08:00
|
|
|
errors_with_context: [{
|
|
|
|
type: 'limit',
|
|
|
|
subtype: 'datasource',
|
2019-11-06 23:44:17 +08:00
|
|
|
message: dbLimitErrorMessage,
|
2017-08-01 16:21:39 +08:00
|
|
|
layer: { id: 'layer0', index: 0, type: 'mapnik' }
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetching interactivity tiles', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({ interactivity: 'val' });
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
|
2017-08-01 16:21:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.layergroupid = res.layergroupid;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with user\'s timeout of 200 ms', function () {
|
|
|
|
beforeEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, done);
|
2017-08-01 16:21:39 +08:00
|
|
|
});
|
|
|
|
|
2017-08-01 16:29:46 +08:00
|
|
|
it('"grid.json" fails due to statement timeout', function (done) {
|
2017-08-01 16:21:39 +08:00
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
format: 'grid.json',
|
2017-08-01 16:29:46 +08:00
|
|
|
layers: 'mapnik',
|
2017-08-01 16:21:39 +08:00
|
|
|
response: {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
|
2017-08-01 16:21:39 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-06 19:17:39 +08:00
|
|
|
describe('torque', function () {
|
2017-08-01 00:26:45 +08:00
|
|
|
describe('while validating in layergroup creation', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({
|
|
|
|
type: 'torque',
|
|
|
|
cartocss: TestClient.CARTOCSS.TORQUE
|
|
|
|
});
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
2017-08-01 00:26:45 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fails due to statement timeout', function (done) {
|
|
|
|
const expectedResponse = {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-08-01 00:26:45 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, {
|
2019-11-06 23:44:17 +08:00
|
|
|
errors: [dbLimitErrorMessage],
|
2017-08-01 00:26:45 +08:00
|
|
|
errors_with_context: [{
|
2017-08-01 01:36:07 +08:00
|
|
|
type: 'limit',
|
|
|
|
subtype: 'datasource',
|
2019-11-06 23:44:17 +08:00
|
|
|
message: dbLimitErrorMessage,
|
2017-08-01 00:26:45 +08:00
|
|
|
layer: { id: 'torque-layer0', index: 0, type: 'torque' }
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-07-28 00:50:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-01 15:39:37 +08:00
|
|
|
describe('fetching torque tiles', function () {
|
|
|
|
beforeEach(function (done) {
|
2017-08-01 00:26:45 +08:00
|
|
|
const mapconfig = createMapConfig({
|
|
|
|
type: 'torque',
|
|
|
|
cartocss: TestClient.CARTOCSS.TORQUE
|
|
|
|
});
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
|
2017-08-01 00:26:45 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.layergroupid = res.layergroupid;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with user\'s timeout of 200 ms', function () {
|
|
|
|
beforeEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, done);
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
|
|
|
|
2017-08-01 15:39:37 +08:00
|
|
|
it('"torque.json" fails due to statement timeout', function (done) {
|
2017-08-01 00:26:45 +08:00
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
format: 'torque.json',
|
2019-10-22 01:07:24 +08:00
|
|
|
layers: [0],
|
2017-08-01 00:26:45 +08:00
|
|
|
response: {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-08-01 00:26:45 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-01 16:21:39 +08:00
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
|
2017-08-01 00:26:45 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
|
2017-08-01 15:39:37 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('".png" fails due to statement timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
format: 'torque.png',
|
2019-10-22 01:07:24 +08:00
|
|
|
layers: [0],
|
2017-08-01 15:39:37 +08:00
|
|
|
response: {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, attributes) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(attributes, DATASOURCE_TIMEOUT_ERROR);
|
2017-08-01 00:26:45 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-07-28 00:50:27 +08:00
|
|
|
});
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
2017-07-28 00:50:27 +08:00
|
|
|
|
2017-08-01 00:26:45 +08:00
|
|
|
describe('attributes:', function () {
|
|
|
|
describe('while validating in map instatiation', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({
|
|
|
|
attributes: {
|
|
|
|
id: 'cartodb_id',
|
2019-10-22 01:07:24 +08:00
|
|
|
columns: ['val']
|
2017-08-01 00:26:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
2017-07-28 00:50:27 +08:00
|
|
|
|
2017-08-01 00:26:45 +08:00
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
2017-08-01 00:26:45 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
2017-07-28 00:50:27 +08:00
|
|
|
});
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
2017-07-28 00:50:27 +08:00
|
|
|
|
2017-08-01 00:26:45 +08:00
|
|
|
it('layergroup creation fails due to statement timeout', function (done) {
|
|
|
|
const expectedResponse = {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-08-01 00:26:45 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
|
2019-10-25 00:38:37 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, {
|
2019-11-06 23:44:17 +08:00
|
|
|
errors: [dbLimitErrorMessage],
|
2017-08-01 00:26:45 +08:00
|
|
|
errors_with_context: [{
|
2017-08-01 01:36:07 +08:00
|
|
|
type: 'limit',
|
|
|
|
subtype: 'datasource',
|
2019-11-06 23:44:17 +08:00
|
|
|
message: dbLimitErrorMessage,
|
2017-08-01 00:26:45 +08:00
|
|
|
layer: {
|
|
|
|
id: 'layer0',
|
|
|
|
index: 0,
|
|
|
|
type: 'mapnik'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetching by feature id', function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({
|
|
|
|
attributes: {
|
|
|
|
id: 'cartodb_id',
|
2019-10-22 01:07:24 +08:00
|
|
|
columns: ['val']
|
2017-08-01 00:26:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
|
|
|
|
const expectedResponse = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response: expectedResponse }, (err, res) => {
|
2017-08-01 00:26:45 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.layergroupid = res.layergroupid;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with user\'s timeout of 200 ms', function () {
|
|
|
|
beforeEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(200, done);
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-10 23:09:05 +08:00
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, done);
|
2017-08-01 00:26:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('fails due to statement timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
layergroupid: this.layergroupid,
|
|
|
|
featureId: 1,
|
|
|
|
layer: 0,
|
|
|
|
response: {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-08-01 00:26:45 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-01 16:21:39 +08:00
|
|
|
this.testClient.getAttributes(params, (err, res, timeoutError) => {
|
2017-08-01 00:26:45 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
|
2017-08-01 00:26:45 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-07-28 00:50:27 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|