migrated to node-varnish, fixed tests, refactor
This commit is contained in:
@@ -32,8 +32,6 @@ tests["get'ing blank style returns default style"] = function(){
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
tests["post'ing no style returns 400 with errors"] = function(){
|
||||
assert.response(server, {
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
@@ -45,8 +43,6 @@ tests["post'ing no style returns 400 with errors"] = function(){
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
tests["post'ing bad style returns 400 with error"] = function(){
|
||||
assert.response(server, {
|
||||
url: '/tiles/my_table3/style',
|
||||
@@ -54,13 +50,11 @@ tests["post'ing bad style returns 400 with error"] = function(){
|
||||
headers: {host: 'vizzuality.localhost.lan', 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
data: querystring.stringify({style: '#my_table3{backgxxxxxround-color:#fff;}'})
|
||||
},{
|
||||
status: 400,
|
||||
status: 500,
|
||||
body: JSON.stringify(['style.mss:1:11 Unrecognized rule: backgxxxxxround-color'])
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
tests["post'ing multiple bad styles returns 400 with error array"] = function(){
|
||||
assert.response(server, {
|
||||
url: '/tiles/my_table4/style',
|
||||
@@ -68,13 +62,11 @@ tests["post'ing multiple bad styles returns 400 with error array"] = function(){
|
||||
headers: {host: 'vizzuality.localhost.lan', 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
data: querystring.stringify({style: '#my_table4{backgxxxxxround-color:#fff;foo:bar}'})
|
||||
},{
|
||||
status: 400,
|
||||
status: 500,
|
||||
body: JSON.stringify([ 'style.mss:1:11 Unrecognized rule: backgxxxxxround-color', 'style.mss:1:38 Unrecognized rule: foo' ])
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
tests["post'ing good style returns 200"] = function(){
|
||||
assert.response(server, {
|
||||
url: '/tiles/my_table5/style',
|
||||
@@ -86,9 +78,6 @@ tests["post'ing good style returns 200"] = function(){
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
tests["post'ing good style returns 200 then getting returns original style"] = function(){
|
||||
var style = '#my_table5{background-color:#fff;}';
|
||||
assert.response(server, {
|
||||
@@ -111,7 +100,6 @@ tests["post'ing good style returns 200 then getting returns original style"] = f
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
tests["get'ing blank infowindow returns blank"] = function(){
|
||||
assert.response(server, {
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
@@ -135,9 +123,6 @@ tests["get'ing blank infowindow with callback returns blank with callback"] = fu
|
||||
};
|
||||
|
||||
|
||||
// note requires:
|
||||
// SELECT 0
|
||||
// HSET rails:cartodb_user_123_db:my_table infowindow "this, that, the other"
|
||||
tests["get'ing completed infowindow with callback returns information with callback"] = function(){
|
||||
assert.response(server, {
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
@@ -172,9 +157,8 @@ tests["get'ing a json with default style should return an grid"] = function(){
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
tests["get'ing a json with default style and sql should return a constrained grid"] = function(){
|
||||
var sql = querystring.stringify({sql: "(SELECT * FROM gadm4 WHERE name_2 = 'Murcia') as foo"})
|
||||
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08'"})
|
||||
assert.response(server, {
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
url: '/tiles/gadm4/6/31/24.grid.json?' + sql,
|
||||
@@ -186,9 +170,8 @@ tests["get'ing a json with default style and sql should return a constrained gri
|
||||
};
|
||||
|
||||
|
||||
|
||||
tests["get'ing a tile with default style and sql should return a constrained image"] = function(){
|
||||
var sql = querystring.stringify({sql: "(SELECT * FROM gadm4 WHERE name_2 = 'Murcia') as foo"});
|
||||
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08'"});
|
||||
assert.response(server, {
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
url: '/tiles/gadm4/6/31/24.png?' + sql,
|
||||
@@ -201,7 +184,7 @@ tests["get'ing a tile with default style and sql should return a constrained ima
|
||||
|
||||
|
||||
tests["get'ing a tile with default style and complex sql should return a constrained image"] = function(){
|
||||
var sql = querystring.stringify({sql: "(SELECT * FROM gadm4 WHERE name_2 = 'Murcia' AND id_1 > 950) as foo"})
|
||||
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08' AND codccaa > 60"})
|
||||
assert.response(server, {
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
url: '/tiles/gadm4/6/31/24.png?' + sql,
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
var assert = require('assert');
|
||||
var net = require('net');
|
||||
require(__dirname + '/../test_helper');
|
||||
var varnish = require(__dirname + '/../../lib/cartodb/varnish');
|
||||
var tests = module.exports = {};
|
||||
|
||||
function VarnishEmu(on_cmd_recieved, port) {
|
||||
var self = this;
|
||||
var welcome_msg = 'hi, im a varnish emu, right?';
|
||||
|
||||
self.commands_recieved = [];
|
||||
|
||||
var sockets = [];
|
||||
var server = net.createServer(function (socket) {
|
||||
var command = '';
|
||||
socket.write("200 " + welcome_msg.length + "\n");
|
||||
socket.write(welcome_msg);
|
||||
socket.on('data', function(data) {
|
||||
self.commands_recieved.push(data);
|
||||
server.commands++;
|
||||
on_cmd_recieved && on_cmd_recieved(self.commands_recieved);
|
||||
socket.write('200 0\n');
|
||||
});
|
||||
sockets.push(socket);
|
||||
});
|
||||
server.commands = 0;
|
||||
server.listen(port || 0, "127.0.0.1");
|
||||
server.close_connections = function() {
|
||||
for(var s in sockets) {
|
||||
sockets[s].end();
|
||||
}
|
||||
};
|
||||
return server;
|
||||
}
|
||||
|
||||
tests['ok'] = function() {
|
||||
assert.ok(true);
|
||||
};
|
||||
|
||||
tests['should connect'] = function() {
|
||||
var ok = false;
|
||||
var server = VarnishEmu();
|
||||
server.on('listening', function() {
|
||||
var client = new varnish.VarnishClient('127.0.0.1', server.address().port);
|
||||
client.on('connect', function() {
|
||||
ok = true;
|
||||
});
|
||||
});
|
||||
setTimeout(function() { assert.ok(ok);
|
||||
server.close();
|
||||
}, 200);
|
||||
};
|
||||
|
||||
tests['should send a command'] = function() {
|
||||
var ok = false;
|
||||
var server = VarnishEmu(function() {
|
||||
ok = true;
|
||||
});
|
||||
server.on('listening', function() {
|
||||
var client = new varnish.VarnishClient('127.0.0.1', server.address().port);
|
||||
client.on('ready', function() {
|
||||
client.run_cmd('purge obj.http.X == test', function(){});
|
||||
});
|
||||
});
|
||||
setTimeout(function() { assert.ok(ok); }, 100);
|
||||
}
|
||||
|
||||
tests['should emit close on server disconect'] = function() {
|
||||
var ok = false;
|
||||
var server = VarnishEmu();
|
||||
server.on('listening', function() {
|
||||
var client = new varnish.VarnishClient('127.0.0.1', server.address().port);
|
||||
client.on('ready', function() {
|
||||
client.on('close', function() { ok = true; });
|
||||
server.close_connections();
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
setTimeout(function() { assert.ok(ok); }, 300);
|
||||
}
|
||||
|
||||
tests['should emit response on command'] = function() {
|
||||
var ok = false;
|
||||
var server = VarnishEmu()
|
||||
server.on('listening', function() {
|
||||
var client = new varnish.VarnishClient('127.0.0.1', server.address().port);
|
||||
client.on('ready', function() {
|
||||
client.run_cmd('purge obj.http.X == test', function(){});
|
||||
client.on('response', function(code, body) {
|
||||
ok = true;
|
||||
assert.equal(200, code);
|
||||
});
|
||||
});
|
||||
});
|
||||
setTimeout(function() { assert.ok(ok); }, 100);
|
||||
}
|
||||
|
||||
tests['should emit error when the user tries to send when thereis a pending command'] = function() {
|
||||
var ok = false;
|
||||
var server = VarnishEmu()
|
||||
server.on('listening', function() {
|
||||
var client = new varnish.VarnishClient('127.0.0.1', server.address().port);
|
||||
client.on('ready', function() {
|
||||
client.run_cmd('purge obj.http.X == test', function(){});
|
||||
client.on('error', function(e) {
|
||||
ok = true;
|
||||
assert.equal('RESPONSE_PENDING', e.code);
|
||||
});
|
||||
client.run_cmd('purge obj.http.X == test', function(){});
|
||||
});
|
||||
});
|
||||
setTimeout(function() { assert.ok(ok); }, 100);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// queue
|
||||
//
|
||||
|
||||
tests['should send command'] = function() {
|
||||
var server = VarnishEmu()
|
||||
server.on('listening', function() {
|
||||
var queue = new varnish.VarnishQueue('127.0.0.1', server.address().port);
|
||||
for(var i = 0; i < 5; ++i) {
|
||||
queue.run_cmd('purge simon_is == gay');
|
||||
}
|
||||
});
|
||||
setTimeout(function() { assert.equal(5, server.commands); }, 100);
|
||||
}
|
||||
|
||||
tests['should send commands on connect'] = function() {
|
||||
// first create queue
|
||||
var queue = new varnish.VarnishQueue('127.0.0.1', 1234)
|
||||
for(var i = 0; i < 10; ++i) {
|
||||
queue.run_cmd('purge simon_is == gay');
|
||||
}
|
||||
// then server
|
||||
var server = VarnishEmu(null, 1234)
|
||||
//wait 2 seconds because the client tries every second the reconnection
|
||||
setTimeout(function() { assert.equal(10, server.commands); }, 2000);
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,16 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
# this script prepare database and redis instance to run accpetance test
|
||||
# Note: requires a postgis template called template_postgis
|
||||
|
||||
echo "preparing redis..."
|
||||
echo "HSET rails:users:vizzuality id 1" | redis-cli -n 5
|
||||
echo "HSET rails:users:vizzuality database_name cartodb_test_user_1_db" | redis-cli -n 5
|
||||
echo 'HSET rails:cartodb_test_user_1_db:my_table infowindow "this, that, the other"' | redis-cli -n 0
|
||||
|
||||
echo "preparing postgres..."
|
||||
dropdb -Upostgres -hlocalhost cartodb_test_user_1_db
|
||||
createdb -Upostgres -hlocalhost -Ttemplate_postgis -Opostgres -EUTF8 cartodb_test_user_1_db
|
||||
psql -Upostgres -hlocalhost cartodb_test_user_1_db < windshaft.test.sql
|
||||
|
||||
echo "ok, you can run test now"
|
||||
|
||||
psql -Upostgres -hlocalhost cartodb_test_user_1_db < ./sql/windshaft.test.sql
|
||||
psql -Upostgres -hlocalhost cartodb_test_user_1_db < ./sql/gadm4.sql
|
||||
|
||||
echo "Finished preparing data. Run tests with expresso."
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +1,7 @@
|
||||
--
|
||||
-- Windshaft test database
|
||||
--
|
||||
-- To use:
|
||||
--
|
||||
-- > dropdb -Upostgres -hlocalhost windshaft_test
|
||||
-- > createdb -Upostgres -hlocalhost -Ttemplate_postgis -Opostgres -EUTF8 windshaft_test
|
||||
-- > psql -Upostgres -hlocalhost windshaft_test < windshaft.test.sql
|
||||
--
|
||||
-- To use run ../prepare_db.sh
|
||||
-- NOTE: requires a postgis template called template_postgis
|
||||
--
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
|
||||
var assert = require('assert')
|
||||
, _ = require('underscore')
|
||||
, TTL = require('../../../lib/cartodb/ttl')
|
||||
, tests = module.exports = {};
|
||||
|
||||
|
||||
tests['all ok'] = function() {
|
||||
assert.ok(true, "ok");
|
||||
}
|
||||
|
||||
tests['should timeout'] = function() {
|
||||
var called = false;
|
||||
var ttl = TTL(function() {
|
||||
called = true;
|
||||
}, 0.1);
|
||||
ttl.start('test');
|
||||
setTimeout(function() {
|
||||
assert.ok(called === true, "called");
|
||||
}, 200);
|
||||
}
|
||||
|
||||
tests['should remove timeout'] = function() {
|
||||
var called = false;
|
||||
var ttl = TTL(function() {
|
||||
called = true;
|
||||
}, 0.1);
|
||||
ttl.start('test');
|
||||
ttl.remove('test');
|
||||
setTimeout(function() {
|
||||
assert.ok(called === false, "removed");
|
||||
}, 200);
|
||||
}
|
||||
|
||||
tests['should renew timeout time'] = function() {
|
||||
var called = false;
|
||||
var ttl = TTL(function() {
|
||||
called = true;
|
||||
}, 0.3);
|
||||
ttl.start('test');
|
||||
setTimeout(function() {
|
||||
ttl.start('test');
|
||||
}, 0.5);
|
||||
setTimeout(function() {
|
||||
assert.ok(called === false, "removed");
|
||||
}, 300);
|
||||
setTimeout(function() {
|
||||
assert.ok(called === true, "removed");
|
||||
}, 600);
|
||||
}
|
||||
Reference in New Issue
Block a user