Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 991bb0f

Browse filesBrowse files
committed
worker_spi: Add tests for BGWORKER_BYPASS_ALLOWCONN
This bgworker flag exists in the core code since eed1ce7, but was never tested. This relies on 4f29946, 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
1 parent 180e339 commit 991bb0f
Copy full SHA for 991bb0f

File tree

1 file changed

+27
-0
lines changed
Filter options

1 file changed

+27
-0
lines changed

‎src/test/modules/worker_spi/t/001_worker_spi.pl

Copy file name to clipboardExpand all lines: src/test/modules/worker_spi/t/001_worker_spi.pl
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,31 @@
104104
'dynamic bgworkers all launched'
105105
) or die "Timed out while waiting for dynamic bgworkers to be launched";
106106

107+
# Check BGWORKER_BYPASS_ALLOWCONN.
108+
$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS false;));
109+
my $log_offset = -s $node->logfile;
110+
111+
# bgworker cannot be launched with connection restriction.
112+
my $worker3_pid = $node->safe_psql('postgres',
113+
qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id);]);
114+
$node->wait_for_log(
115+
qr/database "mydb" is not currently accepting connections/, $log_offset);
116+
117+
$result = $node->safe_psql('postgres',
118+
"SELECT count(*) FROM pg_stat_activity WHERE pid = $worker3_pid;");
119+
is($result, '0', 'dynamic bgworker without BYPASS_ALLOWCONN not started');
120+
121+
# bgworker bypasses the connection check, and can be launched.
122+
my $worker4_pid = $node->safe_psql('postgres',
123+
qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id, '{"ALLOWCONN"}');]);
124+
ok( $node->poll_query_until(
125+
'postgres',
126+
qq[SELECT datname, usename, wait_event FROM pg_stat_activity
127+
WHERE backend_type = 'worker_spi dynamic' AND
128+
pid IN ($worker4_pid) ORDER BY datname;],
129+
qq[mydb|myrole|WorkerSpiMain]),
130+
'dynamic bgworker with BYPASS_ALLOWCONN started');
131+
132+
$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;));
133+
107134
done_testing();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.