From 1fc0545b5ab48796057e882ddb704ab805e7055f Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 30 Mar 2015 15:57:53 +0200 Subject: [PATCH] Replace affected tables tests with multilayer ones --- test/acceptance/multilayer_server.js | 87 +++++++++++++++++++++++++++- test/acceptance/server.js | 39 +------------ 2 files changed, 87 insertions(+), 39 deletions(-) diff --git a/test/acceptance/multilayer_server.js b/test/acceptance/multilayer_server.js index c39d2903..c7c37de2 100644 --- a/test/acceptance/multilayer_server.js +++ b/test/acceptance/multilayer_server.js @@ -1,10 +1,12 @@ -var testHelper = require(__dirname + '/../support/test_helper'); +var testHelper = require('../support/test_helper'); var assert = require('../support/assert'); var redis = require('redis'); var _ = require('underscore'); + +var QueryTablesApi = require('../../lib/cartodb/api/query_tables_api'); var CartodbWindshaft = require('../../lib/cartodb/cartodb_windshaft'); var serverOptions = require('../../lib/cartodb/server_options')(); var server = new CartodbWindshaft(serverOptions); @@ -30,7 +32,6 @@ describe('tests from old api translated to multilayer', function() { function singleLayergroupConfig(sql, cartocss) { return { - stat_tag: 'random_tag', version: '1.0.0', layers: [ { @@ -250,4 +251,86 @@ describe('tests from old api translated to multilayer', function() { ); }); + it("creates layergroup fails when postgresql queries fail to figure affected tables in query", function(done) { + + var runQueryFn = QueryTablesApi.prototype.runQuery; + QueryTablesApi.prototype.runQuery = function(username, query, queryHandler, callback) { + return callback(new Error('failed to query database for affected tables')); + }; + + var layergroup = singleLayergroupConfig('select * from gadm4', '#gadm4 { marker-fill: red; }'); + + assert.response(server, + { + url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)), + method: 'GET', + headers: { + host: 'localhost' + } + }, + { + status: 400 + }, + function(res) { + QueryTablesApi.prototype.runQuery = runQueryFn; + + assert.ok(!res.headers.hasOwnProperty('x-cache-channel')); + + var parsed = JSON.parse(res.body); + assert.deepEqual(parsed, {"errors":["Error: failed to query database for affected tables"]}); + + done(); + } + ); + }); + + it("tile requests works when postgresql queries fail to figure affected tables in query", function(done) { + var layergroup = singleLayergroupConfig('select * from gadm4', '#gadm4 { marker-fill: red; }'); + assert.response(server, + { + url: layergroupUrl + '?config=' + encodeURIComponent(JSON.stringify(layergroup)), + method: 'GET', + headers: { + host: 'localhost' + } + }, + { + status: 200 + }, + function(res) { + var runQueryFn = QueryTablesApi.prototype.runQuery; + QueryTablesApi.prototype.runQuery = function(username, query, queryHandler, callback) { + return callback(new Error('failed to query database for affected tables')); + }; + + // reset internal cacheChannel cache + serverOptions.channelCache = {}; + + assert.response(server, + { + url: layergroupUrl + _.template('/<%= layergroupId %>/<%= z %>/<%= x %>/<%= y %>.png', { + layergroupId: JSON.parse(res.body).layergroupid, + z: 0, + x: 0, + y: 0 + }), + method: 'GET', + headers: { + host: 'localhost' + }, + encoding: 'binary' + }, + { + status: 200 + }, + function(res) { + assert.ok(!res.headers.hasOwnProperty('x-cache-channel')); + QueryTablesApi.prototype.runQuery = runQueryFn; + done(); + } + ); + } + ); + }); + }); diff --git a/test/acceptance/server.js b/test/acceptance/server.js index dd83de50..ffb32fe4 100644 --- a/test/acceptance/server.js +++ b/test/acceptance/server.js @@ -1,7 +1,6 @@ -require(__dirname + '/../support/test_helper'); +require('../support/test_helper'); var assert = require('../support/assert'); -var _ = require('underscore'); var querystring = require('querystring'); var step = require('step'); @@ -10,7 +9,6 @@ var serverOptions = require('../../lib/cartodb/server_options')(); var server = new CartodbWindshaft(serverOptions); server.setMaxListeners(0); -var cdbQueryTablesFromPostgresEnabledValue = true; suite('server', function() { @@ -61,40 +59,7 @@ suite('server', function() { }); }); -suite.skip('server old_api', function() { - - if (!cdbQueryTablesFromPostgresEnabledValue) { // only test if it was using the SQL API - test("requests to skip cache on sqlapi error", function(done){ - var qo = { - sql: "SELECT g.cartodb_id, g.codineprov, t.the_geom_webmercator, 'SQLAPIERROR' is not null" + - " FROM gadm4 g, test_table t" + - " WHERE g.cartodb_id = t.cartodb_id", - map_key: 1234 - }; - step( - function sendRequest() { - var next = this; - assert.response(server, { - headers: {host: 'localhost'}, - url: '/tiles/gadm4/6/31/24.png?' + querystring.stringify(qo), - method: 'GET' - },{}, function(res) { next(null, res); }); - }, - function checkResponse(err, res) { - if ( err ) throw err; - assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); - var ct = res.headers['content-type']; - assert.equal(ct, 'image/png'); - // does NOT send an x-cache-channel - assert.ok(!res.headers.hasOwnProperty('x-cache-channel')); - return null; - }, - function finish(err) { - done(err); - } - ); - }); - } +suite('server old_api', function() { // See https://github.com/CartoDB/Windshaft-cartodb/issues/115 test.skip("get'ing tile with not-strictly-valid style", function(done) {