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 1/3] 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 }); From 53a40de2e7ab176900ada4c3d5181edb80b6b981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 12 Apr 2018 18:24:00 +0200 Subject: [PATCH 2/3] Use another table --- test/acceptance/regressions.js | 9 ++++----- test/support/sql/windshaft.test.sql | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/acceptance/regressions.js b/test/acceptance/regressions.js index 88b109a3..a0eca119 100644 --- a/test/acceptance/regressions.js +++ b/test/acceptance/regressions.js @@ -1,5 +1,3 @@ -require('../support/test_helper'); - var assert = require('../support/assert'); var TestClient = require('../support/test-client'); const LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); @@ -40,12 +38,13 @@ describe('regressions', function() { }); describe('map instantiation', function () { + const apikeyToken = 'regular1'; const mapConfig = { version: '1.7.0', layers: [{ type: 'cartodb', options: { - sql: 'select * from test_table', + sql: 'select * from test_table_localhost_regular1', cartocss: TestClient.CARTOCSS.POINTS, cartocss_version: '2.3.0' } @@ -53,7 +52,7 @@ describe('regressions', function() { }; it('should have distint timestamps when the source was updated', function (done) { - const testClient = new TestClient(mapConfig); + const testClient = new TestClient(mapConfig, apikeyToken); testClient.getLayergroup({}, (err, layergroup) => { if (err) { @@ -64,7 +63,7 @@ describe('regressions', function() { const conn = testClient.getDBConnection(); - const sql = `select CDB_TableMetadataTouch('test_table'::regclass)`; + const sql = `select CDB_TableMetadataTouch('test_table_localhost_regular1'::regclass)`; conn.query(sql, (err) => { if (err) { diff --git a/test/support/sql/windshaft.test.sql b/test/support/sql/windshaft.test.sql index d69e5691..51a6de8a 100644 --- a/test/support/sql/windshaft.test.sql +++ b/test/support/sql/windshaft.test.sql @@ -465,6 +465,8 @@ CREATE INDEX test_table_localhost_regular1_the_geom_webmercator_idx ON test_tabl GRANT ALL ON TABLE test_table_localhost_regular1 TO :TESTUSER; GRANT ALL ON TABLE test_table_localhost_regular1 TO test_windshaft_regular1; +INSERT INTO CDB_TableMetadata (tabname, updated_at) VALUES ('test_table_localhost_regular1'::regclass, '2009-02-13T23:31:30.123Z'); + -- analysis tables ----------------------------------------------- ALTER TABLE cdb_analysis_catalog OWNER TO :TESTUSER; From 1df7df21d5d1913fc7961b0e537b9ca42941ba71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 12 Apr 2018 18:31:22 +0200 Subject: [PATCH 3/3] Revert removed line --- test/acceptance/regressions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/acceptance/regressions.js b/test/acceptance/regressions.js index a0eca119..b8692d24 100644 --- a/test/acceptance/regressions.js +++ b/test/acceptance/regressions.js @@ -1,3 +1,4 @@ +require('../support/test_helper'); var assert = require('../support/assert'); var TestClient = require('../support/test-client'); const LayergroupToken = require('../../lib/cartodb/models/layergroup-token');