diff options
Diffstat (limited to 'src/test/modules/test_custom_rmgrs/t/001_basic.pl')
-rw-r--r-- | src/test/modules/test_custom_rmgrs/t/001_basic.pl | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/modules/test_custom_rmgrs/t/001_basic.pl b/src/test/modules/test_custom_rmgrs/t/001_basic.pl new file mode 100644 index 00000000000..a5e3a8834ac --- /dev/null +++ b/src/test/modules/test_custom_rmgrs/t/001_basic.pl @@ -0,0 +1,61 @@ +# 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', q{ +wal_level = 'replica' +max_wal_senders = 4 +shared_preload_libraries = 'test_custom_rmgrs' +}); +$node->start; + +# setup +$node->safe_psql('postgres', 'CREATE EXTENSION test_custom_rmgrs'); + +# pg_walinspect is required only for verifying test_custom_rmgrs output. +# test_custom_rmgrs doesn't use/depend on it internally. +$node->safe_psql('postgres', 'CREATE EXTENSION pg_walinspect'); + +# make sure checkpoints don't interfere with the test. +my $start_lsn = $node->safe_psql('postgres', + qq[SELECT lsn FROM pg_create_physical_replication_slot('regress_test_slot1', true, false);]); + +# write and save the WAL record's returned end LSN for verifying it later +my $record_end_lsn = $node->safe_psql('postgres', + 'SELECT * FROM test_custom_rmgrs_insert_wal_record(\'payload123\')'); + +# ensure the WAL is written and flushed to disk +$node->safe_psql('postgres', 'SELECT pg_switch_wal()'); + +my $end_lsn = $node->safe_psql('postgres', 'SELECT pg_current_wal_flush_lsn()'); + +# check if our custom WAL resource manager has successfully registered with the server +my $row_count = + $node->safe_psql('postgres', + qq[SELECT count(*) FROM pg_get_wal_resource_managers() + WHERE rm_name = 'test_custom_rmgrs';]); +is($row_count, '1', + 'custom WAL resource manager has successfully registered with the server' +); + +# check if our custom WAL resource manager has successfully written a WAL record +my $expected = qq($record_end_lsn|test_custom_rmgrs|TEST_CUSTOM_RMGRS_MESSAGE|44|18|0|payload (10 bytes): payload123); +my $result = + $node->safe_psql('postgres', + qq[SELECT end_lsn, resource_manager, record_type, record_length, main_data_length, fpi_length, description FROM pg_get_wal_records_info('$start_lsn', '$end_lsn') + WHERE resource_manager = 'test_custom_rmgrs';]); +is($result, $expected, + 'custom WAL resource manager has successfully written a WAL record' +); + +$node->stop; +done_testing(); |