v1_add_test_pg_waldump.patch

application/octet-stream

Filename: v1_add_test_pg_waldump.patch
Type: application/octet-stream
Part: 0
Message: pg_waldump: add test for coverage

Patch

Format: format-patch
Series: patch v1
Subject: pg_waldump: add test for coverage
File+
src/bin/pg_waldump/t/001_basic.pl 39 0
src/bin/pg_waldump/t/002_wal_type.pl 180 0
From f2d9a4c447f4b7a1e51c672aa8269cac6de6a500 Mon Sep 17 00:00:00 2001
From: Lee Dong Wook <sh95119@gmail.com>
Date: Tue, 23 Aug 2022 10:18:58 +0900
Subject: [PATCH] pg_waldump: add test for coverage

---
 src/bin/pg_waldump/t/001_basic.pl    |  39 ++++++
 src/bin/pg_waldump/t/002_wal_type.pl | 180 +++++++++++++++++++++++++++
 2 files changed, 219 insertions(+)
 create mode 100644 src/bin/pg_waldump/t/002_wal_type.pl

diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl
index 883adff8fa13..72f124bfb1f0 100644
--- a/src/bin/pg_waldump/t/001_basic.pl
+++ b/src/bin/pg_waldump/t/001_basic.pl
@@ -3,6 +3,7 @@
 
 use strict;
 use warnings;
+use PostgreSQL::Test::Cluster;
 use PostgreSQL::Test::Utils;
 use Test::More;
 
@@ -10,4 +11,42 @@
 program_version_ok('pg_waldump');
 program_options_handling_ok('pg_waldump');
 
+my $node = PostgreSQL::Test::Cluster->new('main');
+$node->init;
+
+my $wal_dump_path = $node->data_dir . "/pg_wal/000000010000000000000001";
+my ($stdout, $stderr);
+
+# test pg_waldump
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path" ], '>', \$stdout, '2>', \$stderr;
+isnt($stdout, '', "");
+
+# test pg_waldump with -p (path), -s (start), -e (end) options
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-s', '0/0132C160', '-e', '0/018C41A0' ], '>', \$stdout, '2>', \$stderr;
+isnt($stdout, '', "");
+
+# test pg_waldump with -p (path), -s (start), -e (end) options -z (stats)
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-s', '0/0132C160', '-e', '0/018C41A0', '-z' ], '>', \$stdout, '2>', \$stderr;
+isnt($stdout, '', "");
+
+# test pg_waldump with -F (main)
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-F', 'main' ], '>', \$stdout, '2>', \$stderr;
+isnt($stdout, '', "");
+
+# test pg_waldump with -F (fsm)
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-F', 'fsm' ], '>', \$stdout, '2>', \$stderr;
+is($stdout, '', "");
+
+# test pg_waldump with -F (vm)
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-F', 'vm' ], '>', \$stdout, '2>', \$stderr;
+isnt($stdout, '', "");
+
+# test pg_waldump with -F (init)
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-F', 'init' ], '>', \$stdout, '2>', \$stderr;
+is($stdout, '', "");
+
+# test pg_waldump with -q
+IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-F', 'init' ], '>', \$stdout, '2>', \$stderr;
+is($stdout, '', "");
 done_testing();
+
diff --git a/src/bin/pg_waldump/t/002_wal_type.pl b/src/bin/pg_waldump/t/002_wal_type.pl
new file mode 100644
index 000000000000..d69ddf3a39d0
--- /dev/null
+++ b/src/bin/pg_waldump/t/002_wal_type.pl
@@ -0,0 +1,180 @@
+
+# Copyright (c) 2021-2022, PostgreSQL Global Development Group
+
+use strict;
+use warnings;
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+my $node = PostgreSQL::Test::Cluster->new('main');
+$node->init;
+$node->append_conf('postgresql.conf',
+    "track_commit_timestamp = on\n"
+    . "archive_mode=on\n"
+    . "archive_command='/bin/false'\n"
+    . "wal_level=logical");
+
+# test pg_waldump with xlog files.
+my $source_ts_path = PostgreSQL::Test::Utils::tempdir_short();
+my $pg_wal_dir = $node->data_dir . "/pg_wal/";
+my ($stdout, $stderr);
+
+# test pg_waldump with hash index
+$node->start;
+$node->safe_psql('postgres',
+    'BEGIN;'
+    . 'CREATE TABLE hash_idx_tbl (
+           id int
+       );'
+    . 'CREATE INDEX ON hash_idx_tbl USING hash (id);'
+    . 'COMMIT;'
+    . 'BEGIN;'
+    . 'INSERT INTO hash_idx_tbl
+       SELECT generate_series(1, 1000);'
+    . 'COMMIT;'
+    . 'select pg_switch_wal();'
+);
+$node->stop;
+
+# track_commit_timestamp off
+$node->append_conf('postgresql.conf',
+    "track_commit_timestamp = off");
+
+# test pg_waldump with gin index
+$node->start;
+$node->safe_psql('postgres',
+    'BEGIN;'
+    . 'CREATE TABLE gin_idx_tbl (
+        id bigserial PRIMARY KEY,
+        data jsonb
+    );'
+    . 'CREATE INDEX ON gin_idx_tbl USING gin (data);'
+    . 'COMMIT;'
+    . 'BEGIN;'
+    . "INSERT INTO gin_idx_tbl
+       WITH random_json AS (
+            SELECT json_object_agg(key, trunc(random() * 10)) as json_data
+                FROM unnest(array['a', 'b', 'c']) as u(key))
+              SELECT generate_series(1,500), json_data FROM random_json;"
+    . 'COMMIT;'
+    . 'select pg_switch_wal();'
+);
+$node->stop;
+
+# track_commit_timestamp on
+$node->append_conf('postgresql.conf',
+    "track_commit_timestamp = on");
+
+## test pg_waldump with gist index
+$node->start;
+$node->safe_psql('postgres',
+    'BEGIN;'
+    . 'CREATE TABLE gist_idx_tbl (
+    p point
+    );'
+    . 'CREATE INDEX ON gist_idx_tbl USING gist (p);'
+    . 'COMMIT;'
+    . 'BEGIN;'
+    . 'INSERT INTO gist_idx_tbl(p) values (point \'(1,1)\');'
+    . 'INSERT INTO gist_idx_tbl(p) values (point \'(3,2)\');'
+    . 'INSERT INTO gist_idx_tbl(p) values (point \'(6,3)\');'
+    . 'INSERT INTO gist_idx_tbl(p) values (point \'(5,5)\');'
+    . 'INSERT INTO gist_idx_tbl(p) values (point \'(7,8)\');'
+    . 'INSERT INTO gist_idx_tbl(p) values (point \'(8,6)\');'
+    . 'INSERT INTO gist_idx_tbl(p) values (point \'(9,19)\');'
+    . 'COMMIT;'
+    . 'select pg_switch_wal();'
+);
+$node->stop;
+
+
+## test pg_waldump with spgist index
+$node->start;
+$node->safe_psql('postgres',
+    'BEGIN;'
+    . 'CREATE TABLE spgist_idx_tbl (
+    p point
+    );'
+    . 'CREATE INDEX ON spgist_idx_tbl USING spgist (p);'
+    . 'COMMIT;'
+    . 'BEGIN;'
+    . 'INSERT INTO spgist_idx_tbl(p) values (point \'(1,1)\');'
+    . 'INSERT INTO spgist_idx_tbl(p) values (point \'(3,2)\');'
+    . 'INSERT INTO spgist_idx_tbl(p) values (point \'(6,3)\');'
+    . 'INSERT INTO spgist_idx_tbl(p) values (point \'(5,5)\');'
+    . 'INSERT INTO spgist_idx_tbl(p) values (point \'(7,8)\');'
+    . 'INSERT INTO spgist_idx_tbl(p) values (point \'(8,6)\');'
+    . 'INSERT INTO spgist_idx_tbl(p) values (point \'(9,19)\');'
+    . 'COMMIT;'
+);
+$node->stop;
+
+# test pg_waldump with brin index
+$node->start;
+$node->safe_psql('postgres',
+    'BEGIN;'
+    . 'CREATE TABLE brin_idx_tbl (
+        col1 int,
+        col2 text,
+        col3 text
+    );'
+    . 'COMMIT;'
+    . 'BEGIN;'
+    . 'CREATE INDEX brin_idx ON brin_idx_tbl USING brin (col1, col2, col3) WITH (autosummarize=on);'
+    . 'COMMIT;'
+    . 'BEGIN;'
+    . "INSERT INTO brin_idx_tbl
+       SELECT generate_series(1, 10000), 'dummy', 'dummy';"
+    . 'COMMIT;'
+    . 'BEGIN;'
+    . "UPDATE brin_idx_tbl
+       SET col2 = 'updated'
+       WHERE col1 BETWEEN 1 AND 5000;"
+    . 'COMMIT;'
+    . "SELECT brin_summarize_range('brin_idx', 0);"
+    . "SELECT brin_desummarize_range('brin_idx', 0);"
+);
+$node->stop;
+
+# test pg_waldump with tablespace
+$node->start;
+$node->safe_psql('postgres',
+    "CREATE TABLESPACE tbl_space LOCATION '$source_ts_path';"
+    . 'CREATE TABLE table_space_tbl (
+        col1 int
+    ) TABLESPACE tbl_space;'
+);
+$node->stop;
+
+# test pg_waldump with sequence
+$node->start;
+$node->safe_psql('postgres',
+    "CREATE SEQUENCE sequence;"
+);
+$node->stop;
+
+# test local message
+$node->start;
+$node->safe_psql('postgres',
+    'BEGIN;'
+    . "SELECT pg_logical_emit_message(true, 'text', 'text');"
+    . 'COMMIT;'
+);
+$node->stop;
+
+# test relmap
+$node->start;
+$node->safe_psql('postgres',
+    "SELECT relfilenode FROM pg_class WHERE relname = 'pg_authid';"
+    . 'VACUUM FULL pg_authid;'
+);
+$node->stop;
+
+chdir $pg_wal_dir;
+foreach my $file (glob '000*') {
+    IPC::Run::run [ 'pg_waldump', "$pg_wal_dir/$file" ], '>', \$stdout, '2>', \$stderr;
+    isnt($stdout, '');
+}
+
+done_testing();