Merge pull request #944 from CartoDB/improve-test-suite

Improve test suite
This commit is contained in:
Daniel G. Aubert 2018-04-18 16:58:52 +02:00 committed by GitHub
commit 20b46a33cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 247 additions and 102 deletions

View File

@ -4,12 +4,17 @@ var helper = require('../../support/test_helper');
var CartodbWindshaft = require('../../../lib/cartodb/server'); var CartodbWindshaft = require('../../../lib/cartodb/server');
var serverOptions = require('../../../lib/cartodb/server_options'); var serverOptions = require('../../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var TestClient = require('../../support/test-client'); var TestClient = require('../../support/test-client');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('named-maps analysis', function() { describe('named-maps analysis', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var IMAGE_TOLERANCE_PER_MIL = 20; var IMAGE_TOLERANCE_PER_MIL = 20;

View File

@ -5,7 +5,6 @@ const assert = require('../../support/assert');
const testHelper = require('../../support/test_helper'); const testHelper = require('../../support/test_helper');
const CartodbWindshaft = require('../../../lib/cartodb/server'); const CartodbWindshaft = require('../../../lib/cartodb/server');
const serverOptions = require('../../../lib/cartodb/server_options'); const serverOptions = require('../../../lib/cartodb/server_options');
const server = new CartodbWindshaft(serverOptions);
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
function singleLayergroupConfig(sql, cartocss) { function singleLayergroupConfig(sql, cartocss) {
@ -46,6 +45,12 @@ var pointSqlPublic = "select * from test_table";
var keysToDelete; var keysToDelete;
describe('authorization fallback', function () { describe('authorization fallback', function () {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
beforeEach(function () { beforeEach(function () {
keysToDelete = {}; keysToDelete = {};
}); });

View File

@ -5,12 +5,17 @@ var qs = require('querystring');
var CartodbWindshaft = require('../../../lib/cartodb/server'); var CartodbWindshaft = require('../../../lib/cartodb/server');
var serverOptions = require('../../../lib/cartodb/server_options'); var serverOptions = require('../../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('get requests with cache headers', function() { describe('get requests with cache headers', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
var keysToDelete; var keysToDelete;
beforeEach(function() { beforeEach(function() {

View File

@ -7,7 +7,7 @@ var _ = require('underscore');
var NamedMapsCacheEntry = require(__dirname + '/../../../lib/cartodb/cache/model/named_maps_entry'); var NamedMapsCacheEntry = require(__dirname + '/../../../lib/cartodb/cache/model/named_maps_entry');
var CartodbWindshaft = require(__dirname + '/../../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../../lib/cartodb/server');
var nock = require('nock');
describe('templates surrogate keys', function() { describe('templates surrogate keys', function() {
@ -30,7 +30,13 @@ describe('templates surrogate keys', function() {
serviceId: FAKE_FASTLY_SERVICE_ID serviceId: FAKE_FASTLY_SERVICE_ID
}; };
var server = new CartodbWindshaft(serverOptions); var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
nock.disableNetConnect();
nock.enableNetConnect(/(127.0.0.1|cartocdn.com)/);
});
var templateOwner = 'localhost'; var templateOwner = 'localhost';
var templateName = 'acceptance'; var templateName = 'acceptance';
@ -70,9 +76,6 @@ describe('templates surrogate keys', function() {
var invalidationMatchHeader = '\\b' + cacheEntryKey + '\\b'; var invalidationMatchHeader = '\\b' + cacheEntryKey + '\\b';
var fastlyPurgePath = '/service/' + FAKE_FASTLY_SERVICE_ID + '/purge/' + cacheEntryKey; var fastlyPurgePath = '/service/' + FAKE_FASTLY_SERVICE_ID + '/purge/' + cacheEntryKey;
var nock = require('nock');
nock.enableNetConnect(/(127.0.0.1:5555|cartocdn.com)/);
after(function(done) { after(function(done) {
serverOptions.varnish_purge_enabled = false; serverOptions.varnish_purge_enabled = false;
serverOptions.varnish_host = varnishHost; serverOptions.varnish_host = varnishHost;
@ -80,7 +83,9 @@ describe('templates surrogate keys', function() {
serverOptions.fastly = fastlyConfig; serverOptions.fastly = fastlyConfig;
nock.restore(); nock.cleanAll();
nock.enableNetConnect();
done(); done();
}); });

View File

@ -4,9 +4,13 @@ var LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
var testHelper = require(__dirname + '/../support/test_helper'); var testHelper = require(__dirname + '/../support/test_helper');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
describe('dynamic styling for named maps', function() { describe('dynamic styling for named maps', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var keysToDelete; var keysToDelete;

View File

@ -1,9 +1,15 @@
var assert = require('../support/assert'); var assert = require('../support/assert');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
describe('error with context', function () { describe('error with context', function () {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var layerOK = { var layerOK = {
options: { options: {
sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator ' + sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator ' +

View File

@ -18,8 +18,6 @@ var IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL = 25;
var CartodbWindshaft = require('../../lib/cartodb/server'); var CartodbWindshaft = require('../../lib/cartodb/server');
var serverOptions = require('../../lib/cartodb/server_options'); var serverOptions = require('../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var QueryTables = require('cartodb-query-tables'); var QueryTables = require('cartodb-query-tables');
@ -27,7 +25,12 @@ var QueryTables = require('cartodb-query-tables');
var suiteName = 'multilayer:postgres=layergroup_url=' + layergroup_url; var suiteName = 'multilayer:postgres=layergroup_url=' + layergroup_url;
describe(suiteName, function() { describe(suiteName, function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
var keysToDelete; var keysToDelete;

View File

@ -10,10 +10,14 @@ var PgQueryRunner = require('../../lib/cartodb/backends/pg_query_runner');
var QueryTables = require('cartodb-query-tables'); var QueryTables = require('cartodb-query-tables');
var CartodbWindshaft = require('../../lib/cartodb/server'); var CartodbWindshaft = require('../../lib/cartodb/server');
var serverOptions = require('../../lib/cartodb/server_options'); var serverOptions = require('../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
describe('tests from old api translated to multilayer', function() { describe('tests from old api translated to multilayer', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
var layergroupUrl = '/api/v1/map'; var layergroupUrl = '/api/v1/map';

View File

@ -3,7 +3,6 @@ var test_helper = require('../support/test_helper');
var assert = require('../support/assert'); var assert = require('../support/assert');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
@ -13,6 +12,12 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
var step = require('step'); var step = require('step');
describe('named_layers', function() { describe('named_layers', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests // configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);

View File

@ -4,7 +4,6 @@ var test_helper = require('../support/test_helper');
var assert = require('../support/assert'); var assert = require('../support/assert');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var RedisPool = require('redis-mpool'); var RedisPool = require('redis-mpool');
var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
@ -13,6 +12,12 @@ var mapnik = require('windshaft').mapnik;
var IMAGE_TOLERANCE = 20; var IMAGE_TOLERANCE = 20;
describe('layers visibility for previews', function() { describe('layers visibility for previews', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests // configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);
var templateMaps = new TemplateMaps(redisPool, { var templateMaps = new TemplateMaps(redisPool, {

View File

@ -6,11 +6,16 @@ var assert = require('../support/assert');
var mapnik = require('windshaft').mapnik; var mapnik = require('windshaft').mapnik;
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry'); var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry');
describe('named maps authentication', function() { describe('named maps authentication', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests // configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);

View File

@ -5,10 +5,15 @@ var assert = require('../support/assert');
var mapnik = require('windshaft').mapnik; var mapnik = require('windshaft').mapnik;
var CartodbWindshaft = require('../../lib/cartodb/server'); var CartodbWindshaft = require('../../lib/cartodb/server');
var serverOptions = require('../../lib/cartodb/server_options'); var serverOptions = require('../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
describe('named maps provider cache', function() { describe('named maps provider cache', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests // configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);

View File

@ -6,11 +6,16 @@ var assert = require('../support/assert');
var mapnik = require('windshaft').mapnik; var mapnik = require('windshaft').mapnik;
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js');
var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry'); var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry');
describe('named maps preview stats', function() { describe('named maps preview stats', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);
var templateMaps = new TemplateMaps(redisPool, { var templateMaps = new TemplateMaps(redisPool, {

View File

@ -3,7 +3,6 @@ var test_helper = require('../support/test_helper');
var assert = require('../support/assert'); var assert = require('../support/assert');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
@ -15,6 +14,12 @@ var windshaft = require('windshaft');
describe('overviews metadata', function() { describe('overviews metadata', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests // configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);
@ -111,6 +116,12 @@ describe('overviews metadata', function() {
}); });
describe('overviews metadata with filters', function() { describe('overviews metadata with filters', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests // configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);

View File

@ -3,7 +3,6 @@ var test_helper = require('../support/test_helper');
var assert = require('../support/assert'); var assert = require('../support/assert');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
@ -13,8 +12,13 @@ var step = require('step');
var windshaft = require('windshaft'); var windshaft = require('windshaft');
describe('overviews metadata for named maps', function() { describe('overviews metadata for named maps', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
// configure redis pool instance to use in tests // configure redis pool instance to use in tests
var redisPool = new RedisPool(global.environment.redis); var redisPool = new RedisPool(global.environment.redis);

View File

@ -6,9 +6,12 @@ var ServerOptions = require('./ported/support/ported_server_options');
var testClient = require('./ported/support/test_client'); var testClient = require('./ported/support/test_client');
describe('overviews_queries', function() { describe('overviews_queries', function() {
var server;
var server = cartodbServer(ServerOptions); before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 2; var IMAGE_EQUALS_TOLERANCE_PER_MIL = 2;

View File

@ -7,8 +7,12 @@ var PortedServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('attributes', function() { describe('attributes', function() {
var server = cartodbServer(PortedServerOptions); var server;
before(function () {
server = cartodbServer(PortedServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
var test_mapconfig_1 = { var test_mapconfig_1 = {
version: '1.1.0', version: '1.1.0',

View File

@ -11,12 +11,11 @@ describe('external resources', function() {
var res_serv; // resources server var res_serv; // resources server
var res_serv_status = { numrequests:0 }; // status of resources server var res_serv_status = { numrequests:0 }; // status of resources server
var res_serv_port = 8033; // FIXME: make configurable ? var res_serv_port;
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25; var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25;
before(function(done) { before(function(done) {
nock.enableNetConnect('127.0.0.1');
// Start a server to test external resources // Start a server to test external resources
res_serv = http.createServer( function(request, response) { res_serv = http.createServer( function(request, response) {
++res_serv_status.numrequests; ++res_serv_status.numrequests;
@ -32,12 +31,24 @@ describe('external resources', function() {
response.end(); response.end();
}); });
}); });
res_serv.listen(res_serv_port, done);
const host = '127.0.0.1';
const markersServer = res_serv.listen(0);
res_serv_port = markersServer.address().port;
nock.disableNetConnect();
nock.enableNetConnect(host);
markersServer.on('listening', done);
}); });
after(function(done) { after(function(done) {
testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir); testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir);
nock.cleanAll();
nock.enableNetConnect();
// Close the resources server // Close the resources server
res_serv.close(done); res_serv.close(done);
}); });

View File

@ -10,9 +10,13 @@ var ServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('multilayer', function() { describe('multilayer', function() {
var server;
var server = cartodbServer(ServerOptions); before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
mapnik.register_system_fonts(); mapnik.register_system_fonts();
var available_system_fonts = _.keys(mapnik.fontFiles()); var available_system_fonts = _.keys(mapnik.fontFiles());

View File

@ -8,9 +8,12 @@ var testClient = require('./support/test_client');
var TestClient = require('../../support/test-client'); var TestClient = require('../../support/test-client');
describe('multilayer error cases', function() { describe('multilayer error cases', function() {
var server;
var server = cartodbServer(ServerOptions); before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
// var client = null; // var client = null;
afterEach(function(done) { afterEach(function(done) {

View File

@ -8,9 +8,12 @@ var PortedServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('multilayer interactivity and layers order', function() { describe('multilayer interactivity and layers order', function() {
var server;
var server = cartodbServer(PortedServerOptions); before(function () {
server = cartodbServer(PortedServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
function layerType(layer) { function layerType(layer) {
return layer.type || 'undefined'; return layer.type || 'undefined';

View File

@ -8,8 +8,12 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('raster', function() { describe('raster', function() {
var server = cartodbServer(ServerOptions); var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
function checkCORSHeaders(res) { function checkCORSHeaders(res) {
assert.equal(res.headers['access-control-allow-headers'], 'X-Requested-With, X-Prototype-Version, X-CSRF-Token'); assert.equal(res.headers['access-control-allow-headers'], 'X-Requested-With, X-Prototype-Version, X-CSRF-Token');

View File

@ -11,9 +11,12 @@ describe('retina support', function() {
var layergroupId = null; var layergroupId = null;
var server = cartodbServer(ServerOptions); var server;
server.setMaxListeners(0);
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var keysToDelete; var keysToDelete;
beforeEach(function(done) { beforeEach(function(done) {

View File

@ -6,9 +6,12 @@ var ServerOptions = require('./support/ported_server_options');
var testClient = require('./support/test_client'); var testClient = require('./support/test_client');
describe('server', function() { describe('server', function() {
var server;
var server = cartodbServer(ServerOptions); before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
after(function() { after(function() {
testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir); testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir);

View File

@ -8,9 +8,12 @@ var ServerOptions = require('./support/ported_server_options');
var testClient = require('./support/test_client'); var testClient = require('./support/test_client');
describe('server_gettile', function() { describe('server_gettile', function() {
var server;
var server = cartodbServer(ServerOptions); before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25; var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25;

View File

@ -11,17 +11,22 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
var IMAGE_EQUALS_TOLERANCE_PER_MIL = 85; var IMAGE_EQUALS_TOLERANCE_PER_MIL = 85;
describe('server_png8_format', function() { describe('server_png8_format', function() {
var serverPng32;
var serverPng8;
before(function () {
var serverOptionsPng32 = ServerOptions; var serverOptionsPng32 = ServerOptions;
serverOptionsPng32.grainstore = _.clone(ServerOptions.grainstore); serverOptionsPng32.grainstore = _.clone(ServerOptions.grainstore);
serverOptionsPng32.grainstore.mapnik_tile_format = 'png32'; serverOptionsPng32.grainstore.mapnik_tile_format = 'png32';
var serverPng32 = cartodbServer(serverOptionsPng32); serverPng32 = cartodbServer(serverOptionsPng32);
serverPng32.setMaxListeners(0); serverPng32.setMaxListeners(0);
var serverOptionsPng8 = ServerOptions; var serverOptionsPng8 = ServerOptions;
serverOptionsPng8.grainstore = _.clone(ServerOptions.grainstore); serverOptionsPng8.grainstore = _.clone(ServerOptions.grainstore);
serverOptionsPng8.grainstore.mapnik_tile_format = 'png8:m=h'; serverOptionsPng8.grainstore.mapnik_tile_format = 'png8:m=h';
var serverPng8 = cartodbServer(serverOptionsPng8); serverPng8 = cartodbServer(serverOptionsPng8);
serverPng8.setMaxListeners(0); serverPng8.setMaxListeners(0);
});
var layergroupId; var layergroupId;

View File

@ -39,10 +39,19 @@ module.exports = {
getTileLayer: getTileLayer getTileLayer: getTileLayer
}; };
var server;
var server = new CartodbServer(PortedServerOptions); function getServer () {
if (server) {
return server;
}
server = new CartodbServer(PortedServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
return server;
}
var jsonContentType = 'application/json; charset=utf-8'; var jsonContentType = 'application/json; charset=utf-8';
var jsContentType = 'text/javascript; charset=utf-8'; var jsContentType = 'text/javascript; charset=utf-8';
var pngContentType = 'image/png'; var pngContentType = 'image/png';
@ -349,7 +358,7 @@ function getGeneric(layergroupConfig, url, expectedResponse, callback) {
'Content-Type': 'application/json; charset=utf-8' 'Content-Type': 'application/json; charset=utf-8'
} }
}; };
assert.response(server, request, expectedResponse, function (res, err) { assert.response(getServer(), request, expectedResponse, function (res, err) {
next(err, res); next(err, res);
}); });
}, },
@ -384,7 +393,7 @@ function getGeneric(layergroupConfig, url, expectedResponse, callback) {
request.encoding = 'binary'; request.encoding = 'binary';
} }
assert.response(server, request, expectedResponse, function (res, err) { assert.response(getServer(), request, expectedResponse, function (res, err) {
next(err, res); next(err, res);
}); });
}, },

View File

@ -9,9 +9,12 @@ var ServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('torque', function() { describe('torque', function() {
var server;
var server = cartodbServer(ServerOptions); before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0); server.setMaxListeners(0);
});
var keysToDelete; var keysToDelete;
beforeEach(function() { beforeEach(function() {

View File

@ -7,6 +7,13 @@ var ServerOptions = require('./support/ported_server_options');
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('torque boundary points', function() { describe('torque boundary points', function() {
var server;
before(function () {
server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
});
var layergroupIdToDelete = null; var layergroupIdToDelete = null;
beforeEach(function() { beforeEach(function() {
@ -22,9 +29,6 @@ describe('torque boundary points', function() {
testHelper.deleteRedisKeys(keysToDelete, done); testHelper.deleteRedisKeys(keysToDelete, done);
}); });
var server = cartodbServer(ServerOptions);
server.setMaxListeners(0);
var boundaryPointsMapConfig = { var boundaryPointsMapConfig = {
version: '1.1.0', version: '1.1.0',
layers: [ layers: [

View File

@ -6,11 +6,15 @@ var step = require('step');
var CartodbWindshaft = require('../../lib/cartodb/server'); var CartodbWindshaft = require('../../lib/cartodb/server');
var serverOptions = require('../../lib/cartodb/server_options'); var serverOptions = require('../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
describe('server', function() { describe('server', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
// TODO: I guess this should be a 404 instead... // TODO: I guess this should be a 404 instead...
it("get call to server returns 200", function(done){ it("get call to server returns 200", function(done){
@ -54,6 +58,12 @@ describe('server', function() {
}); });
describe('server old_api', function() { describe('server old_api', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
});
// See https://github.com/CartoDB/Windshaft-cartodb/issues/115 // See https://github.com/CartoDB/Windshaft-cartodb/issues/115
it.skip("get'ing tile with not-strictly-valid style", function(done) { it.skip("get'ing tile with not-strictly-valid style", function(done) {
@ -68,5 +78,4 @@ describe('server old_api', function() {
done(); done();
}); });
}); });
}); });

View File

@ -20,13 +20,17 @@ var helper = require(__dirname + '/../support/test_helper');
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server');
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token');
describe('template_api', function() { describe('template_api', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
server.setMaxListeners(0);
server.layergroupAffectedTablesCache.cache.reset(); server.layergroupAffectedTablesCache.cache.reset();
});
var httpRendererResourcesServer; var httpRendererResourcesServer;
before(function(done) { before(function(done) {

View File

@ -4,11 +4,15 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
var testHelper = require('../../support/test_helper'); var testHelper = require('../../support/test_helper');
var CartodbWindshaft = require('../../../lib/cartodb/server'); var CartodbWindshaft = require('../../../lib/cartodb/server');
var serverOptions = require('../../../lib/cartodb/server_options'); var serverOptions = require('../../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var mapnik = require('windshaft').mapnik; var mapnik = require('windshaft').mapnik;
var IMAGE_TOLERANCE_PER_MIL = 10; var IMAGE_TOLERANCE_PER_MIL = 10;
describe('turbo-carto for named maps', function() { describe('turbo-carto for named maps', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var keysToDelete; var keysToDelete;

View File

@ -8,11 +8,15 @@ var helper = require('../../support/test_helper');
var CartodbWindshaft = require('../../../lib/cartodb/server'); var CartodbWindshaft = require('../../../lib/cartodb/server');
var serverOptions = require('../../../lib/cartodb/server_options'); var serverOptions = require('../../../lib/cartodb/server_options');
var server = new CartodbWindshaft(serverOptions);
var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token');
describe('named-maps widgets', function() { describe('named-maps widgets', function() {
var server;
before(function () {
server = new CartodbWindshaft(serverOptions);
});
var username = 'localhost'; var username = 'localhost';
var widgetsTemplateName = 'widgets-template'; var widgetsTemplateName = 'widgets-template';

View File

@ -87,30 +87,18 @@ assert.response = function(server, req, res, callback) {
res = {}; res = {};
} }
var port = 5555, var port = 0, // let the OS to choose a free port
host = '127.0.0.1'; host = '127.0.0.1';
var listeningAttempts = 0; var listener = server.listen(port, host);
var listener; listener.on('error', callback);
function listen() { listener.on('listening', function onServerListening () {
if (listeningAttempts > 25) {
return callback(null, new Error('Tried too many ports'));
}
listener = server.listen(port, host);
listener.on('error', function() {
port++;
listeningAttempts++;
listen();
});
listener.on('listening', onServerListening);
}
listen();
// jshint maxcomplexity:9 // jshint maxcomplexity:9
function onServerListening() { const { address: host, port } = listener.address();
const address = `${host}:${port}`;
var requestParams = { var requestParams = {
url: 'http://' + host + ':' + port + req.url, url: 'http://' + address + req.url,
method: req.method || 'GET', method: req.method || 'GET',
headers: req.headers || {}, headers: req.headers || {},
timeout: req.timeout || 0, timeout: req.timeout || 0,
@ -123,13 +111,16 @@ assert.response = function(server, req, res, callback) {
request(requestParams, function assert$response$requestHandler(error, response, body) { request(requestParams, function assert$response$requestHandler(error, response, body) {
listener.close(function () { listener.close(function () {
if (error) {
return callback(null, error);
}
response.body = response.body || body; response.body = response.body || body;
var err = validateResponse(response, res); var err = validateResponse(response, res);
return callback(response, err); return callback(response, err);
}); });
}); });
});
}
}; };
function validateResponseBody(response, expected) { function validateResponseBody(response, expected) {

View File

@ -12,7 +12,6 @@ var LZMA = require('lzma').LZMA;
var lzmaWorker = new LZMA(); var lzmaWorker = new LZMA();
var redis = require('redis'); var redis = require('redis');
var nock = require('nock');
var log4js = require('log4js'); var log4js = require('log4js');
var pg = require('pg'); var pg = require('pg');
const setICUEnvVariable = require('../../lib/cartodb/utils/icu_data_env_setter'); const setICUEnvVariable = require('../../lib/cartodb/utils/icu_data_env_setter');
@ -104,10 +103,6 @@ beforeEach(function() {
//global afterEach to capture test suites that leave keys in redis //global afterEach to capture test suites that leave keys in redis
afterEach(function(done) { afterEach(function(done) {
// restoring nock globally after each suite
nock.cleanAll();
nock.enableNetConnect();
var expectedKeys = { var expectedKeys = {
'rails:test_windshaft_cartodb_user_1_db:test_table_private_1': true, 'rails:test_windshaft_cartodb_user_1_db:test_table_private_1': true,
'rails:test_windshaft_cartodb_user_1_db:my_table': true, 'rails:test_windshaft_cartodb_user_1_db:my_table': true,
@ -223,4 +218,3 @@ module.exports = {
configureMetadata, configureMetadata,
cleanPGPoolConnections cleanPGPoolConnections
}; };