Windshaft-cartodb/test/acceptance/ported/limits-test.js

93 lines
3.4 KiB
JavaScript
Raw Normal View History

'use strict';
require('../../support/test-helper');
2015-07-08 05:46:58 +08:00
var fs = require('fs');
var assert = require('../../support/assert');
var testClient = require('./support/test-client');
var serverOptions = require('./support/ported-server-options');
2015-07-08 05:46:58 +08:00
2019-10-22 01:07:24 +08:00
describe.skip('render limits', function () {
2015-07-08 05:46:58 +08:00
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25;
var limitsConfig;
var onTileErrorStrategy;
2019-10-22 01:07:24 +08:00
before(function () {
2015-07-08 05:46:58 +08:00
limitsConfig = serverOptions.renderer.mapnik.limits;
serverOptions.renderer.mapnik.limits = {
render: 50,
cacheOnTimeout: false
};
onTileErrorStrategy = serverOptions.renderer.onTileErrorStrategy;
2019-10-22 01:07:24 +08:00
serverOptions.renderer.onTileErrorStrategy = function (err, tile, headers, stats, format, callback) {
2015-07-08 05:46:58 +08:00
callback(err, tile, headers, stats);
};
});
2019-10-22 01:07:24 +08:00
after(function () {
2015-07-08 05:46:58 +08:00
serverOptions.renderer.mapnik.limits = limitsConfig;
serverOptions.renderer.onTileErrorStrategy = onTileErrorStrategy;
});
var slowQuery = 'select pg_sleep(1), * from test_table limit 2';
var slowQueryMapConfig = testClient.singleLayerMapConfig(slowQuery);
2019-10-22 01:07:24 +08:00
it('slow query/render returns with 400 status', function (done) {
2015-07-08 05:46:58 +08:00
var options = {
statusCode: 400,
serverOptions: serverOptions
};
2019-10-22 01:07:24 +08:00
testClient.createLayergroup(slowQueryMapConfig, options, function (err, res) {
assert.deepStrictEqual(JSON.parse(res.body), { errors: ['Render timed out'] });
2015-07-08 05:46:58 +08:00
done();
});
});
2019-10-22 01:07:24 +08:00
it('uses onTileErrorStrategy to handle error and modify response', function (done) {
serverOptions.renderer.onTileErrorStrategy = function (err, tile, headers, stats, format, callback) {
2015-07-08 05:46:58 +08:00
var fixture = __dirname + '/../../fixtures/limits/fallback.png';
2019-10-22 01:07:24 +08:00
fs.readFile(fixture, { encoding: 'binary' }, function (err, img) {
callback(null, img, { 'Content-Type': 'image/png' }, {});
2015-07-08 05:46:58 +08:00
});
};
var options = {
statusCode: 200,
contentType: 'image/png',
serverOptions: serverOptions
};
2019-10-22 01:07:24 +08:00
testClient.createLayergroup(slowQueryMapConfig, options, function (err, res) {
2015-07-08 05:46:58 +08:00
var parsed = JSON.parse(res.body);
assert.ok(parsed.layergroupid);
done();
});
});
2019-10-22 01:07:24 +08:00
it('returns a fallback tile that was modified via onTileErrorStrategy', function (done) {
2015-07-08 05:46:58 +08:00
var fixtureImage = './test/fixtures/limits/fallback.png';
2019-10-22 01:07:24 +08:00
serverOptions.renderer.onTileErrorStrategy = function (err, tile, headers, stats, format, callback) {
fs.readFile(fixtureImage, { encoding: null }, function (err, img) {
callback(null, img, { 'Content-Type': 'image/png' }, {});
2015-07-08 05:46:58 +08:00
});
};
var options = {
statusCode: 200,
contentType: 'image/png',
serverOptions: serverOptions
};
2019-10-22 01:07:24 +08:00
testClient.withLayergroup(slowQueryMapConfig, options, function (err, requestTile, finish) {
2015-07-08 05:46:58 +08:00
var tileUrl = '/0/0/0.png';
2019-10-22 01:07:24 +08:00
requestTile(tileUrl, options, function (err, res) {
2016-02-22 23:36:06 +08:00
assert.imageBufferIsSimilarToFile(res.body, fixtureImage, IMAGE_EQUALS_TOLERANCE_PER_MIL,
2019-10-22 01:07:24 +08:00
function (err) {
finish(function (finishErr) {
2016-02-22 23:36:06 +08:00
done(err || finishErr);
});
}
);
2015-07-08 05:46:58 +08:00
});
});
});
});