2017-07-06 01:08:19 +08:00
|
|
|
require('../support/test_helper');
|
|
|
|
|
2017-07-19 02:50:31 +08:00
|
|
|
const assert = require('../support/assert');
|
|
|
|
const TestClient = require('../support/test-client');
|
2017-10-09 20:46:01 +08:00
|
|
|
var serverOptions = require('../../lib/cartodb/server_options');
|
2017-07-19 02:50:31 +08:00
|
|
|
|
|
|
|
const timeoutErrorTilePath = `${process.cwd()}/assets/render-timeout-fallback.png`;
|
|
|
|
|
2017-07-26 01:16:37 +08:00
|
|
|
const pointSleepSql = `
|
2017-07-19 02:50:31 +08:00
|
|
|
SELECT
|
2017-07-28 22:04:11 +08:00
|
|
|
pg_sleep(0.5),
|
2017-07-19 02:50:31 +08:00
|
|
|
'SRID=3857;POINT(0 0)'::geometry the_geom_webmercator,
|
2017-07-26 19:25:37 +08:00
|
|
|
1 cartodb_id,
|
2017-07-27 22:30:57 +08:00
|
|
|
2 val
|
2017-07-19 02:50:31 +08:00
|
|
|
`;
|
2017-07-06 01:08:19 +08:00
|
|
|
|
2017-07-26 19:25:37 +08:00
|
|
|
// during instatiation we validate tile 30/0/0, creating a point in that tile `pg_sleep` will throw a timeout
|
2017-07-26 01:16:37 +08:00
|
|
|
const validationPointSleepSql = `
|
|
|
|
SELECT
|
2017-07-28 19:21:17 +08:00
|
|
|
pg_sleep(0.5),
|
2017-07-26 19:25:37 +08:00
|
|
|
ST_Transform('SRID=4326;POINT(-180 85.05112877)'::geometry, 3857) the_geom_webmercator,
|
|
|
|
1 cartodb_id,
|
2017-07-27 22:30:57 +08:00
|
|
|
2 val
|
2017-07-26 01:16:37 +08:00
|
|
|
`;
|
|
|
|
|
|
|
|
const createMapConfig = ({
|
|
|
|
version = '1.6.0',
|
|
|
|
type = 'cartodb',
|
|
|
|
sql = pointSleepSql,
|
|
|
|
cartocss = TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version = '2.3.0',
|
|
|
|
interactivity = 'cartodb_id',
|
2017-08-01 00:01:19 +08:00
|
|
|
countBy = 'cartodb_id'
|
2017-07-26 01:16:37 +08:00
|
|
|
} = {}) => ({
|
|
|
|
version,
|
|
|
|
layers: [{
|
|
|
|
type,
|
|
|
|
options: {
|
|
|
|
source: {
|
2017-07-26 19:25:37 +08:00
|
|
|
id: 'a0'
|
2017-07-26 01:16:37 +08:00
|
|
|
},
|
|
|
|
cartocss,
|
|
|
|
cartocss_version,
|
2017-08-01 00:01:19 +08:00
|
|
|
interactivity
|
2017-07-26 01:16:37 +08:00
|
|
|
}
|
|
|
|
}],
|
|
|
|
analyses: [
|
|
|
|
{
|
|
|
|
id: 'a0',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: sql
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
dataviews: {
|
|
|
|
count: {
|
|
|
|
source: {
|
|
|
|
id: 'a0'
|
|
|
|
},
|
|
|
|
type: 'formula',
|
2017-07-06 01:08:19 +08:00
|
|
|
options: {
|
2017-07-26 01:16:37 +08:00
|
|
|
column: countBy,
|
|
|
|
operation: 'count'
|
2017-07-06 01:08:19 +08:00
|
|
|
}
|
2017-07-26 01:16:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-28 00:50:27 +08:00
|
|
|
describe('user render timeout limit', function () {
|
|
|
|
describe('map instantiation => validation', function () {
|
2017-07-26 01:16:37 +08:00
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig({ sql: validationPointSleepSql });
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('layergroup creation fails due to statement timeout', function (done) {
|
|
|
|
const expectedResponse = {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-07-26 01:16:37 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.deepEqual(timeoutError, {
|
2017-08-01 21:03:09 +08:00
|
|
|
errors: ["You are over platform\'s limits. Please contact us to know more details"],
|
2017-07-26 19:25:37 +08:00
|
|
|
errors_with_context: [{
|
2017-08-01 01:36:07 +08:00
|
|
|
type: 'limit',
|
|
|
|
subtype: 'render',
|
2017-08-01 21:03:09 +08:00
|
|
|
message: "You are over platform\'s limits. Please contact us to know more details",
|
2017-07-26 19:25:37 +08:00
|
|
|
layer: {
|
|
|
|
id: "layer0",
|
|
|
|
index: 0,
|
|
|
|
type: "mapnik"
|
|
|
|
}
|
|
|
|
}]
|
2017-07-26 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('raster', function () {
|
|
|
|
describe('with onTileErrorStrategy ENABLED', function () {
|
|
|
|
let onTileErrorStrategy;
|
|
|
|
|
2017-07-27 23:08:29 +08:00
|
|
|
beforeEach(function (done) {
|
2017-07-26 01:16:37 +08:00
|
|
|
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy;
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = true;
|
|
|
|
|
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-07-27 23:08:29 +08:00
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
|
|
|
|
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('layergroup creation works but tile request fails due to render timeout', function (done) {
|
|
|
|
this.testClient.getTile(0, 0, 0, {}, (err, res, tile) => {
|
2017-07-19 02:50:31 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
2017-07-26 01:16:37 +08:00
|
|
|
assert.imageIsSimilarToFile(tile, timeoutErrorTilePath, 0.05, (err) => {
|
2017-07-19 02:50:31 +08:00
|
|
|
assert.ifError(err);
|
2017-07-26 01:16:37 +08:00
|
|
|
done();
|
2017-07-19 02:50:31 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-07-06 01:08:19 +08:00
|
|
|
|
2017-07-26 01:16:37 +08:00
|
|
|
describe('with onTileErrorStrategy DISABLED', function() {
|
|
|
|
var onTileErrorStrategy;
|
2017-07-19 02:50:31 +08:00
|
|
|
|
2017-07-27 23:08:29 +08:00
|
|
|
beforeEach(function (done) {
|
2017-07-26 01:16:37 +08:00
|
|
|
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy;
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = false;
|
2017-07-19 02:50:31 +08:00
|
|
|
|
2017-07-26 01:16:37 +08:00
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-07-27 23:08:29 +08:00
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
|
|
|
|
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
2017-08-01 00:07:44 +08:00
|
|
|
it('layergroup creation works and render tile fails', function (done) {
|
2017-07-19 02:50:31 +08:00
|
|
|
var params = {
|
2017-08-01 00:07:44 +08:00
|
|
|
response: {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-08-01 00:07:44 +08:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
2017-07-19 02:50:31 +08:00
|
|
|
};
|
|
|
|
|
2017-08-01 01:36:07 +08:00
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
|
2017-07-19 02:50:31 +08:00
|
|
|
assert.ifError(err);
|
2017-07-06 01:08:19 +08:00
|
|
|
|
2017-08-01 01:36:07 +08:00
|
|
|
assert.deepEqual(timeoutError, {
|
2017-08-01 21:03:09 +08:00
|
|
|
errors: ["You are over platform\'s limits. Please contact us to know more details"],
|
2017-08-01 01:36:07 +08:00
|
|
|
errors_with_context: [{
|
|
|
|
type: 'limit',
|
|
|
|
subtype: 'render',
|
2017-08-01 21:03:09 +08:00
|
|
|
message: "You are over platform\'s limits. Please contact us to know more details"
|
2017-08-01 01:36:07 +08:00
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
2017-07-26 01:16:37 +08:00
|
|
|
done();
|
2017-07-19 02:50:31 +08:00
|
|
|
});
|
2017-07-06 01:08:19 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
|
2017-10-16 17:08:46 +08:00
|
|
|
if (process.env.POSTGIS_VERSION === '2.4') {
|
|
|
|
describe('vector (PostGIS)', vector(true));
|
|
|
|
}
|
|
|
|
|
2017-10-09 20:46:01 +08:00
|
|
|
describe('vector (mapnik)', vector(false));
|
|
|
|
function vector(usePostGIS) {
|
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
|
|
|
return function () {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = usePostGIS;
|
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(50, done);
|
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
|
2017-10-09 20:46:01 +08:00
|
|
|
afterEach(function (done) {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
this.testClient.setUserDatabaseTimeoutLimit(0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
2017-07-27 23:08:29 +08:00
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
|
2017-10-09 20:46:01 +08:00
|
|
|
it('layergroup creation works but vector tile request fails due to render timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
format: 'mvt',
|
|
|
|
response: {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
2017-11-07 18:08:01 +08:00
|
|
|
'Content-Type': 'application/x-protobuf'
|
2017-10-09 20:46:01 +08:00
|
|
|
}
|
2017-08-01 00:07:44 +08:00
|
|
|
}
|
2017-10-09 20:46:01 +08:00
|
|
|
};
|
2017-07-26 01:16:37 +08:00
|
|
|
|
2017-10-09 20:46:01 +08:00
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
|
|
|
|
assert.ifError(err);
|
2017-07-26 01:16:37 +08:00
|
|
|
|
2017-11-07 18:08:01 +08:00
|
|
|
var tileJSON = tile.toJSON();
|
|
|
|
assert.equal(Array.isArray(tileJSON), true);
|
|
|
|
assert.equal(tileJSON.length, 2);
|
|
|
|
assert.equal(tileJSON[0].name, 'errorTileSquareLayer');
|
|
|
|
assert.equal(tileJSON[1].name, 'errorTileStripesLayer');
|
|
|
|
|
2017-10-09 20:46:01 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
});
|
2017-10-09 20:46:01 +08:00
|
|
|
};
|
|
|
|
}
|
2017-07-26 01:16:37 +08:00
|
|
|
|
2017-07-27 22:29:36 +08:00
|
|
|
describe('interativity', function () {
|
2017-07-26 01:16:37 +08:00
|
|
|
beforeEach(function (done) {
|
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-07-27 23:08:29 +08:00
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('layergroup creation works but "grid.json" tile request fails due to render timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
layers: 'mapnik',
|
|
|
|
format: 'grid.json',
|
2017-08-01 00:07:44 +08:00
|
|
|
response: {
|
2017-08-01 01:08:29 +08:00
|
|
|
status: 429,
|
2017-08-01 00:07:44 +08:00
|
|
|
headers: {
|
2017-08-01 16:29:29 +08:00
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
2017-08-01 00:07:44 +08:00
|
|
|
}
|
|
|
|
}
|
2017-07-26 01:16:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.deepEqual(tile, {
|
2017-08-01 21:03:09 +08:00
|
|
|
errors: ['You are over platform\'s limits. Please contact us to know more details'],
|
2017-08-01 01:36:07 +08:00
|
|
|
errors_with_context: [{
|
|
|
|
type: 'limit',
|
|
|
|
subtype: 'render',
|
2017-08-01 21:03:09 +08:00
|
|
|
message: 'You are over platform\'s limits. Please contact us to know more details'
|
2017-08-01 01:36:07 +08:00
|
|
|
}]
|
2017-07-26 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-08-01 17:47:50 +08:00
|
|
|
|
|
|
|
describe('static images', function () {
|
|
|
|
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);
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
2017-08-01 18:54:41 +08:00
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
|
|
|
|
|
2017-08-01 17:47:50 +08:00
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('layergroup creation works but static image fails due to render timeout', function (done) {
|
|
|
|
const params = {
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with onTileErrorStrategy DISABLED', function() {
|
|
|
|
var onTileErrorStrategy;
|
|
|
|
|
|
|
|
beforeEach(function (done) {
|
|
|
|
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy;
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = false;
|
|
|
|
|
|
|
|
const mapconfig = createMapConfig();
|
|
|
|
this.testClient = new TestClient(mapconfig, 1234);
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
|
|
|
|
|
|
|
|
this.testClient.setUserRenderTimeoutLimit('localhost', 0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('layergroup creation works and render tile fails', function (done) {
|
|
|
|
const params = {
|
|
|
|
zoom: 0,
|
|
|
|
lat: 0,
|
|
|
|
lng: 0,
|
|
|
|
width: 256,
|
|
|
|
height: 256,
|
|
|
|
format: 'png',
|
|
|
|
response: {
|
|
|
|
status: 429,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getStaticCenter(params, function (err, res, timeoutError) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.deepEqual(timeoutError, {
|
2017-08-01 21:03:09 +08:00
|
|
|
errors: ["You are over platform\'s limits. Please contact us to know more details"],
|
2017-08-01 17:47:50 +08:00
|
|
|
errors_with_context: [{
|
|
|
|
type: 'limit',
|
|
|
|
subtype: 'render',
|
2017-08-01 21:03:09 +08:00
|
|
|
message: "You are over platform\'s limits. Please contact us to know more details"
|
2017-08-01 17:47:50 +08:00
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-07-06 01:08:19 +08:00
|
|
|
});
|
2017-07-26 01:16:37 +08:00
|
|
|
|