Implement test to validate response limits work as expected

This commit is contained in:
Daniel García Aubert 2017-07-25 19:16:37 +02:00
parent 526e850f26
commit 788b2f0683

View File

@ -5,87 +5,319 @@ const TestClient = require('../support/test-client');
const timeoutErrorTilePath = `${process.cwd()}/assets/render-timeout-fallback.png`; const timeoutErrorTilePath = `${process.cwd()}/assets/render-timeout-fallback.png`;
var pointSleepSql = ` const pointSleepSql = `
SELECT SELECT
pg_sleep(0.5), pg_sleep(0.5),
'SRID=3857;POINT(0 0)'::geometry the_geom_webmercator, 'SRID=3857;POINT(0 0)'::geometry the_geom_webmercator,
1 cartodb_id 1 cartodb_id
`; `;
function createMapConfig (sql = pointSleepSql, cartocss = TestClient.CARTOCSS.POINTS) { const validationPointSleepSql = `
return { SELECT
version: '1.6.0', pg_sleep(0.5),
layers: [{ 'SRID=3857;POINT(-180 90)'::geometry the_geom_webmercator,
type: 'cartodb', 1 cartodb_id
options: { `;
sql,
cartocss, const createMapConfig = ({
cartocss_version: '2.3.0', version = '1.6.0',
interactivity: 'cartodb_id' type = 'cartodb',
sql = pointSleepSql,
cartocss = TestClient.CARTOCSS.POINTS,
cartocss_version = '2.3.0',
interactivity = 'cartodb_id',
countBy = 'cartodb_id'
} = {}) => ({
version,
layers: [{
type,
options: {
source: {
id: "a0"
},
cartocss,
cartocss_version,
interactivity
}
}],
analyses: [
{
id: 'a0',
type: 'source',
params: {
query: sql
} }
}] }
}; ],
} dataviews: {
count: {
source: {
id: 'a0'
},
type: 'formula',
options: {
column: countBy,
operation: 'count'
}
}
}
});
describe('user timeout limits', function () { describe('user timeout limit', function () {
describe('with onTileErrorStrategy ENABLED', function () { describe.skip('map instantiation', function () {
let onTileErrorStrategy; beforeEach(function (done) {
const mapconfig = createMapConfig({ sql: validationPointSleepSql });
before(function () { this.testClient = new TestClient(mapconfig, 1234);
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy; this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
global.environment.enabledFeatures.onTileErrorStrategy = true;
}); });
after(function () { 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 if test tile is fast but tile request fails if they are slow', function (done) { it('layergroup creation fails due to statement timeout', function (done) {
var testClient = new TestClient(createMapConfig(), 1234); const expectedResponse = {
status: 400,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
testClient.setUserRenderTimeoutLimit('localhost', 50, function (err) { this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => {
assert.ifError(err); assert.ifError(err);
testClient.getTile(0, 0, 0, {}, function (err, res, tile) { assert.deepEqual(timeoutError, {
assert.ifError(err); errors: ['Render timed out'],
errors_with_context: [{ type: 'unknown', message: 'Render timed out' }]
assert.imageIsSimilarToFile(tile, timeoutErrorTilePath, 0.05, function (err) {
assert.ifError(err);
testClient.drain(done);
});
}); });
done();
}); });
}); });
}); });
describe('with onTileErrorStrategy DISABLED', function() { describe('user torque timeout limits', function () {
var onTileErrorStrategy; beforeEach(function (done) {
const mapconfig = createMapConfig({
beforeEach(function() { type: 'torque',
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy; cartocss: TestClient.CARTOCSS.TORQUE
global.environment.enabledFeatures.onTileErrorStrategy = false; });
this.testClient = new TestClient(mapconfig, 1234);
this.testClient.setUserDatabaseTimeoutLimit('localhost', 50, done);
}); });
afterEach(function() { afterEach(function (done) {
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy; this.testClient.setUserDatabaseTimeoutLimit('localhost', 0, (err) => {
if (err) {
return done(err);
}
this.testClient.drain(done);
});
}); });
it('layergroup creation works even if test tile is slow', function (done) { it('layergroup creation fails due to statement timeout', function (done) {
var testClient = new TestClient(createMapConfig(), 1234); const expectedResponse = {
testClient.setUserRenderTimeoutLimit('localhost', 50, function (err) { status: 400,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => {
assert.ifError(err); assert.ifError(err);
assert.deepEqual(timeoutError, {
errors: ["TorqueRenderer: canceling statement due to statement timeout"],
errors_with_context: [{
"type": "layer",
"message": "TorqueRenderer: canceling statement due to statement timeout",
"layer": { "id": "torque-layer0", "index": 0, "type": "torque" }
}]
});
done();
});
});
});
describe('dataview', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig();
this.testClient = new TestClient(mapconfig, 1234);
this.testClient.setUserDatabaseTimeoutLimit('localhost', 50, done);
});
afterEach(function (done) {
this.testClient.setUserDatabaseTimeoutLimit('localhost', 0, (err) => {
if (err) {
return done(err);
}
this.testClient.drain(done);
});
});
it('layergroup creation works but dataview request fails due to statement timeout', function (done) {
const params = {
response: {
status: 400,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}
};
this.testClient.getDataview('count', params, (err, dataview) => {
assert.ifError(err);
assert.deepEqual(dataview, {
errors: ['canceling statement due to statement timeout'],
errors_with_context: [{ type: 'unknown', message: 'canceling statement due to statement timeout' }]
});
done();
});
});
});
describe('raster', function () {
describe('with onTileErrorStrategy ENABLED', function () {
let onTileErrorStrategy;
beforeEach(function () {
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy;
global.environment.enabledFeatures.onTileErrorStrategy = true;
});
afterEach(function () {
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
});
beforeEach(function (done) {
const mapconfig = createMapConfig();
this.testClient = new TestClient(mapconfig, 1234);
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
});
afterEach(function (done) {
this.testClient.drain(done);
});
it('layergroup creation works but tile request fails due to render timeout', function (done) {
this.testClient.getTile(0, 0, 0, {}, (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() {
onTileErrorStrategy = global.environment.enabledFeatures.onTileErrorStrategy;
global.environment.enabledFeatures.onTileErrorStrategy = false;
});
afterEach(function() {
global.environment.enabledFeatures.onTileErrorStrategy = onTileErrorStrategy;
});
beforeEach(function (done) {
const mapconfig = createMapConfig();
this.testClient = new TestClient(mapconfig, 1234);
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
});
afterEach(function (done) {
this.testClient.drain(done);
});
it('layergroup creation works even if render tile is slow', function (done) {
var params = { var params = {
status: 400, status: 400,
contentType: 'application/json; charset=utf-8' contentType: 'application/json; charset=utf-8'
}; };
testClient.getTile(0, 0, 0, params, function (err, res, tile) { this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
assert.ifError(err); assert.ifError(err);
assert.equal(tile.errors[0], 'Render timed out'); assert.equal(tile.errors[0], 'Render timed out');
testClient.drain(done); done();
}); });
}); });
}); });
}); });
describe('user vector timeout limits', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig();
this.testClient = new TestClient(mapconfig, 1234);
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
});
afterEach(function (done) {
this.testClient.drain(done);
});
it('layergroup creation works but vector tile request fails due to render timeout', function (done) {
const params = {
format: 'mvt',
status: 400
};
this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
assert.ifError(err);
assert.deepEqual(tile, {
errors: ['Render timed out'],
errors_with_context: [{ type: 'unknown', message: 'Render timed out' }]
});
done();
});
});
});
describe('user interativity timeout limits', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig();
this.testClient = new TestClient(mapconfig, 1234);
this.testClient.setUserRenderTimeoutLimit('localhost', 50, done);
});
afterEach(function (done) {
this.testClient.drain(done);
});
it('layergroup creation works but "grid.json" tile request fails due to render timeout', function (done) {
const params = {
layers: 'mapnik',
format: 'grid.json',
status: 400
};
this.testClient.getTile(0, 0, 0, params, (err, res, tile) => {
assert.ifError(err);
assert.deepEqual(tile, {
errors: ['Render timed out'],
errors_with_context: [{ type: 'unknown', message: 'Render timed out' }]
});
done();
});
});
});
}); });