Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 353aa01

Browse files
committed
postgres_fdw: Add regression test for postgres_fdw.application_name GUC.
Commit 449ab63 added postgres_fdw.application_name GUC that specifies a value for application_name configuration parameter used when postgres_fdw establishes a connection to a foreign server. Also commit 6e0cb3d allowed it to include escape sequences. Both commits added the regression tests for the GUC, but those tests were reverted by commits 98dbef9 and 5e64ad3 because they were unstable and caused some buildfarm members to report the failure. This is the third try to add the regression test for postgres_fdw.application_name GUC. One of issues to make the test unstable was to have used postgres_fdw_disconnect_all() to close the existing remote connections. The test expected that the remote connection and its corresponding backend at the remote server disappeared just after postgres_fdw_disconnect_all() was executed, but it could take a bit time for them to disappear. To make sure that they exit, this commit makes the test use pg_terminate_backend() with the timeout at the remote server, instead. If the timeout is set to greater than zero, this function waits until they are actually terminated (or until the given time has passed). Another issue was that the test didn't take into consideration the case where postgres_fdw.application_name containing some escape sequences was converted to the string larger than NAMEDATALEN. In this case it was truncated to less than NAMEDATALEN when it's passed to the remote server, but the test expected wrongly that full string of application_name was always viewable. This commit changes the test so that it can handle that case. Author: Fujii Masao Reviewed-by: Masahiko Sawada, Hayato Kuroda, Kyotaro Horiguchi Discussion: https://postgr.es/m/3220909.1631054766@sss.pgh.pa.us Discussion: https://postgr.es/m/20211224.180006.2247635208768233073.horikyota.ntt@gmail.com Discussion: https://postgr.es/m/e7b61420-a97b-8246-77c4-a0d48fba5a45@oss.nttdata.com
1 parent 50e1441 commit 353aa01

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

+51
Original file line numberDiff line numberDiff line change
@@ -10825,3 +10825,54 @@ ERROR: invalid value for integer option "batch_size": 100$%$#$#
1082510825
ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (nonexistent 'fdw');
1082610826
ERROR: invalid option "nonexistent"
1082710827
HINT: There are no valid options in this context.
10828+
-- ===================================================================
10829+
-- test postgres_fdw.application_name GUC
10830+
-- ===================================================================
10831+
--- Turn debug_discard_caches off for this test to make sure that
10832+
--- the remote connection is alive when checking its application_name.
10833+
SET debug_discard_caches = 0;
10834+
-- Specify escape sequences in application_name option of a server
10835+
-- object so as to test that they are replaced with status information
10836+
-- expectedly.
10837+
--
10838+
-- Since pg_stat_activity.application_name may be truncated to less than
10839+
-- NAMEDATALEN characters, note that substring() needs to be used
10840+
-- at the condition of test query to make sure that the string consisting
10841+
-- of database name and process ID is also less than that.
10842+
ALTER SERVER loopback2 OPTIONS (application_name 'fdw_%d%p');
10843+
SELECT 1 FROM ft6 LIMIT 1;
10844+
?column?
10845+
----------
10846+
1
10847+
(1 row)
10848+
10849+
SELECT pg_terminate_backend(pid, 180000) FROM pg_stat_activity
10850+
WHERE application_name =
10851+
substring('fdw_' || current_database() || pg_backend_pid() for
10852+
current_setting('max_identifier_length')::int);
10853+
pg_terminate_backend
10854+
----------------------
10855+
t
10856+
(1 row)
10857+
10858+
-- postgres_fdw.application_name overrides application_name option
10859+
-- of a server object if both settings are present.
10860+
SET postgres_fdw.application_name TO 'fdw_%a%u%%';
10861+
SELECT 1 FROM ft6 LIMIT 1;
10862+
?column?
10863+
----------
10864+
1
10865+
(1 row)
10866+
10867+
SELECT pg_terminate_backend(pid, 180000) FROM pg_stat_activity
10868+
WHERE application_name =
10869+
substring('fdw_' || current_setting('application_name') ||
10870+
CURRENT_USER || '%' for current_setting('max_identifier_length')::int);
10871+
pg_terminate_backend
10872+
----------------------
10873+
t
10874+
(1 row)
10875+
10876+
--Clean up
10877+
RESET postgres_fdw.application_name;
10878+
RESET debug_discard_caches;

contrib/postgres_fdw/sql/postgres_fdw.sql

+35
Original file line numberDiff line numberDiff line change
@@ -3452,3 +3452,38 @@ CREATE FOREIGN TABLE inv_bsz (c1 int )
34523452

34533453
-- No option is allowed to be specified at foreign data wrapper level
34543454
ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (nonexistent 'fdw');
3455+
3456+
-- ===================================================================
3457+
-- test postgres_fdw.application_name GUC
3458+
-- ===================================================================
3459+
--- Turn debug_discard_caches off for this test to make sure that
3460+
--- the remote connection is alive when checking its application_name.
3461+
SET debug_discard_caches = 0;
3462+
3463+
-- Specify escape sequences in application_name option of a server
3464+
-- object so as to test that they are replaced with status information
3465+
-- expectedly.
3466+
--
3467+
-- Since pg_stat_activity.application_name may be truncated to less than
3468+
-- NAMEDATALEN characters, note that substring() needs to be used
3469+
-- at the condition of test query to make sure that the string consisting
3470+
-- of database name and process ID is also less than that.
3471+
ALTER SERVER loopback2 OPTIONS (application_name 'fdw_%d%p');
3472+
SELECT 1 FROM ft6 LIMIT 1;
3473+
SELECT pg_terminate_backend(pid, 180000) FROM pg_stat_activity
3474+
WHERE application_name =
3475+
substring('fdw_' || current_database() || pg_backend_pid() for
3476+
current_setting('max_identifier_length')::int);
3477+
3478+
-- postgres_fdw.application_name overrides application_name option
3479+
-- of a server object if both settings are present.
3480+
SET postgres_fdw.application_name TO 'fdw_%a%u%%';
3481+
SELECT 1 FROM ft6 LIMIT 1;
3482+
SELECT pg_terminate_backend(pid, 180000) FROM pg_stat_activity
3483+
WHERE application_name =
3484+
substring('fdw_' || current_setting('application_name') ||
3485+
CURRENT_USER || '%' for current_setting('max_identifier_length')::int);
3486+
3487+
--Clean up
3488+
RESET postgres_fdw.application_name;
3489+
RESET debug_discard_caches;

0 commit comments

Comments
 (0)