fixed tests

This commit is contained in:
javi
2011-10-20 16:44:37 +02:00
parent 3d03d334b3
commit aef709a453
3 changed files with 197 additions and 17 deletions
+30 -17
View File
@@ -16,7 +16,7 @@ var cached_server = new CartodbWindshaft(serverOptions);
tests["first time a tile is request should not be cached"] = function() {
assert.response(cached_server, {
url: '/tiles/gadm4/6/31/24.png?geom_type=polygon',
url: '/tiles/test_table_2/6/31/24.png?geom_type=polygon',
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
@@ -33,17 +33,17 @@ tests["first time a tile is request should not be cached"] = function() {
tests["second time a tile is request should be cached"] = function() {
var cached_server2 = new CartodbWindshaft(serverOptions);
var url= '/tiles/gadm4/6/31/24.png';
var url= '/tiles/test_table_2/6/31/24.png';
assert.response(cached_server2, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
}, function(res) {
assert.response(cached_server2, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
@@ -57,21 +57,21 @@ tests["second time a tile is request should be cached"] = function() {
tests["LRU tile should be removed"] = function() {
var urls = ['/tiles/gadm4/6/31/24.png',
'/tiles/gadm4/6/31/25.png',
'/tiles/gadm4/6/31/26.png',
'/tiles/gadm4/6/31/27.png'];
var urls = ['/tiles/test_table_2/6/31/24.png',
'/tiles/test_table_2/6/31/25.png',
'/tiles/test_table_2/6/31/26.png',
'/tiles/test_table_2/6/31/27.png'];
//create another server to not take previos test stats into account
var so = _.clone(serverOptions);
_(so).extend({lru_cache: true, lru_cache_size: 3});
var so = _.clone(serverOptions);
_(so).extend({lru_cache: true, lru_cache_size: 3});
var _cached_server = new CartodbWindshaft(so);
function makeReq(url, callback) {
assert.response(_cached_server, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
@@ -93,7 +93,7 @@ tests["LRU tile should be removed"] = function() {
}, function() {
assert.response(_cached_server, {
url: urls[0],
headers: {host: 'vizzuality.localhost.lan'},
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
@@ -112,19 +112,19 @@ tests["LRU tile should be removed"] = function() {
tests["cache should be invalidated"] = function() {
var url = '/tiles/gadm4/6/29/27.png';
var url = '/tiles/test_table_2/6/29/27.png';
var cache = CacheValidator(global.environment.redis);
assert.response(cached_server, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
}, function(res) {
cache.setTimestamp('cartodb_dev_user_3_db', 'gadm4', (new Date().getTime()/1000.0)+100, function() {
cache.setTimestamp('windshaft_test', 'test_table_2', (new Date().getTime()/1000.0)+100, function() {
assert.response(cached_server, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
@@ -134,5 +134,18 @@ tests["cache should be invalidated"] = function() {
});
});
}
};
tests["Last-Modified header should be sent"] = function() {
var cached_server2 = new CartodbWindshaft(serverOptions);
var url= '/tiles/test_table_2/6/31/24.png';
assert.response(cached_server2, {
url: url,
headers: {host: 'vizzuality.localhost.lan'},
method: 'GET'
},{
status: 200
}, function(res) {
assert.ok(res.header('Last-Modified') !== undefined);
});
}
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
# this script prepare database and redis instance to run accpetance test
echo "preparing redis..."
echo "HSET rails:users:vizzuality id 1" | redis-cli -n 5
echo "HSET rails:users:vizzuality database_name windshaft" | redis-cli -n 5
echo "preparing postgres..."
dropdb -Upostgres -hlocalhost whindshaft_test
createdb -Upostgres -hlocalhost -Ttemplate_postgis -Opostgres -EUTF8 whindshaft_test
psql -Upostgres -hlocalhost whindshaft_test < test.sql
echo "ok, you can run test now"
+151
View File
@@ -0,0 +1,151 @@
--
-- 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
--
-- NOTE: requires a postgis template called template_postgis
--
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
-- first table
CREATE TABLE test_table (
updated_at timestamp without time zone DEFAULT now(),
created_at timestamp without time zone DEFAULT now(),
cartodb_id integer NOT NULL,
name character varying,
address character varying,
the_geom geometry,
the_geom_webmercator geometry,
CONSTRAINT enforce_dims_the_geom CHECK ((st_ndims(the_geom) = 2)),
CONSTRAINT enforce_dims_the_geom_webmercator CHECK ((st_ndims(the_geom_webmercator) = 2)),
CONSTRAINT enforce_geotype_the_geom CHECK (((geometrytype(the_geom) = 'POINT'::text) OR (the_geom IS NULL))),
CONSTRAINT enforce_geotype_the_geom_webmercator CHECK (((geometrytype(the_geom_webmercator) = 'POINT'::text) OR (the_geom_webmercator IS NULL))),
CONSTRAINT enforce_srid_the_geom CHECK ((st_srid(the_geom) = 4326)),
CONSTRAINT enforce_srid_the_geom_webmercator CHECK ((st_srid(the_geom_webmercator) = 3857))
);
CREATE SEQUENCE test_table_cartodb_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE test_table_cartodb_id_seq OWNED BY test_table.cartodb_id;
SELECT pg_catalog.setval('test_table_cartodb_id_seq', 60, true);
ALTER TABLE test_table ALTER COLUMN cartodb_id SET DEFAULT nextval('test_table_cartodb_id_seq'::regclass);
INSERT INTO test_table VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.314252', 1, 'Hawai', 'Calle de Pérez Galdós 9, Madrid, Spain', '0101000020E6100000A6B73F170D990DC064E8D84125364440', '0101000020110F000076491621312319C122D4663F1DCC5241');
INSERT INTO test_table VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.319101', 2, 'El Estocolmo', 'Calle de la Palma 72, Madrid, Spain', '0101000020E6100000C90567F0F7AB0DC0AB07CC43A6364440', '0101000020110F0000C4356B29423319C15DD1092DADCC5241');
INSERT INTO test_table VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.324', 3, 'El Rey del Tallarín', 'Plaza Conde de Toreno 2, Madrid, Spain', '0101000020E610000021C8410933AD0DC0CB0EF10F5B364440', '0101000020110F000053E71AC64D3419C10F664E4659CC5241');
INSERT INTO test_table VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.329509', 4, 'El Lacón', 'Manuel Fernández y González 8, Madrid, Spain', '0101000020E6100000BC5983F755990DC07D923B6C22354440', '0101000020110F00005DACDB056F2319C1EC41A980FCCA5241');
INSERT INTO test_table VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.334931', 5, 'El Pico', 'Calle Divino Pastor 12, Madrid, Spain', '0101000020E61000003B6D8D08C6A10DC0371B2B31CF364440', '0101000020110F00005F716E91992A19C17DAAA4D6DACC5241');
ALTER TABLE ONLY test_table ADD CONSTRAINT test_table_pkey PRIMARY KEY (cartodb_id);
CREATE INDEX test_table_the_geom_idx ON test_table USING gist (the_geom);
CREATE INDEX test_table_the_geom_webmercator_idx ON test_table USING gist (the_geom_webmercator);
GRANT ALL ON TABLE test_table TO postgres;
-- second table
CREATE TABLE test_table_2 (
updated_at timestamp without time zone DEFAULT now(),
created_at timestamp without time zone DEFAULT now(),
cartodb_id integer NOT NULL,
name character varying,
address character varying,
the_geom geometry,
the_geom_webmercator geometry,
CONSTRAINT enforce_dims_the_geom CHECK ((st_ndims(the_geom) = 2)),
CONSTRAINT enforce_dims_the_geom_webmercator CHECK ((st_ndims(the_geom_webmercator) = 2)),
CONSTRAINT enforce_geotype_the_geom CHECK (((geometrytype(the_geom) = 'POINT'::text) OR (the_geom IS NULL))),
CONSTRAINT enforce_geotype_the_geom_webmercator CHECK (((geometrytype(the_geom_webmercator) = 'POINT'::text) OR (the_geom_webmercator IS NULL))),
CONSTRAINT enforce_srid_the_geom CHECK ((st_srid(the_geom) = 4326)),
CONSTRAINT enforce_srid_the_geom_webmercator CHECK ((st_srid(the_geom_webmercator) = 3857))
);
CREATE SEQUENCE test_table_2_cartodb_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE test_table_2_cartodb_id_seq OWNED BY test_table_2.cartodb_id;
SELECT pg_catalog.setval('test_table_2_cartodb_id_seq', 60, true);
ALTER TABLE test_table_2 ALTER COLUMN cartodb_id SET DEFAULT nextval('test_table_2_cartodb_id_seq'::regclass);
INSERT INTO test_table_2 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.314252', 1, 'Hawai', 'Calle de Pérez Galdós 9, Madrid, Spain', '0101000020E6100000A6B73F170D990DC064E8D84125364440', '0101000020110F000076491621312319C122D4663F1DCC5241');
INSERT INTO test_table_2 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.319101', 2, 'El Estocolmo', 'Calle de la Palma 72, Madrid, Spain', '0101000020E6100000C90567F0F7AB0DC0AB07CC43A6364440', '0101000020110F0000C4356B29423319C15DD1092DADCC5241');
INSERT INTO test_table_2 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.324', 3, 'El Rey del Tallarín', 'Plaza Conde de Toreno 2, Madrid, Spain', '0101000020E610000021C8410933AD0DC0CB0EF10F5B364440', '0101000020110F000053E71AC64D3419C10F664E4659CC5241');
INSERT INTO test_table_2 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.329509', 4, 'El Lacón', 'Manuel Fernández y González 8, Madrid, Spain', '0101000020E6100000BC5983F755990DC07D923B6C22354440', '0101000020110F00005DACDB056F2319C1EC41A980FCCA5241');
INSERT INTO test_table_2 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.334931', 5, 'El Pico', 'Calle Divino Pastor 12, Madrid, Spain', '0101000020E61000003B6D8D08C6A10DC0371B2B31CF364440', '0101000020110F00005F716E91992A19C17DAAA4D6DACC5241');
ALTER TABLE ONLY test_table_2 ADD CONSTRAINT test_table_2_pkey PRIMARY KEY (cartodb_id);
CREATE INDEX test_table_2_the_geom_idx ON test_table_2 USING gist (the_geom);
CREATE INDEX test_table_2_the_geom_webmercator_idx ON test_table_2 USING gist (the_geom_webmercator);
GRANT ALL ON TABLE test_table_2 TO postgres;
-- third table
CREATE TABLE test_table_3 (
updated_at timestamp without time zone DEFAULT now(),
created_at timestamp without time zone DEFAULT now(),
cartodb_id integer NOT NULL,
name character varying,
address character varying,
the_geom geometry,
the_geom_webmercator geometry,
CONSTRAINT enforce_dims_the_geom CHECK ((st_ndims(the_geom) = 2)),
CONSTRAINT enforce_dims_the_geom_webmercator CHECK ((st_ndims(the_geom_webmercator) = 2)),
CONSTRAINT enforce_geotype_the_geom CHECK (((geometrytype(the_geom) = 'POINT'::text) OR (the_geom IS NULL))),
CONSTRAINT enforce_geotype_the_geom_webmercator CHECK (((geometrytype(the_geom_webmercator) = 'POINT'::text) OR (the_geom_webmercator IS NULL))),
CONSTRAINT enforce_srid_the_geom CHECK ((st_srid(the_geom) = 4326)),
CONSTRAINT enforce_srid_the_geom_webmercator CHECK ((st_srid(the_geom_webmercator) = 3857))
);
CREATE SEQUENCE test_table_3_cartodb_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE test_table_3_cartodb_id_seq OWNED BY test_table_3.cartodb_id;
SELECT pg_catalog.setval('test_table_3_cartodb_id_seq', 60, true);
ALTER TABLE test_table_3 ALTER COLUMN cartodb_id SET DEFAULT nextval('test_table_3_cartodb_id_seq'::regclass);
INSERT INTO test_table_3 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.314252', 1, 'Hawai', 'Calle de Pérez Galdós 9, Madrid, Spain', '0101000020E6100000A6B73F170D990DC064E8D84125364440', '0101000020110F000076491621312319C122D4663F1DCC5241');
INSERT INTO test_table_3 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.319101', 2, 'El Estocolmo', 'Calle de la Palma 72, Madrid, Spain', '0101000020E6100000C90567F0F7AB0DC0AB07CC43A6364440', '0101000020110F0000C4356B29423319C15DD1092DADCC5241');
INSERT INTO test_table_3 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.324', 3, 'El Rey del Tallarín', 'Plaza Conde de Toreno 2, Madrid, Spain', '0101000020E610000021C8410933AD0DC0CB0EF10F5B364440', '0101000020110F000053E71AC64D3419C10F664E4659CC5241');
INSERT INTO test_table_3 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.329509', 4, 'El Lacón', 'Manuel Fernández y González 8, Madrid, Spain', '0101000020E6100000BC5983F755990DC07D923B6C22354440', '0101000020110F00005DACDB056F2319C1EC41A980FCCA5241');
INSERT INTO test_table_3 VALUES ('2011-09-21 14:02:21.358706', '2011-09-21 14:02:21.334931', 5, 'El Pico', 'Calle Divino Pastor 12, Madrid, Spain', '0101000020E61000003B6D8D08C6A10DC0371B2B31CF364440', '0101000020110F00005F716E91992A19C17DAAA4D6DACC5241');
ALTER TABLE ONLY test_table_3 ADD CONSTRAINT test_table_3_pkey PRIMARY KEY (cartodb_id);
CREATE INDEX test_table_3_the_geom_idx ON test_table_3 USING gist (the_geom);
CREATE INDEX test_table_3_the_geom_webmercator_idx ON test_table_3 USING gist (the_geom_webmercator);
GRANT ALL ON TABLE test_table_3 TO postgres;