0001-WIP-Add-regression-tests-for-DDL-deparse.patch
application/octet-stream
Filename: 0001-WIP-Add-regression-tests-for-DDL-deparse.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0001
Subject: WIP: Add regression tests for DDL deparse.
| File | + | − |
|---|---|---|
| src/test/modules/test_ddl_deparse/Makefile | 5 | 0 |
| src/test/modules/test_ddl_deparse/t/001_deparse_regress.pl | 135 | 0 |
From 8847e4502a608597e8bb593e251e990c5a9df99f Mon Sep 17 00:00:00 2001
From: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Wed, 22 Jun 2022 14:29:33 +0900
Subject: [PATCH] WIP: Add regression tests for DDL deparse.
---
src/test/modules/test_ddl_deparse/Makefile | 5 +
.../test_ddl_deparse/t/001_deparse_regress.pl | 135 ++++++++++++++++++
2 files changed, 140 insertions(+)
create mode 100644 src/test/modules/test_ddl_deparse/t/001_deparse_regress.pl
diff --git a/src/test/modules/test_ddl_deparse/Makefile b/src/test/modules/test_ddl_deparse/Makefile
index 3a57a95c84..cf047e2ae2 100644
--- a/src/test/modules/test_ddl_deparse/Makefile
+++ b/src/test/modules/test_ddl_deparse/Makefile
@@ -31,6 +31,11 @@ REGRESS = test_ddl_deparse \
EXTRA_INSTALL = contrib/pg_stat_statements
+REGRESS_SHLIB=$(abs_top_builddir)/src/test/regress/regress$(DLSUFFIX)
+export REGRESS_SHLIB
+
+TAP_TESTS = 1
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/src/test/modules/test_ddl_deparse/t/001_deparse_regress.pl b/src/test/modules/test_ddl_deparse/t/001_deparse_regress.pl
new file mode 100644
index 0000000000..5043b3e02c
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/t/001_deparse_regress.pl
@@ -0,0 +1,135 @@
+use strict;
+use warnings;
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+use File::Basename;
+
+my $node1 = PostgreSQL::Test::Cluster->new('main');
+$node1->init;
+
+# Increase some settings that Cluster->new makes too low by default.
+$node1->adjust_conf('postgresql.conf', 'max_connections', '25');
+$node1->append_conf('postgresql.conf',
+ 'max_prepared_transactions = 10');
+
+# Create the event trigger to get deparsed DDLs.
+$node1->start;
+is( $node1->psql('postgres',
+ q(
+begin;
+create table deparsed_ddls(tag text, object_identity text, ddl text);
+
+create or replace function deparse_to_json()
+ returns event_trigger language plpgsql as
+$$
+declare
+ r record;
+begin
+ for r in select * from pg_event_trigger_ddl_commands()
+ loop
+ insert into deparsed_ddls(tag, object_identity, ddl) values (r.command_tag, r.object_identity, pg_catalog.ddl_deparse_to_json(r.command));
+ end loop;
+END;
+$$;
+
+create event trigger ddl_deparse_trig
+on ddl_command_end execute procedure deparse_to_json();
+commit;
+)), 0, 'event trigger created');
+
+my $dlpath = dirname($ENV{REGRESS_SHLIB});
+my $outputdir = $PostgreSQL::Test::Utils::tmp_check;
+
+# Run the regression tests against the main server.
+#
+# FIXME: As the deparsing DDL code is in under development and many DDLs are not
+# supported yet, regression tests againt the main server fails.
+#
+#my $extra_opts = $ENV{EXTRA_REGRESS_OPTS} || "";
+#my $rc =
+# system($ENV{PG_REGRESS}
+# . " $extra_opts "
+# . "--dlpath=\"$dlpath\" "
+# . "--bindir= "
+# . "--host="
+# . $node1->host . " "
+# . "--port="
+# . $node1->port . " "
+# . "--schedule=../../regress/parallel_schedule "
+# . "--use-existing "
+# . "--max-concurrent-tests=20 "
+# . "--inputdir=../../regress "
+# . "--outputdir=\"$outputdir\"");
+#if ($rc != 0)
+#{
+# # Dump out the regression diffs file, if there is one
+# my $diffs = "$outputdir/regression.diffs";
+# if (-e $diffs)
+# {
+# print "=== dumping $diffs ===\n";
+# print slurp_file($diffs);
+# print "=== EOF ===\n";
+# }
+#}
+#
+#is($rc, 0, 'regression tests pass');
+
+# FIXME: temporary tests in lieu of running the regression tests
+$node1->safe_psql(
+ 'postgres',
+ q(
+create table test_tbl (a int, b text, c jsonb);
+alter table test_tbl add column d int;
+alter table test_tbl alter column b type varchar;
+alter table test_tbl alter column a set not null;
+alter table test_tbl drop column d;
+));
+
+# Retrieve the deparsed DDLs.
+my $ddl_sql = '';
+is( $node1->psql(
+ 'postgres',
+ q(select ddl_deparse_expand_command(ddl) || ';' from deparsed_ddls),
+ stdout => \$ddl_sql
+ ), 0, 'dump deparsed DDLs');
+
+# Initialize another database cluster where we load the deparsed DDLs.
+my $node2 = PostgreSQL::Test::Cluster->new('sub');
+$node2->init;
+$node2->start;
+
+# Load the deparsed DDLs.
+$node2->safe_psql('postgres', $ddl_sql);
+
+# Drop the event trigger and the function before taking a logical dump.
+$node1->safe_psql(
+ 'postgres',
+ q(
+drop event trigger ddl_deparse_trig;
+drop function deparse_to_json();
+drop table deparsed_ddls;
+));
+
+# Perform a logical dump of both the main and the sub server, ane check
+# that they match.
+command_ok(
+ [
+ 'pg_dumpall', '-f', $outputdir . '/main.dump',
+ '--no-sync', '-p', $node1->port
+ ],
+ 'dump main server');
+command_ok(
+ [
+ 'pg_dumpall', '-f', $outputdir . '/sub.dump',
+ '--no-sync', '-p', $node2->port
+ ],
+ 'dump main server');
+command_ok(
+ [ 'diff', $outputdir . '/main.dump', $outputdir . '/sub.dump' ],
+ 'compare main and sub dumps');
+
+$node1->stop;
+$node2->stop;
+
+done_testing();
--
2.24.3 (Apple Git-128)