Fix ported test related to cache_buster from layergroup token

This commit is contained in:
Daniel García Aubert 2018-03-19 13:51:03 +01:00
parent b038763b7b
commit 5cde325d9a
3 changed files with 36 additions and 19 deletions

View File

@ -7,7 +7,7 @@ var cartodbServer = require('../../../lib/cartodb/server');
var ServerOptions = require('./support/ported_server_options'); var ServerOptions = require('./support/ported_server_options');
var testClient = require('./support/test_client'); var testClient = require('./support/test_client');
describe('server_gettile', function() { describe.only('server_gettile', function() {
var server = cartodbServer(ServerOptions); var server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
@ -42,8 +42,7 @@ describe('server_gettile', function() {
); );
}); });
// REVIEW it("response of get tile can be served by renderer cache", function(done) {
it.skip("response of get tile can be served by renderer cache", function(done) {
var tileUrl = '/13/4011/3088.png'; var tileUrl = '/13/4011/3088.png';
var lastXwc; var lastXwc;
var mapConfig = testClient.defaultTableMapConfig('test_table'); var mapConfig = testClient.defaultTableMapConfig('test_table');
@ -60,7 +59,7 @@ describe('server_gettile', function() {
assert.ok(xwc > 0); assert.ok(xwc > 0);
assert.ok(xwc >= lastXwc); assert.ok(xwc >= lastXwc);
requestTile(tileUrl + '?cache_buster=wadus', function (err, res) { requestTile(tileUrl, { cache_buster: 'wadus' }, function (err, res) {
var xwc = res.headers['x-windshaft-cache']; var xwc = res.headers['x-windshaft-cache'];
assert.ok(!xwc); assert.ok(!xwc);
@ -85,8 +84,7 @@ describe('server_gettile', function() {
); );
}); });
// REVIEW it("getting two tiles with same configuration uses renderer cache", function(done) {
it.skip("getting two tiles with same configuration uses renderer cache", function(done) {
var imageFixture = './test/fixtures/test_table_13_4011_3088_styled.png'; var imageFixture = './test/fixtures/test_table_13_4011_3088_styled.png';
var tileUrl = '/13/4011/3088.png'; var tileUrl = '/13/4011/3088.png';
@ -101,9 +99,15 @@ describe('server_gettile', function() {
} }
testClient.withLayergroup(mapConfig, validateLayergroup, function(err, requestTile, finish) { testClient.withLayergroup(mapConfig, validateLayergroup, function(err, requestTile, finish) {
requestTile(tileUrl, function(err, res) { requestTile(tileUrl, function(err, res) {
assert.ok(res.headers.hasOwnProperty('x-windshaft-cache'), "Did not hit renderer cache on second time"); var xwc = res.headers['x-windshaft-cache'];
assert.ok(!xwc);
requestTile(tileUrl, function (err, res) {
assert.ok(
res.headers.hasOwnProperty('x-windshaft-cache'),
"Did not hit renderer cache on second time"
);
assert.ok(res.headers['x-windshaft-cache'] >= 0); assert.ok(res.headers['x-windshaft-cache'] >= 0);
assert.imageBufferIsSimilarToFile(res.body, imageFixture, IMAGE_EQUALS_TOLERANCE_PER_MIL, assert.imageBufferIsSimilarToFile(res.body, imageFixture, IMAGE_EQUALS_TOLERANCE_PER_MIL,
@ -116,6 +120,7 @@ describe('server_gettile', function() {
}); });
}); });
}); });
});
var test_style_black_200 = "#test_table{marker-fill:black;marker-line-color:black;marker-width:5}"; var test_style_black_200 = "#test_table{marker-fill:black;marker-line-color:black;marker-width:5}";
var test_style_black_210 = "#test_table{marker-fill:black;marker-line-color:black;marker-width:10}"; var test_style_black_210 = "#test_table{marker-fill:black;marker-line-color:black;marker-width:10}";

View File

@ -1,7 +1,6 @@
var _ = require('underscore'); var _ = require('underscore');
var serverOptions = require('../../../../lib/cartodb/server_options'); var serverOptions = require('../../../../lib/cartodb/server_options');
var mapnik = require('windshaft').mapnik; var mapnik = require('windshaft').mapnik;
var LayergroupToken = require('../../../../lib/cartodb/models/layergroup-token');
var OverviewsQueryRewriter = require('../../../../lib/cartodb/utils/overviews_query_rewriter'); var OverviewsQueryRewriter = require('../../../../lib/cartodb/utils/overviews_query_rewriter');
var overviewsQueryRewriter = new OverviewsQueryRewriter({ var overviewsQueryRewriter = new OverviewsQueryRewriter({
zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)' zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)'

View File

@ -454,8 +454,21 @@ function withLayergroup(layergroupConfig, options, callback) {
}; };
} }
var baseUrlTpl = '/database/windshaft_test/layergroup/<%= layergroupid %>'; const signerTpl = function ({ signer }) {
var finalUrl = _.template(baseUrlTpl, { layergroupid: layergroupid }) + layergroupUrl; return `${signer ? `:${signer}@` : ''}`;
}
const cacheTpl = function ({ cache_buster, cacheBuster }) {
return `${cache_buster ? `:${cache_buster}` : `:${cacheBuster}`}`;
}
const urlTpl = function ({layergroupid, cache_buster = null, tile }) {
const { signer, token , cacheBuster } = LayergroupToken.parse(layergroupid);
const base = '/database/windshaft_test/layergroup/'
return `${base}${signerTpl({signer})}${token}${cacheTpl({cache_buster, cacheBuster})}${tile}`;
}
const finalUrl = urlTpl({ layergroupid, cache_buster: options.cache_buster, tile: layergroupUrl });
var request = { var request = {
url: finalUrl, url: finalUrl,