postgres.git / summary / log / commit / refs

commit    991bb0f9653c61cf116338f295534d1378df2751
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Fri Oct 06 00:01:27 2023 +0000
First released in: 17.0

    worker_spi: Add tests for BGWORKER_BYPASS_ALLOWCONN
    
    This bgworker flag exists in the core code since eed1ce72e159, but was
    never tested.  This relies on 4f2994647ff1, that has added a way to
    start dynamic workers with this flag enabled.
    
    Reviewed-by: Bertrand Drouvot, Bharath Rupireddy
    Discussion: https://postgr.es/m/bcc36259-7850-4882-97ef-d6b905d2fc51@gmail.com


src/test/modules/worker_spi/t/001_worker_spi.pl | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/modules/worker_spi/t/001_worker_spi.pl b/src/test/modules/worker_spi/t/001_worker_spi.pl index 4b46b1336b1..06bb73816fd 100644 --- a/src/test/modules/worker_spi/t/001_worker_spi.pl +++ b/src/test/modules/worker_spi/t/001_worker_spi.pl @@ -104,4 +104,31 @@ postgres|myrole|WorkerSpiMain]), 'dynamic bgworkers all launched' ) or die "Timed out while waiting for dynamic bgworkers to be launched"; +# Check BGWORKER_BYPASS_ALLOWCONN. +$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS false;)); +my $log_offset = -s $node->logfile; + +# bgworker cannot be launched with connection restriction. +my $worker3_pid = $node->safe_psql('postgres', + qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id);]); +$node->wait_for_log( + qr/database "mydb" is not currently accepting connections/, $log_offset); + +$result = $node->safe_psql('postgres', + "SELECT count(*) FROM pg_stat_activity WHERE pid = $worker3_pid;"); +is($result, '0', 'dynamic bgworker without BYPASS_ALLOWCONN not started'); + +# bgworker bypasses the connection check, and can be launched. +my $worker4_pid = $node->safe_psql('postgres', + qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id, '{"ALLOWCONN"}');]); +ok( $node->poll_query_until( + 'postgres', + qq[SELECT datname, usename, wait_event FROM pg_stat_activity + WHERE backend_type = 'worker_spi dynamic' AND + pid IN ($worker4_pid) ORDER BY datname;], + qq[mydb|myrole|WorkerSpiMain]), + 'dynamic bgworker with BYPASS_ALLOWCONN started'); + +$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;)); + done_testing(); [parent: 180e3394a704]