From 98f29f945b973a9c81d1ef25e550a954cab87280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 16 Apr 2018 14:09:24 +0200 Subject: [PATCH 1/3] Create application server inside of describes instead of at module level --- test/acceptance/analysis/named-maps.js | 2 +- test/acceptance/auth/authorization-fallback.js | 5 +++-- test/acceptance/cache/cache_headers.js | 4 ++-- test/acceptance/dynamic-styling-named-maps.js | 2 +- test/acceptance/errors-with-context.js | 3 ++- test/acceptance/multilayer.js | 5 ++--- test/acceptance/multilayer_server.js | 4 ++-- test/acceptance/named_layers.js | 3 ++- test/acceptance/named_layers_visibility.js | 2 +- test/acceptance/named_maps_authentication.js | 3 ++- test/acceptance/named_maps_cache.js | 3 ++- test/acceptance/named_maps_stats.js | 3 ++- test/acceptance/overviews_metadata.js | 5 ++++- test/acceptance/overviews_metadata_named_maps.js | 4 ++-- test/acceptance/server.js | 7 ++++--- test/acceptance/templates.js | 4 ++-- test/acceptance/turbo-carto/named-maps.js | 2 +- test/acceptance/widgets/named-maps.js | 2 +- 18 files changed, 36 insertions(+), 27 deletions(-) diff --git a/test/acceptance/analysis/named-maps.js b/test/acceptance/analysis/named-maps.js index b9c93e00..63ddafa2 100644 --- a/test/acceptance/analysis/named-maps.js +++ b/test/acceptance/analysis/named-maps.js @@ -4,12 +4,12 @@ var helper = require('../../support/test_helper'); var CartodbWindshaft = require('../../../lib/cartodb/server'); var serverOptions = require('../../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var TestClient = require('../../support/test-client'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('named-maps analysis', function() { + var server = new CartodbWindshaft(serverOptions); var IMAGE_TOLERANCE_PER_MIL = 20; diff --git a/test/acceptance/auth/authorization-fallback.js b/test/acceptance/auth/authorization-fallback.js index 8546c8ff..95b86612 100644 --- a/test/acceptance/auth/authorization-fallback.js +++ b/test/acceptance/auth/authorization-fallback.js @@ -5,7 +5,6 @@ const assert = require('../../support/assert'); const testHelper = require('../../support/test_helper'); const CartodbWindshaft = require('../../../lib/cartodb/server'); const serverOptions = require('../../../lib/cartodb/server_options'); -const server = new CartodbWindshaft(serverOptions); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); function singleLayergroupConfig(sql, cartocss) { @@ -46,6 +45,8 @@ var pointSqlPublic = "select * from test_table"; var keysToDelete; describe('authorization fallback', function () { + const server = new CartodbWindshaft(serverOptions); + beforeEach(function () { keysToDelete = {}; }); @@ -56,7 +57,7 @@ describe('authorization fallback', function () { it("succeed with master", function (done) { var layergroup = singleLayergroupConfig(pointSqlMaster, '#layer { marker-fill:red; }'); - + assert.response(server, createRequest(layergroup, 'user_previous_to_project_auth', '4444'), { diff --git a/test/acceptance/cache/cache_headers.js b/test/acceptance/cache/cache_headers.js index a4ce7285..abe472ee 100644 --- a/test/acceptance/cache/cache_headers.js +++ b/test/acceptance/cache/cache_headers.js @@ -5,12 +5,12 @@ var qs = require('querystring'); var CartodbWindshaft = require('../../../lib/cartodb/server'); var serverOptions = require('../../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); -server.setMaxListeners(0); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('get requests with cache headers', function() { + var server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); var keysToDelete; beforeEach(function() { diff --git a/test/acceptance/dynamic-styling-named-maps.js b/test/acceptance/dynamic-styling-named-maps.js index 87796c5e..87da7d81 100644 --- a/test/acceptance/dynamic-styling-named-maps.js +++ b/test/acceptance/dynamic-styling-named-maps.js @@ -4,9 +4,9 @@ var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); var testHelper = require(__dirname + '/../support/test_helper'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); describe('dynamic styling for named maps', function() { + var server = new CartodbWindshaft(serverOptions); var keysToDelete; diff --git a/test/acceptance/errors-with-context.js b/test/acceptance/errors-with-context.js index e6e88f8b..5579524b 100644 --- a/test/acceptance/errors-with-context.js +++ b/test/acceptance/errors-with-context.js @@ -1,9 +1,10 @@ var assert = require('../support/assert'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); describe('error with context', function () { + var server = new CartodbWindshaft(serverOptions); + var layerOK = { options: { sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator ' + diff --git a/test/acceptance/multilayer.js b/test/acceptance/multilayer.js index b4840879..895e8fb1 100644 --- a/test/acceptance/multilayer.js +++ b/test/acceptance/multilayer.js @@ -18,8 +18,6 @@ var IMAGE_EQUALS_HIGHER_TOLERANCE_PER_MIL = 25; var CartodbWindshaft = require('../../lib/cartodb/server'); var serverOptions = require('../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); -server.setMaxListeners(0); var QueryTables = require('cartodb-query-tables'); @@ -27,7 +25,8 @@ var QueryTables = require('cartodb-query-tables'); var suiteName = 'multilayer:postgres=layergroup_url=' + layergroup_url; describe(suiteName, function() { - + var server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); var keysToDelete; diff --git a/test/acceptance/multilayer_server.js b/test/acceptance/multilayer_server.js index b599cf9c..f39d4db0 100644 --- a/test/acceptance/multilayer_server.js +++ b/test/acceptance/multilayer_server.js @@ -10,10 +10,10 @@ var PgQueryRunner = require('../../lib/cartodb/backends/pg_query_runner'); var QueryTables = require('cartodb-query-tables'); var CartodbWindshaft = require('../../lib/cartodb/server'); var serverOptions = require('../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); -server.setMaxListeners(0); describe('tests from old api translated to multilayer', function() { + var server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); var layergroupUrl = '/api/v1/map'; diff --git a/test/acceptance/named_layers.js b/test/acceptance/named_layers.js index 2090ffe2..7d34deb8 100644 --- a/test/acceptance/named_layers.js +++ b/test/acceptance/named_layers.js @@ -3,7 +3,6 @@ var test_helper = require('../support/test_helper'); var assert = require('../support/assert'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); @@ -13,6 +12,8 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var step = require('step'); describe('named_layers', function() { + var server = new CartodbWindshaft(serverOptions); + // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/named_layers_visibility.js b/test/acceptance/named_layers_visibility.js index 01e10126..585ae58d 100644 --- a/test/acceptance/named_layers_visibility.js +++ b/test/acceptance/named_layers_visibility.js @@ -4,7 +4,6 @@ var test_helper = require('../support/test_helper'); var assert = require('../support/assert'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var RedisPool = require('redis-mpool'); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); @@ -13,6 +12,7 @@ var mapnik = require('windshaft').mapnik; var IMAGE_TOLERANCE = 20; describe('layers visibility for previews', function() { + var server = new CartodbWindshaft(serverOptions); // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); var templateMaps = new TemplateMaps(redisPool, { diff --git a/test/acceptance/named_maps_authentication.js b/test/acceptance/named_maps_authentication.js index ba791f37..7215b014 100644 --- a/test/acceptance/named_maps_authentication.js +++ b/test/acceptance/named_maps_authentication.js @@ -6,11 +6,12 @@ var assert = require('../support/assert'); var mapnik = require('windshaft').mapnik; var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry'); describe('named maps authentication', function() { + var server = new CartodbWindshaft(serverOptions); + // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/named_maps_cache.js b/test/acceptance/named_maps_cache.js index 5d121afa..c4f7f92d 100644 --- a/test/acceptance/named_maps_cache.js +++ b/test/acceptance/named_maps_cache.js @@ -5,10 +5,11 @@ var assert = require('../support/assert'); var mapnik = require('windshaft').mapnik; var CartodbWindshaft = require('../../lib/cartodb/server'); var serverOptions = require('../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); describe('named maps provider cache', function() { + var server = new CartodbWindshaft(serverOptions); + // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/named_maps_stats.js b/test/acceptance/named_maps_stats.js index 9813a402..14b512e5 100644 --- a/test/acceptance/named_maps_stats.js +++ b/test/acceptance/named_maps_stats.js @@ -6,11 +6,12 @@ var assert = require('../support/assert'); var mapnik = require('windshaft').mapnik; var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry'); describe('named maps preview stats', function() { + var server = new CartodbWindshaft(serverOptions); + var redisPool = new RedisPool(global.environment.redis); var templateMaps = new TemplateMaps(redisPool, { diff --git a/test/acceptance/overviews_metadata.js b/test/acceptance/overviews_metadata.js index 8af7b2a4..76bc5341 100644 --- a/test/acceptance/overviews_metadata.js +++ b/test/acceptance/overviews_metadata.js @@ -3,7 +3,6 @@ var test_helper = require('../support/test_helper'); var assert = require('../support/assert'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); @@ -15,6 +14,8 @@ var windshaft = require('windshaft'); describe('overviews metadata', function() { + var server = new CartodbWindshaft(serverOptions); + // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); @@ -111,6 +112,8 @@ describe('overviews metadata', function() { }); describe('overviews metadata with filters', function() { + var server = new CartodbWindshaft(serverOptions); + // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/overviews_metadata_named_maps.js b/test/acceptance/overviews_metadata_named_maps.js index a6557910..cd771ee3 100644 --- a/test/acceptance/overviews_metadata_named_maps.js +++ b/test/acceptance/overviews_metadata_named_maps.js @@ -3,7 +3,6 @@ var test_helper = require('../support/test_helper'); var assert = require('../support/assert'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); @@ -13,8 +12,9 @@ var step = require('step'); var windshaft = require('windshaft'); - describe('overviews metadata for named maps', function() { + var server = new CartodbWindshaft(serverOptions); + // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/server.js b/test/acceptance/server.js index 6c293aa4..ca4a9c8b 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -6,11 +6,11 @@ var step = require('step'); var CartodbWindshaft = require('../../lib/cartodb/server'); var serverOptions = require('../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); -server.setMaxListeners(0); describe('server', function() { + var server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); // TODO: I guess this should be a 404 instead... it("get call to server returns 200", function(done){ @@ -54,6 +54,8 @@ describe('server', function() { }); describe('server old_api', function() { + var server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); // See https://github.com/CartoDB/Windshaft-cartodb/issues/115 it.skip("get'ing tile with not-strictly-valid style", function(done) { @@ -68,5 +70,4 @@ describe('server old_api', function() { done(); }); }); - }); diff --git a/test/acceptance/templates.js b/test/acceptance/templates.js index 92a95f60..230a64b1 100644 --- a/test/acceptance/templates.js +++ b/test/acceptance/templates.js @@ -20,12 +20,12 @@ var helper = require(__dirname + '/../support/test_helper'); var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); -server.setMaxListeners(0); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); describe('template_api', function() { + var server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); server.layergroupAffectedTablesCache.cache.reset(); var httpRendererResourcesServer; diff --git a/test/acceptance/turbo-carto/named-maps.js b/test/acceptance/turbo-carto/named-maps.js index 063118aa..fde34922 100644 --- a/test/acceptance/turbo-carto/named-maps.js +++ b/test/acceptance/turbo-carto/named-maps.js @@ -4,11 +4,11 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var testHelper = require('../../support/test_helper'); var CartodbWindshaft = require('../../../lib/cartodb/server'); var serverOptions = require('../../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var mapnik = require('windshaft').mapnik; var IMAGE_TOLERANCE_PER_MIL = 10; describe('turbo-carto for named maps', function() { + var server = new CartodbWindshaft(serverOptions); var keysToDelete; diff --git a/test/acceptance/widgets/named-maps.js b/test/acceptance/widgets/named-maps.js index e54ced23..4caa6a0c 100644 --- a/test/acceptance/widgets/named-maps.js +++ b/test/acceptance/widgets/named-maps.js @@ -8,11 +8,11 @@ var helper = require('../../support/test_helper'); var CartodbWindshaft = require('../../../lib/cartodb/server'); var serverOptions = require('../../../lib/cartodb/server_options'); -var server = new CartodbWindshaft(serverOptions); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('named-maps widgets', function() { + var server = new CartodbWindshaft(serverOptions); var username = 'localhost'; var widgetsTemplateName = 'widgets-template'; From 817afb13d1c41b1dd5ea6a24fae27f823d72cb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 16 Apr 2018 16:16:23 +0200 Subject: [PATCH 2/3] Use mocha hooks to create server just before perform the test --- test/acceptance/analysis/named-maps.js | 7 +++++- .../acceptance/auth/authorization-fallback.js | 6 ++++- test/acceptance/cache/cache_headers.js | 9 +++++-- .../cache/surrogate_keys_invalidation.js | 7 +++++- test/acceptance/dynamic-styling-named-maps.js | 6 ++++- test/acceptance/errors-with-context.js | 7 +++++- test/acceptance/multilayer.js | 8 ++++-- test/acceptance/multilayer_server.js | 8 ++++-- test/acceptance/named_layers.js | 6 ++++- test/acceptance/named_layers_visibility.js | 7 +++++- test/acceptance/named_maps_authentication.js | 6 ++++- test/acceptance/named_maps_cache.js | 6 ++++- test/acceptance/named_maps_stats.js | 6 ++++- test/acceptance/overviews_metadata.js | 12 +++++++-- .../overviews_metadata_named_maps.js | 6 ++++- test/acceptance/overviews_queries.js | 7 ++++-- test/acceptance/ported/attributes.js | 8 ++++-- test/acceptance/ported/multilayer.js | 8 ++++-- .../ported/multilayer_error_cases.js | 7 ++++-- .../ported/multilayer_interactivity.js | 7 ++++-- test/acceptance/ported/raster.js | 8 ++++-- test/acceptance/ported/retina.js | 7 ++++-- test/acceptance/ported/server.js | 7 ++++-- test/acceptance/ported/server_gettile.js | 7 ++++-- test/acceptance/ported/server_png8_format.js | 25 +++++++++++-------- test/acceptance/ported/support/test_client.js | 17 ++++++++++--- test/acceptance/ported/torque.js | 7 ++++-- test/acceptance/ported/torque_boundaries.js | 10 +++++--- test/acceptance/server.js | 16 +++++++++--- test/acceptance/templates.js | 10 +++++--- test/acceptance/turbo-carto/named-maps.js | 6 ++++- test/acceptance/widgets/named-maps.js | 6 ++++- 32 files changed, 205 insertions(+), 65 deletions(-) diff --git a/test/acceptance/analysis/named-maps.js b/test/acceptance/analysis/named-maps.js index 63ddafa2..42fb19d0 100644 --- a/test/acceptance/analysis/named-maps.js +++ b/test/acceptance/analysis/named-maps.js @@ -9,7 +9,12 @@ var TestClient = require('../../support/test-client'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('named-maps analysis', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); + var IMAGE_TOLERANCE_PER_MIL = 20; diff --git a/test/acceptance/auth/authorization-fallback.js b/test/acceptance/auth/authorization-fallback.js index 95b86612..bbc16140 100644 --- a/test/acceptance/auth/authorization-fallback.js +++ b/test/acceptance/auth/authorization-fallback.js @@ -45,7 +45,11 @@ var pointSqlPublic = "select * from test_table"; var keysToDelete; describe('authorization fallback', function () { - const server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); beforeEach(function () { keysToDelete = {}; diff --git a/test/acceptance/cache/cache_headers.js b/test/acceptance/cache/cache_headers.js index abe472ee..8e0cb9f3 100644 --- a/test/acceptance/cache/cache_headers.js +++ b/test/acceptance/cache/cache_headers.js @@ -9,8 +9,13 @@ var serverOptions = require('../../../lib/cartodb/server_options'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('get requests with cache headers', function() { - var server = new CartodbWindshaft(serverOptions); - server.setMaxListeners(0); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); + }); + var keysToDelete; beforeEach(function() { diff --git a/test/acceptance/cache/surrogate_keys_invalidation.js b/test/acceptance/cache/surrogate_keys_invalidation.js index fbe2ff7d..5538e603 100644 --- a/test/acceptance/cache/surrogate_keys_invalidation.js +++ b/test/acceptance/cache/surrogate_keys_invalidation.js @@ -30,7 +30,12 @@ describe('templates surrogate keys', function() { serviceId: FAKE_FASTLY_SERVICE_ID }; - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); + var templateOwner = 'localhost'; var templateName = 'acceptance'; diff --git a/test/acceptance/dynamic-styling-named-maps.js b/test/acceptance/dynamic-styling-named-maps.js index 87da7d81..ac483cf2 100644 --- a/test/acceptance/dynamic-styling-named-maps.js +++ b/test/acceptance/dynamic-styling-named-maps.js @@ -6,7 +6,11 @@ var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); describe('dynamic styling for named maps', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); var keysToDelete; diff --git a/test/acceptance/errors-with-context.js b/test/acceptance/errors-with-context.js index 5579524b..27440368 100644 --- a/test/acceptance/errors-with-context.js +++ b/test/acceptance/errors-with-context.js @@ -3,7 +3,12 @@ var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/server'); var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); describe('error with context', function () { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); + var layerOK = { options: { diff --git a/test/acceptance/multilayer.js b/test/acceptance/multilayer.js index 895e8fb1..d818ae5b 100644 --- a/test/acceptance/multilayer.js +++ b/test/acceptance/multilayer.js @@ -25,8 +25,12 @@ var QueryTables = require('cartodb-query-tables'); var suiteName = 'multilayer:postgres=layergroup_url=' + layergroup_url; describe(suiteName, function() { - var server = new CartodbWindshaft(serverOptions); - server.setMaxListeners(0); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); + }); var keysToDelete; diff --git a/test/acceptance/multilayer_server.js b/test/acceptance/multilayer_server.js index f39d4db0..b95c9a74 100644 --- a/test/acceptance/multilayer_server.js +++ b/test/acceptance/multilayer_server.js @@ -12,8 +12,12 @@ var CartodbWindshaft = require('../../lib/cartodb/server'); var serverOptions = require('../../lib/cartodb/server_options'); describe('tests from old api translated to multilayer', function() { - var server = new CartodbWindshaft(serverOptions); - server.setMaxListeners(0); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); + }); var layergroupUrl = '/api/v1/map'; diff --git a/test/acceptance/named_layers.js b/test/acceptance/named_layers.js index 7d34deb8..0f8998e4 100644 --- a/test/acceptance/named_layers.js +++ b/test/acceptance/named_layers.js @@ -12,7 +12,11 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var step = require('step'); describe('named_layers', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/named_layers_visibility.js b/test/acceptance/named_layers_visibility.js index 585ae58d..bc8e3f6b 100644 --- a/test/acceptance/named_layers_visibility.js +++ b/test/acceptance/named_layers_visibility.js @@ -12,7 +12,12 @@ var mapnik = require('windshaft').mapnik; var IMAGE_TOLERANCE = 20; describe('layers visibility for previews', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); + // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); var templateMaps = new TemplateMaps(redisPool, { diff --git a/test/acceptance/named_maps_authentication.js b/test/acceptance/named_maps_authentication.js index 7215b014..00ac721e 100644 --- a/test/acceptance/named_maps_authentication.js +++ b/test/acceptance/named_maps_authentication.js @@ -10,7 +10,11 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry'); describe('named maps authentication', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/named_maps_cache.js b/test/acceptance/named_maps_cache.js index c4f7f92d..6ebd05b1 100644 --- a/test/acceptance/named_maps_cache.js +++ b/test/acceptance/named_maps_cache.js @@ -8,7 +8,11 @@ var serverOptions = require('../../lib/cartodb/server_options'); var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); describe('named maps provider cache', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/named_maps_stats.js b/test/acceptance/named_maps_stats.js index 14b512e5..f585d059 100644 --- a/test/acceptance/named_maps_stats.js +++ b/test/acceptance/named_maps_stats.js @@ -10,7 +10,11 @@ var TemplateMaps = require('../../lib/cartodb/backends/template_maps.js'); var NamedMapsCacheEntry = require('../../lib/cartodb/cache/model/named_maps_entry'); describe('named maps preview stats', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/overviews_metadata.js b/test/acceptance/overviews_metadata.js index 76bc5341..08cf37a9 100644 --- a/test/acceptance/overviews_metadata.js +++ b/test/acceptance/overviews_metadata.js @@ -14,7 +14,11 @@ var windshaft = require('windshaft'); describe('overviews metadata', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); @@ -112,7 +116,11 @@ describe('overviews metadata', function() { }); describe('overviews metadata with filters', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/overviews_metadata_named_maps.js b/test/acceptance/overviews_metadata_named_maps.js index cd771ee3..80451222 100644 --- a/test/acceptance/overviews_metadata_named_maps.js +++ b/test/acceptance/overviews_metadata_named_maps.js @@ -13,7 +13,11 @@ var step = require('step'); var windshaft = require('windshaft'); describe('overviews metadata for named maps', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); // configure redis pool instance to use in tests var redisPool = new RedisPool(global.environment.redis); diff --git a/test/acceptance/overviews_queries.js b/test/acceptance/overviews_queries.js index ad7599a6..6fdf7d62 100644 --- a/test/acceptance/overviews_queries.js +++ b/test/acceptance/overviews_queries.js @@ -6,9 +6,12 @@ var ServerOptions = require('./ported/support/ported_server_options'); var testClient = require('./ported/support/test_client'); describe('overviews_queries', function() { + var server; - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); var IMAGE_EQUALS_TOLERANCE_PER_MIL = 2; diff --git a/test/acceptance/ported/attributes.js b/test/acceptance/ported/attributes.js index 8b36c3e3..ba241a4f 100644 --- a/test/acceptance/ported/attributes.js +++ b/test/acceptance/ported/attributes.js @@ -7,8 +7,12 @@ var PortedServerOptions = require('./support/ported_server_options'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('attributes', function() { - var server = cartodbServer(PortedServerOptions); - server.setMaxListeners(0); + var server; + + before(function () { + server = cartodbServer(PortedServerOptions); + server.setMaxListeners(0); + }); var test_mapconfig_1 = { version: '1.1.0', diff --git a/test/acceptance/ported/multilayer.js b/test/acceptance/ported/multilayer.js index 9da57948..0f43af8d 100644 --- a/test/acceptance/ported/multilayer.js +++ b/test/acceptance/ported/multilayer.js @@ -10,9 +10,13 @@ var ServerOptions = require('./support/ported_server_options'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('multilayer', function() { + var server; + + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); mapnik.register_system_fonts(); var available_system_fonts = _.keys(mapnik.fontFiles()); diff --git a/test/acceptance/ported/multilayer_error_cases.js b/test/acceptance/ported/multilayer_error_cases.js index 5752a9b5..dcd52f6d 100644 --- a/test/acceptance/ported/multilayer_error_cases.js +++ b/test/acceptance/ported/multilayer_error_cases.js @@ -8,9 +8,12 @@ var testClient = require('./support/test_client'); var TestClient = require('../../support/test-client'); describe('multilayer error cases', function() { + var server; - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); // var client = null; afterEach(function(done) { diff --git a/test/acceptance/ported/multilayer_interactivity.js b/test/acceptance/ported/multilayer_interactivity.js index ac406725..1e46e512 100644 --- a/test/acceptance/ported/multilayer_interactivity.js +++ b/test/acceptance/ported/multilayer_interactivity.js @@ -8,9 +8,12 @@ var PortedServerOptions = require('./support/ported_server_options'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('multilayer interactivity and layers order', function() { + var server; - var server = cartodbServer(PortedServerOptions); - server.setMaxListeners(0); + before(function () { + server = cartodbServer(PortedServerOptions); + server.setMaxListeners(0); + }); function layerType(layer) { return layer.type || 'undefined'; diff --git a/test/acceptance/ported/raster.js b/test/acceptance/ported/raster.js index 6425e090..349d4a07 100644 --- a/test/acceptance/ported/raster.js +++ b/test/acceptance/ported/raster.js @@ -8,8 +8,12 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('raster', function() { - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); + var server; + + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); function checkCORSHeaders(res) { assert.equal(res.headers['access-control-allow-headers'], 'X-Requested-With, X-Prototype-Version, X-CSRF-Token'); diff --git a/test/acceptance/ported/retina.js b/test/acceptance/ported/retina.js index 137f9738..a5c29416 100644 --- a/test/acceptance/ported/retina.js +++ b/test/acceptance/ported/retina.js @@ -11,9 +11,12 @@ describe('retina support', function() { var layergroupId = null; - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); + var server; + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); var keysToDelete; beforeEach(function(done) { diff --git a/test/acceptance/ported/server.js b/test/acceptance/ported/server.js index b18bae07..a38b4da7 100644 --- a/test/acceptance/ported/server.js +++ b/test/acceptance/ported/server.js @@ -6,9 +6,12 @@ var ServerOptions = require('./support/ported_server_options'); var testClient = require('./support/test_client'); describe('server', function() { + var server; - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); after(function() { testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir); diff --git a/test/acceptance/ported/server_gettile.js b/test/acceptance/ported/server_gettile.js index f40b680b..4dc089c9 100644 --- a/test/acceptance/ported/server_gettile.js +++ b/test/acceptance/ported/server_gettile.js @@ -8,9 +8,12 @@ var ServerOptions = require('./support/ported_server_options'); var testClient = require('./support/test_client'); describe('server_gettile', function() { + var server; - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); var IMAGE_EQUALS_TOLERANCE_PER_MIL = 25; diff --git a/test/acceptance/ported/server_png8_format.js b/test/acceptance/ported/server_png8_format.js index ee565498..c2703994 100644 --- a/test/acceptance/ported/server_png8_format.js +++ b/test/acceptance/ported/server_png8_format.js @@ -11,17 +11,22 @@ var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); var IMAGE_EQUALS_TOLERANCE_PER_MIL = 85; describe('server_png8_format', function() { - var serverOptionsPng32 = ServerOptions; - serverOptionsPng32.grainstore = _.clone(ServerOptions.grainstore); - serverOptionsPng32.grainstore.mapnik_tile_format = 'png32'; - var serverPng32 = cartodbServer(serverOptionsPng32); - serverPng32.setMaxListeners(0); + var serverPng32; + var serverPng8; - var serverOptionsPng8 = ServerOptions; - serverOptionsPng8.grainstore = _.clone(ServerOptions.grainstore); - serverOptionsPng8.grainstore.mapnik_tile_format = 'png8:m=h'; - var serverPng8 = cartodbServer(serverOptionsPng8); - serverPng8.setMaxListeners(0); + before(function () { + var serverOptionsPng32 = ServerOptions; + serverOptionsPng32.grainstore = _.clone(ServerOptions.grainstore); + serverOptionsPng32.grainstore.mapnik_tile_format = 'png32'; + serverPng32 = cartodbServer(serverOptionsPng32); + serverPng32.setMaxListeners(0); + + var serverOptionsPng8 = ServerOptions; + serverOptionsPng8.grainstore = _.clone(ServerOptions.grainstore); + serverOptionsPng8.grainstore.mapnik_tile_format = 'png8:m=h'; + serverPng8 = cartodbServer(serverOptionsPng8); + serverPng8.setMaxListeners(0); + }); var layergroupId; diff --git a/test/acceptance/ported/support/test_client.js b/test/acceptance/ported/support/test_client.js index ab4576b6..d3e08328 100644 --- a/test/acceptance/ported/support/test_client.js +++ b/test/acceptance/ported/support/test_client.js @@ -39,9 +39,18 @@ module.exports = { getTileLayer: getTileLayer }; +var server; -var server = new CartodbServer(PortedServerOptions); -server.setMaxListeners(0); +function getServer () { + if (server) { + return server; + } + + server = new CartodbServer(PortedServerOptions); + server.setMaxListeners(0); + + return server; +} var jsonContentType = 'application/json; charset=utf-8'; var jsContentType = 'text/javascript; charset=utf-8'; @@ -349,7 +358,7 @@ function getGeneric(layergroupConfig, url, expectedResponse, callback) { '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); }); }, @@ -384,7 +393,7 @@ function getGeneric(layergroupConfig, url, expectedResponse, callback) { request.encoding = 'binary'; } - assert.response(server, request, expectedResponse, function (res, err) { + assert.response(getServer(), request, expectedResponse, function (res, err) { next(err, res); }); }, diff --git a/test/acceptance/ported/torque.js b/test/acceptance/ported/torque.js index 6d761b3d..fa86d4e5 100644 --- a/test/acceptance/ported/torque.js +++ b/test/acceptance/ported/torque.js @@ -9,9 +9,12 @@ var ServerOptions = require('./support/ported_server_options'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('torque', function() { + var server; - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); var keysToDelete; beforeEach(function() { diff --git a/test/acceptance/ported/torque_boundaries.js b/test/acceptance/ported/torque_boundaries.js index 4dde46a0..9ae1face 100644 --- a/test/acceptance/ported/torque_boundaries.js +++ b/test/acceptance/ported/torque_boundaries.js @@ -7,6 +7,13 @@ var ServerOptions = require('./support/ported_server_options'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('torque boundary points', function() { + var server; + + before(function () { + server = cartodbServer(ServerOptions); + server.setMaxListeners(0); + }); + var layergroupIdToDelete = null; beforeEach(function() { @@ -22,9 +29,6 @@ describe('torque boundary points', function() { testHelper.deleteRedisKeys(keysToDelete, done); }); - var server = cartodbServer(ServerOptions); - server.setMaxListeners(0); - var boundaryPointsMapConfig = { version: '1.1.0', layers: [ diff --git a/test/acceptance/server.js b/test/acceptance/server.js index ca4a9c8b..7e917b09 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -9,8 +9,12 @@ var serverOptions = require('../../lib/cartodb/server_options'); describe('server', function() { - var server = new CartodbWindshaft(serverOptions); - server.setMaxListeners(0); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); + }); // TODO: I guess this should be a 404 instead... it("get call to server returns 200", function(done){ @@ -54,8 +58,12 @@ describe('server', function() { }); describe('server old_api', function() { - var server = new CartodbWindshaft(serverOptions); - server.setMaxListeners(0); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); + }); // See https://github.com/CartoDB/Windshaft-cartodb/issues/115 it.skip("get'ing tile with not-strictly-valid style", function(done) { diff --git a/test/acceptance/templates.js b/test/acceptance/templates.js index 230a64b1..810e1c99 100644 --- a/test/acceptance/templates.js +++ b/test/acceptance/templates.js @@ -24,9 +24,13 @@ var serverOptions = require(__dirname + '/../../lib/cartodb/server_options'); var LayergroupToken = require('../../lib/cartodb/models/layergroup-token'); describe('template_api', function() { - var server = new CartodbWindshaft(serverOptions); - server.setMaxListeners(0); - server.layergroupAffectedTablesCache.cache.reset(); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + server.setMaxListeners(0); + server.layergroupAffectedTablesCache.cache.reset(); + }); var httpRendererResourcesServer; before(function(done) { diff --git a/test/acceptance/turbo-carto/named-maps.js b/test/acceptance/turbo-carto/named-maps.js index fde34922..af31ce80 100644 --- a/test/acceptance/turbo-carto/named-maps.js +++ b/test/acceptance/turbo-carto/named-maps.js @@ -8,7 +8,11 @@ var mapnik = require('windshaft').mapnik; var IMAGE_TOLERANCE_PER_MIL = 10; describe('turbo-carto for named maps', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); var keysToDelete; diff --git a/test/acceptance/widgets/named-maps.js b/test/acceptance/widgets/named-maps.js index 4caa6a0c..f0ca0125 100644 --- a/test/acceptance/widgets/named-maps.js +++ b/test/acceptance/widgets/named-maps.js @@ -12,7 +12,11 @@ var serverOptions = require('../../../lib/cartodb/server_options'); var LayergroupToken = require('../../../lib/cartodb/models/layergroup-token'); describe('named-maps widgets', function() { - var server = new CartodbWindshaft(serverOptions); + var server; + + before(function () { + server = new CartodbWindshaft(serverOptions); + }); var username = 'localhost'; var widgetsTemplateName = 'widgets-template'; From 7012c6e77a6ba86dd3f0cc4a7469be317b718076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 17 Apr 2018 10:44:44 +0200 Subject: [PATCH 3/3] Test: Let the OS to choose a random free port to make the tiler listen at it --- .../cache/surrogate_keys_invalidation.js | 12 +++--- test/acceptance/ported/external_resources.js | 17 +++++++-- test/support/assert.js | 37 +++++++------------ test/support/test_helper.js | 6 --- 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/test/acceptance/cache/surrogate_keys_invalidation.js b/test/acceptance/cache/surrogate_keys_invalidation.js index 5538e603..36985e5e 100644 --- a/test/acceptance/cache/surrogate_keys_invalidation.js +++ b/test/acceptance/cache/surrogate_keys_invalidation.js @@ -7,7 +7,7 @@ var _ = require('underscore'); var NamedMapsCacheEntry = require(__dirname + '/../../../lib/cartodb/cache/model/named_maps_entry'); var CartodbWindshaft = require(__dirname + '/../../../lib/cartodb/server'); - +var nock = require('nock'); describe('templates surrogate keys', function() { @@ -34,9 +34,10 @@ describe('templates surrogate keys', function() { before(function () { server = new CartodbWindshaft(serverOptions); + nock.disableNetConnect(); + nock.enableNetConnect(/(127.0.0.1|cartocdn.com)/); }); - var templateOwner = 'localhost'; var templateName = 'acceptance'; var expectedTemplateId = templateName; @@ -75,9 +76,6 @@ describe('templates surrogate keys', function() { var invalidationMatchHeader = '\\b' + cacheEntryKey + '\\b'; 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) { serverOptions.varnish_purge_enabled = false; serverOptions.varnish_host = varnishHost; @@ -85,7 +83,9 @@ describe('templates surrogate keys', function() { serverOptions.fastly = fastlyConfig; - nock.restore(); + nock.cleanAll(); + nock.enableNetConnect(); + done(); }); diff --git a/test/acceptance/ported/external_resources.js b/test/acceptance/ported/external_resources.js index 0aae14c3..5791a640 100644 --- a/test/acceptance/ported/external_resources.js +++ b/test/acceptance/ported/external_resources.js @@ -11,12 +11,11 @@ describe('external resources', function() { var res_serv; // 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; before(function(done) { - nock.enableNetConnect('127.0.0.1'); // Start a server to test external resources res_serv = http.createServer( function(request, response) { ++res_serv_status.numrequests; @@ -32,12 +31,24 @@ describe('external resources', function() { 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) { testHelper.rmdirRecursiveSync(global.environment.millstone.cache_basedir); + nock.cleanAll(); + nock.enableNetConnect(); + // Close the resources server res_serv.close(done); }); diff --git a/test/support/assert.js b/test/support/assert.js index 6815a63f..89620fac 100644 --- a/test/support/assert.js +++ b/test/support/assert.js @@ -87,30 +87,18 @@ assert.response = function(server, req, res, callback) { res = {}; } - var port = 5555, + var port = 0, // let the OS to choose a free port host = '127.0.0.1'; - var listeningAttempts = 0; - var listener; - function listen() { - 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); - } + var listener = server.listen(port, host); + listener.on('error', callback); + listener.on('listening', function onServerListening () { + // jshint maxcomplexity:9 + const { address: host, port } = listener.address(); + const address = `${host}:${port}`; - listen(); - - // jshint maxcomplexity:9 - function onServerListening() { var requestParams = { - url: 'http://' + host + ':' + port + req.url, + url: 'http://' + address + req.url, method: req.method || 'GET', headers: req.headers || {}, timeout: req.timeout || 0, @@ -122,14 +110,17 @@ assert.response = function(server, req, res, callback) { } 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; var err = validateResponse(response, res); return callback(response, err); }); }); - - } + }); }; function validateResponseBody(response, expected) { diff --git a/test/support/test_helper.js b/test/support/test_helper.js index a538c7a7..48c764a4 100644 --- a/test/support/test_helper.js +++ b/test/support/test_helper.js @@ -12,7 +12,6 @@ var LZMA = require('lzma').LZMA; var lzmaWorker = new LZMA(); var redis = require('redis'); -var nock = require('nock'); var log4js = require('log4js'); var pg = require('pg'); 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 afterEach(function(done) { - // restoring nock globally after each suite - nock.cleanAll(); - nock.enableNetConnect(); - var expectedKeys = { 'rails:test_windshaft_cartodb_user_1_db:test_table_private_1': true, 'rails:test_windshaft_cartodb_user_1_db:my_table': true, @@ -223,4 +218,3 @@ module.exports = { configureMetadata, cleanPGPoolConnections }; -