From 6437e2ec67f4d773b7425e7d72ecb6a600be6c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 12 Apr 2018 16:32:44 +0200 Subject: [PATCH] Add test to check regression when cache buster during instantiation is not updated --- test/acceptance/regressions.js | 53 ++++++++++++++++++++++++++++++++++ test/support/test-client.js | 13 +++++++++ 2 files changed, 66 insertions(+) diff --git a/test/acceptance/regressions.js b/test/acceptance/regressions.js index 421df02f..88b109a3 100644 --- a/test/acceptance/regressions.js +++ b/test/acceptance/regressions.js @@ -2,6 +2,7 @@ require('../support/test_helper'); var assert = require('../support/assert'); var TestClient = require('../support/test-client'); +const LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); describe('regressions', function() { @@ -37,4 +38,56 @@ describe('regressions', function() { testClient.drain(done); }); }); + + describe('map instantiation', function () { + const mapConfig = { + version: '1.7.0', + layers: [{ + type: 'cartodb', + options: { + sql: 'select * from test_table', + cartocss: TestClient.CARTOCSS.POINTS, + cartocss_version: '2.3.0' + } + }] + }; + + it('should have distint timestamps when the source was updated', function (done) { + const testClient = new TestClient(mapConfig); + + testClient.getLayergroup({}, (err, layergroup) => { + if (err) { + return done(err); + } + + const { cacheBuster: cacheBusterA } = LayergroupToken.parse(layergroup.layergroupid); + + const conn = testClient.getDBConnection(); + + const sql = `select CDB_TableMetadataTouch('test_table'::regclass)`; + + conn.query(sql, (err) => { + if (err) { + return done(err); + } + + testClient.getLayergroup({}, (err, layergroup) => { + if (err) { + return done(err); + } + + const { cacheBuster: cacheBusterB } = LayergroupToken.parse(layergroup.layergroupid); + + const timestampA = parseInt(cacheBusterA, 10); + const timestampB = parseInt(cacheBusterB, 10); + + assert.notEqual(timestampA, timestampB); + assert.ok(timestampA < timestampB, `timestampA: ${timestampA} > timestampB:${timestampB}`); + + testClient.drain(done); + }); + }); + }); + }); + }); }); diff --git a/test/support/test-client.js b/test/support/test-client.js index 7b068901..4c71ed6d 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -1183,6 +1183,19 @@ TestClient.prototype.setUserRenderTimeoutLimit = function (user, userTimeoutLimi helper.configureMetadata('hmset', params, callback); }; +TestClient.prototype.getDBConnection = function () { + const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db'; + + const psql = new PSQL({ + user: 'postgres', + dbname: dbname, + host: global.environment.postgres.host, + port: global.environment.postgres.port + }); + + return psql; +}; + TestClient.prototype.setUserDatabaseTimeoutLimit = function (timeoutLimit, callback) { const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db'; const dbuser = _.template(global.environment.postgres_auth_user, { user_id: 1 });