Skip to content

Commit

Permalink
Rework the use of temporary files in the regression tests scenarios. …
Browse files Browse the repository at this point in the history
…Use subdirectories in /tmp that hold the PGVER number so that several tests for several PG versions could be run in parallel. Systematically create and remove the temporary directory in each test script. Use environment variables for executed shell commands, and psql variables for SQL statements.
  • Loading branch information
beaud76 committed Jul 5, 2020
1 parent ca78acb commit de37550
Show file tree
Hide file tree
Showing 63 changed files with 4,054 additions and 3,939 deletions.
4 changes: 2 additions & 2 deletions test/10/expected/adm1.out
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ select emaj.emaj_start_group('myGroup1','M1');

delete from emaj.emaj_param where param_key = 'history_retention';
-- try to generate a sql script for 2 and 3 groups with a mix of groups with or without marks
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'],NULL,'EMAJ_LAST_MARK','/tmp/tmp');
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'],NULL,'EMAJ_LAST_MARK','/dev/null');
ERROR: _check_marks_range: The group "myGroup2" has no mark.
CONTEXT: PL/pgSQL function emaj._check_marks_range(text[],text,text) line 25 at RAISE
SQL statement "SELECT * FROM emaj._check_marks_range(v_groupNames, v_firstMark, v_lastMark)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 42 at SQL statement
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2','emptyGroup'],NULL,'EMAJ_LAST_MARK','/tmp/tmp');
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2','emptyGroup'],NULL,'EMAJ_LAST_MARK','/dev/null');
ERROR: _check_marks_range: The groups "emptyGroup, myGroup2" have no mark.
CONTEXT: PL/pgSQL function emaj._check_marks_range(text[],text,text) line 27 at RAISE
SQL statement "SELECT * FROM emaj._check_marks_range(v_groupNames, v_firstMark, v_lastMark)"
Expand Down
74 changes: 40 additions & 34 deletions test/10/expected/adm2.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
-- adm2.sql : complex scenario executed by an emaj_adm role.
-- Follows adm1.sql, and includes more specific test cases
--
-- define and create the temp file directory to be used by the script
\setenv EMAJTESTTMPDIR '/tmp/emaj_'`echo $PGVER`'/adm2'
\set EMAJTESTTMPDIR `echo $EMAJTESTTMPDIR`
\! mkdir -p $EMAJTESTTMPDIR
set role emaj_regression_tests_adm_user;
-- before going on, save and reload parameters
select emaj.emaj_import_parameters_configuration(emaj.emaj_export_parameters_configuration());
Expand Down Expand Up @@ -1165,29 +1169,28 @@ delete from mytbl1 where col13 = E'A\\000B'::BYTEA;
reset role;
alter sequence myschema2.myseq1 minvalue 1 maxvalue 100 increment 10 start 21 restart 11 cache 2 cycle;
set role emaj_regression_tests_adm_user;
-- reset directory for snaps
\! rm -Rf /tmp/emaj_test/snaps
\! mkdir -p /tmp/emaj_test/snaps
-- create the directory for the first snaps set
\! mkdir -p $EMAJTESTTMPDIR/snaps1
-- ... and snap the all groups
select emaj.emaj_snap_group('myGroup1','/tmp/emaj_test/snaps','CSV HEADER');
select emaj.emaj_snap_group('myGroup1',:'EMAJTESTTMPDIR' || '/snaps1','CSV HEADER');
emaj_snap_group
-----------------
7
(1 row)

select emaj.emaj_snap_group('myGroup2','/tmp/emaj_test/snaps','CSV HEADER');
select emaj.emaj_snap_group('myGroup2',:'EMAJTESTTMPDIR' || '/snaps1','CSV HEADER');
emaj_snap_group
-----------------
8
(1 row)

select emaj.emaj_snap_group('phil''s group#3",','/tmp/emaj_test/snaps','CSV HEADER');
select emaj.emaj_snap_group('phil''s group#3",',:'EMAJTESTTMPDIR' || '/snaps1','CSV HEADER');
emaj_snap_group
-----------------
4
(1 row)

\! ls /tmp/emaj_test/snaps
\! ls $EMAJTESTTMPDIR/snaps1
_INFO
myschema1_myTbl3.snap
myschema1_myTbl3_col31_seq.snap
Expand All @@ -1208,11 +1211,8 @@ phil's_schema3_myTbl2_.snap
phil's_schema3_myTbl2__col21_seq.snap
phil's_schema3_phil's_seq_1.snap
phil's_schema3_phil's_tbl1.snap
-- reset directory for emaj_gen_sql_group tests
\! rm -Rf /tmp/emaj_test/sql_scripts
\! mkdir /tmp/emaj_test/sql_scripts
-- generate a sql script for each active group (and check the result with detailed log statistics + number of sequences)
select emaj.emaj_gen_sql_group('myGroup1', 'Multi-1', NULL, '/tmp/emaj_test/sql_scripts/myGroup1.sql');
select emaj.emaj_gen_sql_group('myGroup1', 'Multi-1', NULL, :'EMAJTESTTMPDIR' || '/myGroup1.sql');
NOTICE: table "emaj_temp_script" does not exist, skipping
emaj_gen_sql_group
--------------------
Expand All @@ -1225,7 +1225,7 @@ select coalesce(sum(stat_rows),0) + 2 as check from emaj.emaj_detailed_log_stat_
7
(1 row)

select emaj.emaj_gen_sql_group('myGroup2', 'Multi-1', NULL, '/tmp/emaj_test/sql_scripts/myGroup2.sql', array[
select emaj.emaj_gen_sql_group('myGroup2', 'Multi-1', NULL, :'EMAJTESTTMPDIR' || '/myGroup2.sql', array[
'myschema2.mytbl1','myschema2.mytbl2','myschema2.myTbl3','myschema2.mytbl4',
'myschema2.mytbl5','myschema2.mytbl6','myschema2.myseq1','myschema2.myTbl3_col31_seq']);
NOTICE: table "emaj_temp_script" does not exist, skipping
Expand All @@ -1240,7 +1240,7 @@ select sum(stat_rows) + 2 as check from emaj.emaj_detailed_log_stat_group('myGro
27
(1 row)

select emaj.emaj_gen_sql_group('phil''s group#3",', 'M1_rollbackable', NULL, '/tmp/emaj_test/sql_scripts/Group3.sql');
select emaj.emaj_gen_sql_group('phil''s group#3",', 'M1_rollbackable', NULL, :'EMAJTESTTMPDIR' || '/Group3.sql');
NOTICE: table "emaj_temp_script" does not exist, skipping
emaj_gen_sql_group
--------------------
Expand All @@ -1261,17 +1261,18 @@ NOTICE: table "emaj_temp_script" does not exist, skipping
6
(1 row)

\copy (select * from emaj_sql_script) to '/tmp/emaj_test/sql_scripts/myGroup1_2.sql'
\setenv FILE1 :EMAJTESTTMPDIR'/myGroup1_2.sql'
\copy (select * from emaj_sql_script) to program 'cat >$FILE1'
-- mask timestamp in initial comment and compare
\! find /tmp/emaj_test/sql_scripts -name '*.sql' -type f -print0 | xargs -0 sed -i -s 's/at .*$/at [ts]$/'
\! diff /tmp/emaj_test/sql_scripts/myGroup1.sql /tmp/emaj_test/sql_scripts/myGroup1_2.sql
\! find $EMAJTESTTMPDIR -name '*.sql' -type f -print0 | xargs -0 sed -i -s 's/at .*$/at [ts]$/'
\! diff $EMAJTESTTMPDIR/myGroup1.sql $EMAJTESTTMPDIR/myGroup1_2.sql
-- process \\ characters in script files
\! find /tmp/emaj_test/sql_scripts -name '*.sql' -type f -print0 | xargs -0 sed -i_s -s 's/\\\\/\\/g'
\! find $EMAJTESTTMPDIR -name '*.sql' -type f -print0 | xargs -0 sed -i_s -s 's/\\\\/\\/g'
-- comment transaction commands for the need of the current test
\! find /tmp/emaj_test/sql_scripts -name '*.sql' -type f -print0 | xargs -0 sed -i -s 's/^BEGIN/--BEGIN/;s/^COMMIT/--COMMIT/'
\! find $EMAJTESTTMPDIR -name '*.sql' -type f -print0 | xargs -0 sed -i -s 's/^BEGIN/--BEGIN/;s/^COMMIT/--COMMIT/'
-- mask timestamp in initial comment
\! find /tmp/emaj_test/sql_scripts -name '*.sql' -type f -print0 | xargs -0 sed -i -s 's/at .*$/at [ts]$/'
\! ls /tmp/emaj_test/sql_scripts
\! find $EMAJTESTTMPDIR -name '*.sql' -type f -print0 | xargs -0 sed -i -s 's/at .*$/at [ts]$/'
\! ls $EMAJTESTTMPDIR
Group3.sql
Group3.sql_s
myGroup1.sql
Expand All @@ -1280,9 +1281,9 @@ myGroup1_2.sql
myGroup1_2.sql_s
myGroup2.sql
myGroup2.sql_s
-- reset directory for second set of snaps
\! rm -Rf /tmp/emaj_test/snaps2
\! mkdir /tmp/emaj_test/snaps2
snaps1
-- create the directory for the second snaps set
\! mkdir $EMAJTESTTMPDIR/snaps2
-- in a single transaction and as superuser:
-- rollback groups, replay updates with generated scripts, snap groups again and cancel the transaction
reset role;
Expand All @@ -1308,7 +1309,7 @@ begin;
Notice | 2 sequences processed.
(2 rows)

\! cat /tmp/emaj_test/sql_scripts/myGroup1.sql
\! cat $EMAJTESTTMPDIR/myGroup1.sql
-- SQL script generated by E-Maj at [ts]$
-- for tables group(s): myGroup1
-- processing logs between mark Multi-1 and the current situation
Expand All @@ -1326,7 +1327,8 @@ ALTER SEQUENCE myschema1.mytbl2b_col20_seq RESTART 8;
RESET standard_conforming_strings;
RESET escape_string_warning;
RESET datestyle;
\i /tmp/emaj_test/sql_scripts/myGroup1.sql
\set FILE1 :EMAJTESTTMPDIR '/myGroup1.sql'
\i :FILE1
-- SQL script generated by E-Maj at [ts]$
-- for tables group(s): myGroup1
-- processing logs between mark Multi-1 and the current situation
Expand All @@ -1344,7 +1346,8 @@ ALTER SEQUENCE myschema1.mytbl2b_col20_seq RESTART 8;
RESET standard_conforming_strings;
RESET escape_string_warning;
RESET datestyle;
\i /tmp/emaj_test/sql_scripts/myGroup2.sql
\set FILE2 :EMAJTESTTMPDIR '/myGroup2.sql'
\i :FILE2
-- SQL script generated by E-Maj at [ts]$
-- for tables group(s): myGroup2
-- processing logs between mark Multi-1 and the current situation
Expand Down Expand Up @@ -1383,7 +1386,8 @@ ALTER SEQUENCE myschema2.myseq1 RESTART 11 START 21 INCREMENT 10 MINVALUE 1 MAX
RESET standard_conforming_strings;
RESET escape_string_warning;
RESET datestyle;
\i /tmp/emaj_test/sql_scripts/Group3.sql
\set FILE3 :EMAJTESTTMPDIR '/Group3.sql'
\i :FILE3
-- SQL script generated by E-Maj at [ts]$
-- for tables group(s): phil's group#3",
-- processing logs between mark M1_rollbackable and the current situation
Expand Down Expand Up @@ -1451,38 +1455,38 @@ ALTER SEQUENCE "phil's schema3"."phil's seq\1" RESTART 1002;
RESET standard_conforming_strings;
RESET escape_string_warning;
RESET datestyle;
select emaj.emaj_snap_group('myGroup1','/tmp/emaj_test/snaps2','CSV HEADER');
select emaj.emaj_snap_group('myGroup1',:'EMAJTESTTMPDIR' || '/snaps2','CSV HEADER');
emaj_snap_group
-----------------
7
(1 row)

select emaj.emaj_snap_group('myGroup2','/tmp/emaj_test/snaps2','CSV HEADER');
select emaj.emaj_snap_group('myGroup2',:'EMAJTESTTMPDIR' || '/snaps2','CSV HEADER');
emaj_snap_group
-----------------
8
(1 row)

select emaj.emaj_snap_group('phil''s group#3",','/tmp/emaj_test/snaps2','CSV HEADER');
select emaj.emaj_snap_group('phil''s group#3",',:'EMAJTESTTMPDIR' || '/snaps2','CSV HEADER');
emaj_snap_group
-----------------
4
(1 row)

rollback;
-- mask timestamp in _INFO files
\! sed -i_s -s 's/at .*/at [ts]/' /tmp/emaj_test/snaps/_INFO /tmp/emaj_test/snaps2/_INFO
\! sed -i_s -s 's/at .*/at [ts]/' $EMAJTESTTMPDIR/snaps1/_INFO $EMAJTESTTMPDIR/snaps2/_INFO
-- and compare both snaps sets
-- sequences are detected as different because of :
-- - the effect of RESTART on is_called and next_val attributes
-- - internal log_cnt value being reset
\! diff --exclude _INFO_s /tmp/emaj_test/snaps /tmp/emaj_test/snaps2
diff --exclude _INFO_s /tmp/emaj_test/snaps/myschema1_mytbl2b_col20_seq.snap /tmp/emaj_test/snaps2/myschema1_mytbl2b_col20_seq.snap
\! diff --exclude _INFO_s $EMAJTESTTMPDIR/snaps1 $EMAJTESTTMPDIR/snaps2
diff --exclude _INFO_s /tmp/emaj_10/adm2/snaps1/myschema1_mytbl2b_col20_seq.snap /tmp/emaj_10/adm2/snaps2/myschema1_mytbl2b_col20_seq.snap
2c2
< mytbl2b_col20_seq,7,1,1,2147483647,1,1,f,t
---
> mytbl2b_col20_seq,8,1,1,2147483647,1,1,f,f
diff --exclude _INFO_s /tmp/emaj_test/snaps/phil's_schema3_phil's_seq_1.snap /tmp/emaj_test/snaps2/phil's_schema3_phil's_seq_1.snap
diff --exclude _INFO_s /tmp/emaj_10/adm2/snaps1/phil's_schema3_phil's_seq_1.snap /tmp/emaj_10/adm2/snaps2/phil's_schema3_phil's_seq_1.snap
2c2
< phil's seq\1,1001,1000,1,2000,1000,1,t,t
---
Expand Down Expand Up @@ -2115,3 +2119,5 @@ select * from emaj.emaj_rollback_group('myGroup1','Multi-1',false) order by 1,2;
Notice | 3 / 5 tables effectively processed.
(2 rows)

-- remove the temp directory
\! rm -R $EMAJTESTTMPDIR

0 comments on commit de37550

Please sign in to comment.