Add test to check regression when cache buster during instantiation is not updated

This commit is contained in:
Daniel García Aubert 2018-04-12 16:32:44 +02:00
parent 2d2629c088
commit 6437e2ec67
2 changed files with 66 additions and 0 deletions

View File

@ -2,6 +2,7 @@ require('../support/test_helper');
var assert = require('../support/assert'); var assert = require('../support/assert');
var TestClient = require('../support/test-client'); var TestClient = require('../support/test-client');
const LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
describe('regressions', function() { describe('regressions', function() {
@ -37,4 +38,56 @@ describe('regressions', function() {
testClient.drain(done); 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);
});
});
});
});
});
}); });

View File

@ -1183,6 +1183,19 @@ TestClient.prototype.setUserRenderTimeoutLimit = function (user, userTimeoutLimi
helper.configureMetadata('hmset', params, callback); 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) { TestClient.prototype.setUserDatabaseTimeoutLimit = function (timeoutLimit, callback) {
const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db'; const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db';
const dbuser = _.template(global.environment.postgres_auth_user, { user_id: 1 }); const dbuser = _.template(global.environment.postgres_auth_user, { user_id: 1 });