From 26b489dd862e2d0ceba426ff9cfaa3b5a3f85560 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:11:00 -0500 Subject: [PATCH 01/14] Add dump tests --- sql/object_reference.sql | 14 ++--- test/dump/load_all.sql | 101 +++++++++++++++++++++++++++++++++- test/dump/run.sh | 28 ++++++---- test/dump/verify.sql | 86 ++++++++++++++++++++++++++--- test/expected/zzz_build.out | 8 ++- test/helpers/object_table.sql | 17 ++++-- test/sql/capture.sql | 2 +- 7 files changed, 217 insertions(+), 39 deletions(-) diff --git a/sql/object_reference.sql b/sql/object_reference.sql index c267abe..cfbae74 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -187,6 +187,7 @@ CREATE TABLE _object_reference.object( */ ); SELECT __object_reference.safe_dump('_object_reference.object'); +SELECT __object_reference.safe_dump('_object_reference.object_object_id_seq'); GRANT REFERENCES ON _object_reference.object TO object_reference__dependency; CREATE TABLE _object_reference._object_oid( @@ -356,7 +357,7 @@ BEGIN IF object_type IS NULL THEN -- Should definitely exist SELECT INTO STRICT object_type, classid, objid, objsubid - o.object_type, a.classid, a.objid, a.subobjid + o.object_type, a.classid, a.objid, a.objsubid FROM _object_reference.object o , pg_catalog.pg_get_object_address(o.object_type::text, o.object_names, o.object_args) a WHERE o.object_id = _object_oid__add.object_id @@ -1365,6 +1366,8 @@ BEGIN USING HINT = 'Did you not start a transaction? Did you forget to call object_reference.capture__stop()?' ; END IF; + + RETURN NULL; END $body$ , 'Trigger function to ensure capture__stop() is called an appropriate number of times.' @@ -1508,15 +1511,6 @@ $body$ , 'Event trigger function to drop object records when objects are removed.' ); -/* -CREATE OR REPLACE FUNCTION snitch() RETURNS event_trigger AS $$ -BEGIN - RAISE WARNING 'snitch: % %', tg_event, tg_tag; -END; -$$ LANGUAGE plpgsql; -CREATE EVENT TRIGGER snitch ON ddl_command_start EXECUTE PROCEDURE snitch(); -*/ - CREATE EVENT TRIGGER zzz__object_reference_drop ON sql_drop -- For debugging diff --git a/test/dump/load_all.sql b/test/dump/load_all.sql index bd747a6..5b73421 100644 --- a/test/dump/load_all.sql +++ b/test/dump/load_all.sql @@ -8,12 +8,12 @@ CREATE SCHEMA test_support; SET search_path = test_support, tap, public; - \i test/helpers/object_table.sql CREATE SCHEMA test_objects; -- THIS NEEDS TO FAIL IF THE SCHEMA EXISTS! SET search_path=test_objects, test_support, tap, public; + SELECT plan( ( 0 @@ -23,8 +23,21 @@ SELECT plan( ( + c -- register + c -- verify + /* + * Capture stuff + */ + + (SELECT count(*) FROM test_prereq) + + 1 -- Create group + + + (SELECT count(*) FROM test_prereq) + + c -- create + + --+ c -- register + + cna + 1 -- verify + )::int ) - FROM (SELECT count(*) c FROM test_object) c + FROM (SELECT count(*) c, count(CASE WHEN create_command NOT LIKE 'ALTER%' THEN 1 END) AS cna + FROM test_object) c ; SELECT lives_ok( @@ -41,8 +54,90 @@ SELECT c.* FROM test_object o, test__verify(o) c ORDER BY o.seq ASC; --SET client_min_messages = DEBUG; --\i test/pgxntool/finish.sql + +CREATE SCHEMA test_capture_support; +SET search_path = test_capture_support, tap, public; + +/* + * Create table to remember our object group. NOTE: make sure to do this in the + * test_capture_support schema! + */ +CREATE TABLE object_group_ids(n int, object_group_id int); +CREATE VIEW og_o AS + SELECT n, ogo.* + FROM _object_reference.object_group__object ogo + JOIN object_group_ids ogi USING(object_group_id) +; + +\i test/helpers/object_table.sql + +/* + * Now, test creating objects via capture__start() + */ +CREATE SCHEMA test_capture; -- THIS NEEDS TO FAIL IF THE SCHEMA EXISTS! +SET search_path=test_capture, test_capture_support, tap, public; + +-- Run prereqs +SELECT lives_ok( + command + , 'prereq: ' || command + ) + FROM test_prereq +; + +-- Create groups +SELECT lives_ok( + format( + $$INSERT INTO object_group_ids VALUES( + %1$s + , object_reference.object_group__create('object capture test group %1$s') + ) + $$ + , n + ) + , format('Create "object capture test group %s"', n) +) FROM generate_series(1,2) n(n); + +-- Start capture +SELECT is( + object_reference.capture__start('object capture test group 1') + , 1 -- Next level # + , 'Start capture for group 1' +); +SELECT is_empty( + $$SELECT * FROM og_o$$ + , 'No objects exist for either test group' +); + +-- Create +SELECT c.* FROM test_object o, test__create(o) c ORDER BY o.seq ASC; + +-- Stop group 1 +SELECT lives_ok( + $$SELECT object_reference.capture__stop('object capture test group 1')$$ + , 'Stop capture group 1' +); + +-- Verify #1 +SELECT is( + (SELECT count(*) FROM og_o WHERE n=1) + , (SELECT count(*) FROM test_object + WHERE create_command NOT LIKE 'ALTER%' + ) + , 'Correct # of objects captured to group.' +); +SELECT c.* + FROM test_object o, test__register(o) c + WHERE create_command NOT LIKE 'ALTER%' + ORDER BY o.seq +; +SELECT bag_eq( + $$SELECT object_id FROM og_o WHERE n = 1$$ + , $$SELECT object_id FROM obj_ref$$ + , 'Verify captured object IDs match' +); + SELECT finish(); COMMIT; -- vi: expandtab sw=2 ts=2 - diff --git a/test/dump/run.sh b/test/dump/run.sh index 9e1bbed..3889f20 100755 --- a/test/dump/run.sh +++ b/test/dump/run.sh @@ -23,23 +23,31 @@ if [ "$1" == "-f" ]; then fi echo Creating dump database -createdb test_dump && psql -f test/dump/load_all.sql test_dump > $create_log || die 3 "Unable to dump database" +createdb test_dump && psql -f test/dump/load_all.sql test_dump > $create_log || die 3 "Unable to create dump database" + +# Ensure no errors in log +check_log() { + file=$1 + step=$2 + + test=`tail -n +2 $file | egrep -v '^ok ' | head -n1` + if [ -n "$test" ]; then + cat $file + #echo "x${test}x" + die 11 "Errors during $step" + fi +} + +check_log $create_log creation echo Running dump and restore +# No real need to cat the log on failure here; psql will generate an error and even if not verify will almost certainly catch it createdb test_load && (echo 'BEGIN;' && pg_dump test_dump && echo 'COMMIT;') | psql -q -v VERBOSITY=verbose -v ON_ERROR_STOP=true test_load > $restore_log || die 4 "Unable to load database" echo Verifying restore psql -f test/dump/verify.sql test_load > $verify_log || die 5 "Test failed" -rc=0 - -if grep -q '^not ok ' $verify_log; then - cat $verify_log - exit 8 -elif grep -q 'Looks like you planned' $verify_log; then - grep 'Looks like you planned' $verify_log - exit 9 -fi +check_log $create_log verify echo Dropping databases drop diff --git a/test/dump/verify.sql b/test/dump/verify.sql index dac366b..c074bc4 100644 --- a/test/dump/verify.sql +++ b/test/dump/verify.sql @@ -6,24 +6,94 @@ * SEE ALSO sql/all.sql! */ -SET search_path=test_objects, test_support, tap, public; +SET search_path=test_capture, test_capture_support, tap, public; +/* + * NOTE: If you get a 'relation "test_object" does not exist' error that + * probably means you dumped an empty database! + */ +SELECT plan( + 1 -- Verify captured object IDs match -SELECT plan( ( + + ( 0 - + c -- verify + + cna -- test_capture verify + + c * 2 -- test_capture drop + + (SELECT count(*) FROM object_group_ids) + 1 -- drop capture groups + + c * 2 -- test_capture drop #2 + + c -- verify + c * 2 -- drop + )::int + 1 -- verify object table is now empty -)::int ) - FROM (SELECT count(*) c FROM test_object) c +) + FROM (SELECT count(*) c, count(CASE WHEN create_command NOT LIKE 'ALTER%' THEN 1 END) AS cna + FROM test_object) c ; -SELECT c.* FROM test_object o, test__verify(o) c ORDER BY o.seq ASC; - -SET client_min_messages = WARNING; +SET client_min_messages = WARNING; -- Drop is noisy --SET client_min_messages = DEBUG; +SELECT isnt_empty( + 'SELECT * FROM test_capture_support.obj_ref' + , 'obj_ref is not empty' +); +SELECT isnt_empty( + 'SELECT * FROM test_capture_support.og_o WHERE n = 1' + , 'og_o is not empty' +); +SELECT bag_eq( + $$SELECT object_id FROM test_capture_support.og_o WHERE n = 1$$ + , $$SELECT object_id FROM test_capture_support.obj_ref$$ + , 'Verify captured object IDs match' +); + +SELECT c.* + FROM test_capture_support.test_object o, test_capture_support.test__verify(o) c + WHERE create_command NOT LIKE 'ALTER%' + ORDER BY o.seq ASC +; + + +-- First verify that object group prevents drop +-- (see below too) +SELECT c.* + FROM test_capture_support.test_object o + --, test_capture_support.test__drop(o) c + , test_capture_support.test__drop(o, 'object_group__object', 'object_group__object_object_id_fkey') c + WHERE create_command NOT LIKE 'ALTER%' + ORDER BY o.seq DESC -- NEEDS to be DESC! +; + +-- Drop capture groups +SELECT throws_ok( + format( $$SELECT object_reference.object_group__remove(%s, false)$$, n ) + , '23503' + , 'update or delete on table "object_group" violates foreign key constraint "object_group__object_object_group_id_fkey" on table "object_group__object"' + , 'Remove object group 1 should fail' || n +) FROM object_group_ids WHERE n = 1 +; +SELECT lives_ok( + format( $$SELECT object_reference.object_group__remove(%s, true)$$, n ) + , 'Remove object group ' || n +) FROM object_group_ids +; + +-- Drop objects for real this time +-- (see above too) +SELECT c.* + FROM test_capture_support.test_object o + , test_capture_support.test__drop(o) c + --, test_capture_support.test__drop(o, 'object_group__object', 'object_group__object_object_id_fkey') c + WHERE create_command NOT LIKE 'ALTER%' + ORDER BY o.seq DESC -- NEEDS to be DESC! +; + +/* + * Non-capture tests + */ +SET search_path=test_objects, test_support, tap, public; +SELECT c.* FROM test_object o, test__verify(o) c ORDER BY o.seq ASC; SELECT c.* FROM test_object o, test__drop(o) c ORDER BY o.seq DESC; SELECT is_empty( diff --git a/test/expected/zzz_build.out b/test/expected/zzz_build.out index c2f7bc7..fb1c275 100644 --- a/test/expected/zzz_build.out +++ b/test/expected/zzz_build.out @@ -4,13 +4,14 @@ You really, REALLY do NOT want to try and load this via psql!!! psql:test/temp_load.not_sql:188: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:189: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:512: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:513: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! @@ -19,9 +20,10 @@ psql:test/temp_load.not_sql:512: WARNING: I promise you will be sorry if you tr -psql:test/temp_load.not_sql:619: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:626: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:620: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! + +psql:test/temp_load.not_sql:627: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! diff --git a/test/helpers/object_table.sql b/test/helpers/object_table.sql index a2ec508..67f07ee 100644 --- a/test/helpers/object_table.sql +++ b/test/helpers/object_table.sql @@ -101,6 +101,8 @@ $body$; CREATE FUNCTION test__drop( o test_object + , ref_table text = 'obj_ref' + , fkey_name name = 'obj_ref_object_id_fkey' ) RETURNS SETOF text LANGUAGE plpgsql AS $body$ DECLARE c_sql CONSTANT text := test__command_sql(o, 'drop'); @@ -115,13 +117,20 @@ BEGIN RETURN NEXT throws_ok( c_sql , '23503' - , 'update or delete on table "object" violates foreign key constraint "obj_ref_object_id_fkey" on table "obj_ref"' + , format( + 'update or delete on table "object" violates foreign key constraint "%s" on table "%s"' + , fkey_name + , ref_table + ) , 'Drop should fail while reference exists' ); - DELETE FROM obj_ref WHERE seq = o.seq; - - RETURN NEXT lives_ok(c_sql, c_sql); + IF ref_table = 'obj_ref' THEN + DELETE FROM obj_ref WHERE seq = o.seq; + RETURN NEXT lives_ok(c_sql, c_sql); + ELSE + RETURN NEXT skip('ref_table != "obj_ref"'); + END IF; END $body$; diff --git a/test/sql/capture.sql b/test/sql/capture.sql index b44171f..8eb1414 100644 --- a/test/sql/capture.sql +++ b/test/sql/capture.sql @@ -84,7 +84,7 @@ SELECT lives_ok( -- Start capture SELECT is( object_reference.capture__start('TEMP object capture test group 1') - , 1 + , 1 -- Next level # , 'Start capture for group 1' ); SELECT is_empty( From a6824bc53e2f82813307f727a30453c600878d74 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:11:26 -0500 Subject: [PATCH 02/14] Add some helper triggers --- sql/object_reference.sql | 52 +++++++++++++++++++++++++++++++++++++ test/expected/zzz_build.out | 2 ++ 2 files changed, 54 insertions(+) diff --git a/sql/object_reference.sql b/sql/object_reference.sql index cfbae74..e5e50e4 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -1511,6 +1511,58 @@ $body$ , 'Event trigger function to drop object records when objects are removed.' ); +SELECT __object_reference.create_function( + '_object_reference.etg_raise_start' + , '' + , 'event_trigger LANGUAGE plpgsql' + , $body$ +BEGIN + RAISE WARNING 'snitch: % %', tg_event, tg_tag; +END; +$body$ + , $$Event trigger function to report on DDL activity. Example trigger: +CREATE EVENT TRIGGER start + ON ddl_command_start + --WHEN tag IN ( 'ALTER TABLE', 'DROP TABLE' ) + EXECUTE PROCEDURE _object_reference.etg_raise_start() +; +$$); +SELECT __object_reference.create_function( + '_object_reference.etg_raise_drop' + , '' + , 'event_trigger LANGUAGE plpgsql' + , $body$ +DECLARE + r record; +BEGIN + FOR r IN SELECT classid, objid, objsubid, object_type, schema_name, object_identity FROM pg_catalog.pg_event_trigger_dropped_objects() LOOP + RAISE WARNING 'dropped_objects: + classid: % + objid: % + objsubid: % + object_type: % + schema_name: % + object_identity: % + ' + -- :^r" s/\([^ ]\+\):.*/, r.\1/ + , r.classid + , r.objid + , r.objsubid + , r.object_type + , r.schema_name + , r.object_identity + ; + END LOOP; +END; +$body$ + , $$Event trigger function to report on DDL activity. Example trigger: +CREATE EVENT TRIGGER drop + ON sql_drop + --WHEN tag IN ( 'ALTER TABLE', 'DROP TABLE' ) + EXECUTE PROCEDURE _object_reference.etg_raise_drop() +; +$$); + CREATE EVENT TRIGGER zzz__object_reference_drop ON sql_drop -- For debugging diff --git a/test/expected/zzz_build.out b/test/expected/zzz_build.out index fb1c275..fe92660 100644 --- a/test/expected/zzz_build.out +++ b/test/expected/zzz_build.out @@ -45,6 +45,8 @@ psql:test/temp_load.not_sql:627: WARNING: I promise you will be sorry if you tr + + From 12f975f48b5aef8566a71810f81449c8a710ccae Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:11:43 -0500 Subject: [PATCH 03/14] Add travis support --- .travis.yml | 12 ++++++++++++ pg-travis-test.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .travis.yml create mode 100644 pg-travis-test.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f0713e5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: c +before_install: + - wget https://gist.github.com/petere/5893799/raw/apt.postgresql.org.sh + - sudo sh ./apt.postgresql.org.sh + - sudo sh -c "echo deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs 2>/dev/null)-pgdg main $PGVERSION >> /etc/apt/sources.list.d/pgdg.list" +env: + - PGVERSION=9.6 + - PGVERSION=9.5 + - PGVERSION=9.4 + - PGVERSION=9.3 + - PGVERSION=9.2 +script: bash ./pg-travis-test.sh diff --git a/pg-travis-test.sh b/pg-travis-test.sh new file mode 100644 index 0000000..6b9964b --- /dev/null +++ b/pg-travis-test.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Based on https://gist.github.com/petere/6023944 + +set -eux + +sudo apt-get update + +packages="python-setuptools postgresql-$PGVERSION postgresql-server-dev-$PGVERSION postgresql-common" + +# bug: http://www.postgresql.org/message-id/20130508192711.GA9243@msgid.df7cb.de +sudo update-alternatives --remove-all postmaster.1.gz + +# stop all existing instances (because of https://github.com/travis-ci/travis-cookbooks/pull/221) +sudo service postgresql stop +# and make sure they don't come back +echo 'exit 0' | sudo tee /etc/init.d/postgresql +sudo chmod a+x /etc/init.d/postgresql + +sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install $packages + +sudo easy_install pgxnclient + +PGPORT=55435 +sudo pg_createcluster --start $PGVERSION test -p $PGPORT -- -A trust +# TODO: have base.mk support dynamic sudo +sudo PGPORT=$PGPORT PGUSER=postgres PG_CONFIG=/usr/lib/postgresql/$PGVERSION/bin/pg_config make test + +[ ! -e test/regression.diffs ] From 91592bbd4ccef386fe8bc41df19952adc17eae0e Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:24:41 -0500 Subject: [PATCH 04/14] Looks like the script actually depends on bash --- test/dump/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dump/run.sh b/test/dump/run.sh index 3889f20..8890a13 100755 --- a/test/dump/run.sh +++ b/test/dump/run.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash DIR=test/dump create_log=$DIR/create.log From 6bbf732c99760b055418151b40e8cc6f71e8c2b9 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:25:20 -0500 Subject: [PATCH 05/14] Add object name to dropped object output --- sql/object_reference.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/object_reference.sql b/sql/object_reference.sql index e5e50e4..a91a585 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -1535,13 +1535,14 @@ SELECT __object_reference.create_function( DECLARE r record; BEGIN - FOR r IN SELECT classid, objid, objsubid, object_type, schema_name, object_identity FROM pg_catalog.pg_event_trigger_dropped_objects() LOOP + FOR r IN SELECT classid, objid, objsubid, object_type, schema_name, object_name, object_identity FROM pg_catalog.pg_event_trigger_dropped_objects() LOOP RAISE WARNING 'dropped_objects: classid: % objid: % objsubid: % object_type: % schema_name: % + object_name: % object_identity: % ' -- :^r" s/\([^ ]\+\):.*/, r.\1/ @@ -1550,6 +1551,7 @@ BEGIN , r.objsubid , r.object_type , r.schema_name + , r.object_name , r.object_identity ; END LOOP; From db02f6fbeb884cd152c43538dd704a36b1467fac Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:26:14 -0500 Subject: [PATCH 06/14] Fix etg_raise_start output --- sql/object_reference.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/object_reference.sql b/sql/object_reference.sql index a91a585..e04ca70 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -1517,7 +1517,7 @@ SELECT __object_reference.create_function( , 'event_trigger LANGUAGE plpgsql' , $body$ BEGIN - RAISE WARNING 'snitch: % %', tg_event, tg_tag; + RAISE WARNING 'etg_raise_start: % %', tg_event, tg_tag; END; $body$ , $$Event trigger function to report on DDL activity. Example trigger: From 6b2bd79a25611ee600b5b931c7a6addd05ec6501 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:26:48 -0500 Subject: [PATCH 07/14] Change etg_raise_* names --- sql/object_reference.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sql/object_reference.sql b/sql/object_reference.sql index e04ca70..44dc1c6 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -1512,23 +1512,23 @@ $body$ ); SELECT __object_reference.create_function( - '_object_reference.etg_raise_start' + '_object_reference.etg_raise__start' , '' , 'event_trigger LANGUAGE plpgsql' , $body$ BEGIN - RAISE WARNING 'etg_raise_start: % %', tg_event, tg_tag; + RAISE WARNING 'etg_raise__start: % %', tg_event, tg_tag; END; $body$ , $$Event trigger function to report on DDL activity. Example trigger: CREATE EVENT TRIGGER start ON ddl_command_start --WHEN tag IN ( 'ALTER TABLE', 'DROP TABLE' ) - EXECUTE PROCEDURE _object_reference.etg_raise_start() + EXECUTE PROCEDURE _object_reference.etg_raise__start() ; $$); SELECT __object_reference.create_function( - '_object_reference.etg_raise_drop' + '_object_reference.etg_raise__drop' , '' , 'event_trigger LANGUAGE plpgsql' , $body$ @@ -1561,7 +1561,7 @@ $body$ CREATE EVENT TRIGGER drop ON sql_drop --WHEN tag IN ( 'ALTER TABLE', 'DROP TABLE' ) - EXECUTE PROCEDURE _object_reference.etg_raise_drop() + EXECUTE PROCEDURE _object_reference.etg_raise__drop() ; $$); From 6661ca6d8fdeb1a6514a81f0d5f633e7cea395f8 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 20:52:46 -0500 Subject: [PATCH 08/14] Fix for test script --- pg-travis-test.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pg-travis-test.sh b/pg-travis-test.sh index 6b9964b..61d5416 100644 --- a/pg-travis-test.sh +++ b/pg-travis-test.sh @@ -22,7 +22,9 @@ sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-co sudo easy_install pgxnclient PGPORT=55435 -sudo pg_createcluster --start $PGVERSION test -p $PGPORT -- -A trust +export PGCLUSTER=test +sudo pg_createcluster --start $PGVERSION $PGCLUSTER -p $PGPORT -- -A trust + # TODO: have base.mk support dynamic sudo sudo PGPORT=$PGPORT PGUSER=postgres PG_CONFIG=/usr/lib/postgresql/$PGVERSION/bin/pg_config make test From 39eb3455c8f84e4da33800246708f108f0cb71e2 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 21:43:03 -0500 Subject: [PATCH 09/14] Try to debug travis --- pg-travis-test.sh | 3 +++ test/dump/run.sh | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pg-travis-test.sh b/pg-travis-test.sh index 61d5416..acd403e 100644 --- a/pg-travis-test.sh +++ b/pg-travis-test.sh @@ -23,6 +23,9 @@ sudo easy_install pgxnclient PGPORT=55435 export PGCLUSTER=test +env | grep PG +which pg_dump + sudo pg_createcluster --start $PGVERSION $PGCLUSTER -p $PGPORT -- -A trust # TODO: have base.mk support dynamic sudo diff --git a/test/dump/run.sh b/test/dump/run.sh index 8890a13..a6252cf 100755 --- a/test/dump/run.sh +++ b/test/dump/run.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +env | grep PG +which pg_dump + DIR=test/dump create_log=$DIR/create.log restore_log=$DIR/restore.log From 3cf99ecb3e1e50255333e66b530a481f599f997d Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 21:57:51 -0500 Subject: [PATCH 10/14] More travis debug --- pg-travis-test.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pg-travis-test.sh b/pg-travis-test.sh index acd403e..f63ae43 100644 --- a/pg-travis-test.sh +++ b/pg-travis-test.sh @@ -22,11 +22,13 @@ sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-co sudo easy_install pgxnclient PGPORT=55435 -export PGCLUSTER=test +PGCLUSTER_NAME=test + +export PGCLUSTER=9.6/$PGCLUSTER_NAME env | grep PG which pg_dump -sudo pg_createcluster --start $PGVERSION $PGCLUSTER -p $PGPORT -- -A trust +sudo pg_createcluster --start $PGVERSION $PGCLUSTER_NAME -p $PGPORT -- -A trust # TODO: have base.mk support dynamic sudo sudo PGPORT=$PGPORT PGUSER=postgres PG_CONFIG=/usr/lib/postgresql/$PGVERSION/bin/pg_config make test From 67eab2fe16926c7320abe723d83370c0477c8dc0 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 22:25:06 -0500 Subject: [PATCH 11/14] Kick travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f0713e5..0c4e016 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,5 @@ env: - PGVERSION=9.4 - PGVERSION=9.3 - PGVERSION=9.2 + script: bash ./pg-travis-test.sh From bce84cf209d20168bfed281fb0642ab0712446e3 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 22:36:19 -0500 Subject: [PATCH 12/14] More travis debug --- test/dump/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dump/run.sh b/test/dump/run.sh index a6252cf..d6038c0 100755 --- a/test/dump/run.sh +++ b/test/dump/run.sh @@ -45,7 +45,7 @@ check_log $create_log creation echo Running dump and restore # No real need to cat the log on failure here; psql will generate an error and even if not verify will almost certainly catch it -createdb test_load && (echo 'BEGIN;' && pg_dump test_dump && echo 'COMMIT;') | psql -q -v VERBOSITY=verbose -v ON_ERROR_STOP=true test_load > $restore_log || die 4 "Unable to load database" +createdb test_load && (echo '\df pg_getobject_address' && echo 'BEGIN;' && pg_dump test_dump && echo 'COMMIT;') | psql -q -v VERBOSITY=verbose -v ON_ERROR_STOP=true test_load > $restore_log || die 4 "Unable to load database" echo Verifying restore psql -f test/dump/verify.sql test_load > $verify_log || die 5 "Test failed" From a0bee7486abeb14cebc929f26cd5eaa371b8d53f Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 22:46:43 -0500 Subject: [PATCH 13/14] More travis debug --- test/dump/run.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/dump/run.sh b/test/dump/run.sh index d6038c0..450d753 100755 --- a/test/dump/run.sh +++ b/test/dump/run.sh @@ -45,7 +45,12 @@ check_log $create_log creation echo Running dump and restore # No real need to cat the log on failure here; psql will generate an error and even if not verify will almost certainly catch it -createdb test_load && (echo '\df pg_getobject_address' && echo 'BEGIN;' && pg_dump test_dump && echo 'COMMIT;') | psql -q -v VERBOSITY=verbose -v ON_ERROR_STOP=true test_load > $restore_log || die 4 "Unable to load database" +createdb test_load && psql -c '\df pg_getobject_address' test_load && (echo 'BEGIN;' && pg_dump test_dump && echo 'COMMIT;') | psql -q -v VERBOSITY=verbose -v ON_ERROR_STOP=true test_load > $restore_log +rc=$? +if [ $rc ne 0 ]; then + cat $restore_log + die 4 "Unable to load database" +fi echo Verifying restore psql -f test/dump/verify.sql test_load > $verify_log || die 5 "Test failed" From d191ef1c95bcfe46b5ebbd6afb3234826806f731 Mon Sep 17 00:00:00 2001 From: Jim Nasby Date: Thu, 18 May 2017 22:51:06 -0500 Subject: [PATCH 14/14] More travis debug --- test/dump/run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/dump/run.sh b/test/dump/run.sh index 450d753..4d0c7a3 100755 --- a/test/dump/run.sh +++ b/test/dump/run.sh @@ -45,9 +45,10 @@ check_log $create_log creation echo Running dump and restore # No real need to cat the log on failure here; psql will generate an error and even if not verify will almost certainly catch it -createdb test_load && psql -c '\df pg_getobject_address' test_load && (echo 'BEGIN;' && pg_dump test_dump && echo 'COMMIT;') | psql -q -v VERBOSITY=verbose -v ON_ERROR_STOP=true test_load > $restore_log +createdb test_load && PAGER='' psql -c '\df pg_get_object_address' test_load || die 5 'crap' +(echo 'BEGIN;' && pg_dump test_dump && echo 'COMMIT;') | psql -q -v VERBOSITY=verbose -v ON_ERROR_STOP=true test_load > $restore_log rc=$? -if [ $rc ne 0 ]; then +if [ $rc -ne 0 ]; then cat $restore_log die 4 "Unable to load database" fi