Implemented database timeout test while requesting tiles

This commit is contained in:
Daniel García Aubert 2017-08-01 10:21:39 +02:00
parent dd5209b9a7
commit 0c4e67d6a8

View File

@ -11,12 +11,21 @@ const pointSleepSql = `
2 val 2 val
`; `;
const validationPointSleepSql = `
SELECT
pg_sleep(0.3),
ST_Transform('SRID=4326;POINT(-180 85.05112877)'::geometry, 3857) the_geom_webmercator,
1 cartodb_id,
2 val
`;
const createMapConfig = ({ const createMapConfig = ({
version = '1.6.0', version = '1.6.0',
type = 'cartodb', type = 'cartodb',
sql = pointSleepSql, sql = pointSleepSql,
cartocss = TestClient.CARTOCSS.POINTS, cartocss = TestClient.CARTOCSS.POINTS,
cartocss_version = '2.3.0', cartocss_version = '2.3.0',
interactivity = 'cartodb_id',
countBy = 'cartodb_id', countBy = 'cartodb_id',
attributes attributes
} = {}) => ({ } = {}) => ({
@ -29,7 +38,8 @@ const createMapConfig = ({
}, },
cartocss, cartocss,
cartocss_version, cartocss_version,
attributes attributes,
interactivity
} }
}], }],
analyses: [ analyses: [
@ -91,16 +101,320 @@ describe('user database timeout limit', function () {
} }
}; };
this.testClient.getDataview('count', params, (err, dataview) => { this.testClient.getDataview('count', params, (err, timeoutError) => {
assert.ifError(err); assert.ifError(err);
assert.deepEqual(dataview, DATASOURCE_TIMEOUT_ERROR); assert.deepEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
done(); done();
}); });
}); });
}); });
describe('raster', function () {
describe('while validating in layergroup creation', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig({ sql: validationPointSleepSql });
this.testClient = new TestClient(mapconfig, 1234);
TestClient.setUserDatabaseTimeoutLimit('localhost', 200, done);
});
afterEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 0, (err) => {
if (err) {
return done(err);
}
this.testClient.drain(done);
});
});
it('fails due to statement timeout', function (done) {
const expectedResponse = {
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform limits. Please contact us to know more details' ],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform limits. Please contact us to know more details',
layer: { id: 'layer0', index: 0, type: 'mapnik' }
}]
});
done();
});
});
});
describe('fetching raster tiles', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig();
this.testClient = new TestClient(mapconfig, 1234);
const expectedResponse = {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.testClient.getLayergroup(expectedResponse, (err, res) => {
if (err) {
return done(err);
}
this.layergroupid = res.layergroupid;
done();
});
});
afterEach(function (done) {
this.testClient.drain(done);
});
describe('with user\'s timeout of 200 ms', function () {
beforeEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 200, done);
});
afterEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 0, done);
});
it('"png" fails due to statement timeout', function (done) {
const params = {
layergroupid: this.layergroupid,
format: 'png',
layers: [ 0 ],
response: {
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}
};
this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
assert.ifError(err);
assert.deepEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
done();
});
});
});
});
});
describe('vector', function () {
describe('while validating in layergroup creation', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig({ sql: validationPointSleepSql });
this.testClient = new TestClient(mapconfig, 1234);
TestClient.setUserDatabaseTimeoutLimit('localhost', 200, done);
});
afterEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 0, (err) => {
if (err) {
return done(err);
}
this.testClient.drain(done);
});
});
it('fails due to statement timeout', function (done) {
const expectedResponse = {
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform limits. Please contact us to know more details' ],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform limits. Please contact us to know more details',
layer: { id: 'layer0', index: 0, type: 'mapnik' }
}]
});
done();
});
});
});
describe('fetching vector tiles', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig();
this.testClient = new TestClient(mapconfig, 1234);
const expectedResponse = {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.testClient.getLayergroup(expectedResponse, (err, res) => {
if (err) {
return done(err);
}
this.layergroupid = res.layergroupid;
done();
});
});
afterEach(function (done) {
this.testClient.drain(done);
});
describe('with user\'s timeout of 200 ms', function () {
beforeEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 200, done);
});
afterEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 0, done);
});
it('"mvt" fails due to statement timeout', function (done) {
const params = {
layergroupid: this.layergroupid,
format: 'mvt',
layers: [ 0 ],
response: {
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}
};
this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
assert.ifError(err);
assert.deepEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
done();
});
});
});
});
});
describe('interactivity', function () {
describe('while validating in layergroup creation', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig({ sql: validationPointSleepSql, interactivity: 'val' });
this.testClient = new TestClient(mapconfig, 1234);
TestClient.setUserDatabaseTimeoutLimit('localhost', 200, done);
});
afterEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 0, (err) => {
if (err) {
return done(err);
}
this.testClient.drain(done);
});
});
it('fails due to statement timeout', function (done) {
const expectedResponse = {
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.testClient.getLayergroup(expectedResponse, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform limits. Please contact us to know more details' ],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform limits. Please contact us to know more details',
layer: { id: 'layer0', index: 0, type: 'mapnik' }
}]
});
done();
});
});
});
describe('fetching interactivity tiles', function () {
beforeEach(function (done) {
const mapconfig = createMapConfig({ interactivity: 'val' });
this.testClient = new TestClient(mapconfig, 1234);
const expectedResponse = {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.testClient.getLayergroup(expectedResponse, (err, res) => {
if (err) {
return done(err);
}
this.layergroupid = res.layergroupid;
done();
});
});
afterEach(function (done) {
this.testClient.drain(done);
});
describe('with user\'s timeout of 200 ms', function () {
beforeEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 200, done);
});
afterEach(function (done) {
TestClient.setUserDatabaseTimeoutLimit('localhost', 0, done);
});
it.skip('"grid.json" fails due to statement timeout', function (done) {
const params = {
layergroupid: this.layergroupid,
format: 'grid.json',
layers: [ 0 ],
response: {
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}
};
this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
assert.ifError(err);
assert.deepEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
done();
});
});
});
});
});
describe('torque', function () { describe('torque', function () {
describe('while validating in layergroup creation', function () { describe('while validating in layergroup creation', function () {
beforeEach(function (done) { beforeEach(function (done) {
@ -196,10 +510,10 @@ describe('user database timeout limit', function () {
} }
}; };
this.testClient.getTile(0, 0, 0, params, (err, res, attributes) => { this.testClient.getTile(0, 0, 0, params, (err, res, timeoutError) => {
assert.ifError(err); assert.ifError(err);
assert.deepEqual(attributes, DATASOURCE_TIMEOUT_ERROR); assert.deepEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
done(); done();
}); });
@ -335,10 +649,10 @@ describe('user database timeout limit', function () {
} }
}; };
this.testClient.getAttributes(params, (err, res, attributes) => { this.testClient.getAttributes(params, (err, res, timeoutError) => {
assert.ifError(err); assert.ifError(err);
assert.deepEqual(attributes, DATASOURCE_TIMEOUT_ERROR); assert.deepEqual(timeoutError, DATASOURCE_TIMEOUT_ERROR);
done(); done();
}); });