Re: pg_waldump: add test for coverage
On 29.06.23 21:16, Tristen Raab wrote: I've reviewed your latest v3 patches on Ubuntu 23.04. Both patches apply correctly and all the tests run and pass as they should. Execution time was normal for me, I didn't notice any significant latency when compared to other tests. The only other feedback I can provide would be to add test coverage to some of the other options that aren't currently covered (ie. --bkp-details, --end, --follow, --path, etc.) for completeness. Other than that, this looks like a great patch. Committed. I added a test for the --quiet option. --end and --path are covered. The only options not covered now are -b, --bkp-details output detailed information about backup blocks -f, --follow keep retrying after reaching end of WAL -t, --timeline=TLI timeline from which to read WAL records -x, --xid=XID only show records with transaction ID XID --follow is a bit tricky to test because you need to leave pg_waldump running in the background for a while, or something like that. --timeline and --xid can be tested but would need some work on the underlying test data (such as creating more than one timeline). I don't know much about --bkp-details, so I don't have a good idea how to test it. So I'll leave those as projects for the future.
Re: pg_waldump: add test for coverage
The following review has been posted through the commitfest application: make installcheck-world: tested, passed Implements feature: tested, passed Spec compliant: not tested Documentation:not tested Hello, I've reviewed your latest v3 patches on Ubuntu 23.04. Both patches apply correctly and all the tests run and pass as they should. Execution time was normal for me, I didn't notice any significant latency when compared to other tests. The only other feedback I can provide would be to add test coverage to some of the other options that aren't currently covered (ie. --bkp-details, --end, --follow, --path, etc.) for completeness. Other than that, this looks like a great patch. Kind regards, Tristen
Re: pg_waldump: add test for coverage
On 14.06.23 09:16, Peter Eisentraut wrote: On 06.09.22 07:57, Peter Eisentraut wrote: I wrote a test for coverage. Unfortunately, it seems to take quite a while to run the test. I want to improve these execution times, but I don't know exactly what to do. Therefore, I want to hear feedback from many people. I think having some more test coverage for pg_waldump would be good, so I encourage you to continue working on this. I made an updated patch that incorporates many of your ideas and code, just made it a bit more compact, and added more tests for various command-line options. This moves the test coverage of pg_waldump from "bloodbath" to "mixed fruit salad", which I think is pretty good progress. And now there is room for additional patches if someone wants to figure out, e.g., how to get more complete coverage in gindesc.c or whatever. Here is an updated patch set. I added a test case for the "first record is after" message. Also, I think this message should really go to stderr, since it's more of a notice or warning, so I changed it to use pg_log_info. From e5d13b7891a9c0fcc3d28f9bc2756c5372b2fa40 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 14 Jun 2023 08:46:47 +0200 Subject: [PATCH v3 1/2] Add more pg_waldump tests This adds tests for most command-line options and tests for most rmgrdesc routines. Discussion: https://www.postgresql.org/message-id/flat/CAAcByaKM7zyJSDkPWv6_%2BapupY4fXXM3q3SRXas9MMNVPUGcsQ%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 191 ++ 1 file changed, 191 insertions(+) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 492a8cadd8..d4056e1b95 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,194 @@ program_version_ok('pg_waldump'); program_options_handling_ok('pg_waldump'); +# wrong number of arguments +command_fails_like([ 'pg_waldump', ], qr/error: no arguments/, 'no arguments'); +command_fails_like([ 'pg_waldump', 'foo', 'bar', 'baz' ], qr/error: too many command-line arguments/, 'too many arguments'); + +# invalid option arguments +command_fails_like([ 'pg_waldump', '--block', 'bad' ], qr/error: invalid block number/, 'invalid block number'); +command_fails_like([ 'pg_waldump', '--fork', 'bad' ], qr/error: invalid fork name/, 'invalid fork name'); +command_fails_like([ 'pg_waldump', '--limit', 'bad' ], qr/error: invalid value/, 'invalid limit'); +command_fails_like([ 'pg_waldump', '--relation', 'bad' ], qr/error: invalid relation/, 'invalid relation specification'); +command_fails_like([ 'pg_waldump', '--rmgr', 'bad' ], qr/error: resource manager .* does not exist/, 'invalid rmgr name'); +command_fails_like([ 'pg_waldump', '--start', 'bad' ], qr/error: invalid WAL location/, 'invalid start LSN'); +command_fails_like([ 'pg_waldump', '--end', 'bad' ], qr/error: invalid WAL location/, 'invalid end LSN'); + +# rmgr list: If you add one to the list, consider also adding a test +# case exercising the new rmgr below. +command_like([ 'pg_waldump', '--rmgr=list'], qr/^XLOG +Transaction +Storage +CLOG +Database +Tablespace +MultiXact +RelMap +Standby +Heap2 +Heap +Btree +Hash +Gin +Gist +Sequence +SPGist +BRIN +CommitTs +ReplicationOrigin +Generic +LogicalMessage$/, + 'rmgr list'); + + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->append_conf('postgresql.conf', q{ +autovacuum = off +checkpoint_timeout = 1h + +# for standbydesc +archive_mode=on +archive_command='' + +# for XLOG_HEAP_TRUNCATE +wal_level=logical +}); +$node->start; + +my ($start_lsn, $start_walfile) = split /\|/, $node->safe_psql('postgres', q{SELECT pg_current_wal_insert_lsn(), pg_walfile_name(pg_current_wal_insert_lsn())}); + +$node->safe_psql('postgres', q{ +-- heap, btree, hash, sequence +CREATE TABLE t1 (a int GENERATED ALWAYS AS IDENTITY, b text); +CREATE INDEX i1a ON t1 USING btree (a); +CREATE INDEX i1b ON t1 USING hash (b); +INSERT INTO t1 VALUES (default, 'one'), (default, 'two'); +DELETE FROM t1 WHERE b = 'one'; +TRUNCATE t1; + +-- abort +START TRANSACTION; +INSERT INTO t1 VALUES (default, 'three'); +ROLLBACK; + +-- unlogged/init fork +CREATE UNLOGGED TABLE t2 (x int); +CREATE INDEX i2 ON t2 USING btree (x); +INSERT INTO t2 SELECT generate_series(1, 10); + +-- gin +CREATE TABLE gin_idx_tbl (id bigserial PRIMARY KEY, data jsonb); +CREATE INDEX gin_idx ON gin_idx_tbl USING gin (data); +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; + +-- gist, spgist +CREATE TABLE gist_idx_tbl (p point); +CREATE INDEX gist_idx ON gist_idx_tbl USING gist (p); +CREATE INDEX spgist_idx ON gi
Re: pg_waldump: add test for coverage
On 06.09.22 07:57, Peter Eisentraut wrote: I wrote a test for coverage. Unfortunately, it seems to take quite a while to run the test. I want to improve these execution times, but I don't know exactly what to do. Therefore, I want to hear feedback from many people. I think having some more test coverage for pg_waldump would be good, so I encourage you to continue working on this. I made an updated patch that incorporates many of your ideas and code, just made it a bit more compact, and added more tests for various command-line options. This moves the test coverage of pg_waldump from "bloodbath" to "mixed fruit salad", which I think is pretty good progress. And now there is room for additional patches if someone wants to figure out, e.g., how to get more complete coverage in gindesc.c or whatever. From 67d63a87cf9ea8de69801127607101b3a515fb42 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 14 Jun 2023 08:46:47 +0200 Subject: [PATCH v2] Add more pg_waldump tests This adds tests for most command-line options and tests for most rmgrdesc routines. Discussion: https://www.postgresql.org/message-id/flat/CAAcByaKM7zyJSDkPWv6_%2BapupY4fXXM3q3SRXas9MMNVPUGcsQ%40mail.gmail.com --- src/bin/pg_waldump/t/001_basic.pl | 191 ++ 1 file changed, 191 insertions(+) diff --git a/src/bin/pg_waldump/t/001_basic.pl b/src/bin/pg_waldump/t/001_basic.pl index 492a8cadd8..d4056e1b95 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,194 @@ program_version_ok('pg_waldump'); program_options_handling_ok('pg_waldump'); +# wrong number of arguments +command_fails_like([ 'pg_waldump', ], qr/error: no arguments/, 'no arguments'); +command_fails_like([ 'pg_waldump', 'foo', 'bar', 'baz' ], qr/error: too many command-line arguments/, 'too many arguments'); + +# invalid option arguments +command_fails_like([ 'pg_waldump', '--block', 'bad' ], qr/error: invalid block number/, 'invalid block number'); +command_fails_like([ 'pg_waldump', '--fork', 'bad' ], qr/error: invalid fork name/, 'invalid fork name'); +command_fails_like([ 'pg_waldump', '--limit', 'bad' ], qr/error: invalid value/, 'invalid limit'); +command_fails_like([ 'pg_waldump', '--relation', 'bad' ], qr/error: invalid relation/, 'invalid relation specification'); +command_fails_like([ 'pg_waldump', '--rmgr', 'bad' ], qr/error: resource manager .* does not exist/, 'invalid rmgr name'); +command_fails_like([ 'pg_waldump', '--start', 'bad' ], qr/error: invalid WAL location/, 'invalid start LSN'); +command_fails_like([ 'pg_waldump', '--end', 'bad' ], qr/error: invalid WAL location/, 'invalid end LSN'); + +# rmgr list: If you add one to the list, consider also adding a test +# case exercising the new rmgr below. +command_like([ 'pg_waldump', '--rmgr=list'], qr/^XLOG +Transaction +Storage +CLOG +Database +Tablespace +MultiXact +RelMap +Standby +Heap2 +Heap +Btree +Hash +Gin +Gist +Sequence +SPGist +BRIN +CommitTs +ReplicationOrigin +Generic +LogicalMessage$/, + 'rmgr list'); + + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->append_conf('postgresql.conf', q{ +autovacuum = off +checkpoint_timeout = 1h + +# for standbydesc +archive_mode=on +archive_command='' + +# for XLOG_HEAP_TRUNCATE +wal_level=logical +}); +$node->start; + +my ($start_lsn, $start_walfile) = split /\|/, $node->safe_psql('postgres', q{SELECT pg_current_wal_insert_lsn(), pg_walfile_name(pg_current_wal_insert_lsn())}); + +$node->safe_psql('postgres', q{ +-- heap, btree, hash, sequence +CREATE TABLE t1 (a int GENERATED ALWAYS AS IDENTITY, b text); +CREATE INDEX i1a ON t1 USING btree (a); +CREATE INDEX i1b ON t1 USING hash (b); +INSERT INTO t1 VALUES (default, 'one'), (default, 'two'); +DELETE FROM t1 WHERE b = 'one'; +TRUNCATE t1; + +-- abort +START TRANSACTION; +INSERT INTO t1 VALUES (default, 'three'); +ROLLBACK; + +-- unlogged/init fork +CREATE UNLOGGED TABLE t2 (x int); +CREATE INDEX i2 ON t2 USING btree (x); +INSERT INTO t2 SELECT generate_series(1, 10); + +-- gin +CREATE TABLE gin_idx_tbl (id bigserial PRIMARY KEY, data jsonb); +CREATE INDEX gin_idx ON gin_idx_tbl USING gin (data); +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; + +-- gist, spgist +CREATE TABLE gist_idx_tbl (p point); +CREATE INDEX gist_idx ON gist_idx_tbl USING gist (p); +CREATE INDEX spgist_idx ON gist_idx_tbl USING spgist (p); +INSERT INTO gist_idx_tbl (p) VALUES (point '(1, 1)'), (point '(3, 2)'), (point '(6, 3)'); + +-- brin +CREATE TABLE brin_idx_tbl (col1 int, col2 text, col3 text ); +CREATE INDEX brin_idx ON brin_idx_tbl USING brin (col1, col2, col3) WITH (autosum
Re: pg_waldump: add test for coverage
Hi, On 2022-08-23 10:50:08 +0900, Dong Wook Lee wrote: > I wrote a test for coverage. Unfortunately the test doesn't seem to pass on windows, and hasn't ever done so: https://cirrus-ci.com/github/postgresql-cfbot/postgresql/commitfest/39/3834 Due to the merge of the meson patchset, you should also add 001_basic.pl to the list of tests in meson.build Greetings, Andres Freund
Re: pg_waldump: add test for coverage
On 23.08.22 03:50, Dong Wook Lee wrote: Hi Hackers, I wrote a test for coverage. Unfortunately, it seems to take quite a while to run the test. I want to improve these execution times, but I don't know exactly what to do. Therefore, I want to hear feedback from many people. I don't find these tests to be particularly slow. How long do they take for you to run? A couple of tips: - You should give each test a name. That's why each test function has a (usually) last argument that takes a string. - You could use command_like() to run a command and check that it exits successfully and check its standard out. For example, instead of # test pg_waldump with -F (main) IPC::Run::run [ 'pg_waldump', "$wal_dump_path", '-F', 'main' ], '>', \$stdout, '2>', \$stderr; isnt($stdout, '', ""); it is better to write command_like([ 'pg_waldump', "$wal_dump_path", '-F', 'main' ], qr/TODO/, 'test -F (main)'); - It would be useful to test the actual output (that is, fill in the TODO above). I don't know what the best way to do that is -- that is part of designing these tests. Also, - Your patch introduces a spurious blank line at the end of the test file. - For portability, options must be before non-option arguments. So instead of [ 'pg_waldump', "$wal_dump_path", '-F', 'main' ] it should be [ 'pg_waldump', '-F', 'main', "$wal_dump_path" ] I think having some more test coverage for pg_waldump would be good, so I encourage you to continue working on this.
pg_waldump: add test for coverage
Hi Hackers, I wrote a test for coverage. Unfortunately, it seems to take quite a while to run the test. I want to improve these execution times, but I don't know exactly what to do. Therefore, I want to hear feedback from many people. --- Regards, Dong Wook Lee v1_add_test_pg_waldump.patch Description: Binary data