From e13d6f97cdd9b2806b4c8fe9db78766d7e7fe1e6 Mon Sep 17 00:00:00 2001 From: Jacob Champion Date: Mon, 5 May 2025 14:09:54 -0700 Subject: [PATCH v1 2/2] WIP: add TCP tests Regression test for the previous patch. Needs discussion on-list. --- .cirrus.tasks.yml | 2 +- src/test/modules/libpq_pipeline/meson.build | 1 + src/test/modules/libpq_pipeline/t/002_tcp.pl | 45 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/test/modules/libpq_pipeline/t/002_tcp.pl diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml index 92057006c93..dc7786fff42 100644 --- a/.cirrus.tasks.yml +++ b/.cirrus.tasks.yml @@ -29,7 +29,7 @@ env: MTEST_ARGS: --print-errorlogs --no-rebuild -C build PGCTLTIMEOUT: 120 # avoids spurious failures during parallel tests TEMP_CONFIG: ${CIRRUS_WORKING_DIR}/src/tools/ci/pg_ci_base.conf - PG_TEST_EXTRA: kerberos ldap ssl libpq_encryption load_balance oauth + PG_TEST_EXTRA: kerberos ldap ssl libpq_encryption load_balance oauth tcp # What files to preserve in case tests fail diff --git a/src/test/modules/libpq_pipeline/meson.build b/src/test/modules/libpq_pipeline/meson.build index 3fd70a04a38..9edf6c0a22b 100644 --- a/src/test/modules/libpq_pipeline/meson.build +++ b/src/test/modules/libpq_pipeline/meson.build @@ -26,6 +26,7 @@ tests += { 'tap': { 'tests': [ 't/001_libpq_pipeline.pl', + 't/002_tcp.pl', ], 'deps': [libpq_pipeline], }, diff --git a/src/test/modules/libpq_pipeline/t/002_tcp.pl b/src/test/modules/libpq_pipeline/t/002_tcp.pl new file mode 100644 index 00000000000..64902a1a9c2 --- /dev/null +++ b/src/test/modules/libpq_pipeline/t/002_tcp.pl @@ -0,0 +1,45 @@ + +# Copyright (c) 2021-2025, PostgreSQL Global Development Group + +use strict; +use warnings FATAL => 'all'; + +use PostgreSQL::Test::Utils; +use Test::More; + +# Force test nodes to begin in TCP mode. +# Use an INIT block so it runs after the BEGIN block in Utils.pm. + +INIT { $PostgreSQL::Test::Utils::use_unix_sockets = 0; } + +use PostgreSQL::Test::Cluster; + +if (!$ENV{PG_TEST_EXTRA} || $ENV{PG_TEST_EXTRA} !~ /\btcp\b/) +{ + plan skip_all => + 'Potentially unsafe test TCP not enabled in PG_TEST_EXTRA'; +} + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +# Don't let PGHOST interfere with these tests. +delete $ENV{PGHOST}; + +my @cases = ( + $node->connstr('postgres') . " max_protocol_version=latest", + $node->connstr('postgres') . " max_protocol_version=3.0", + "hostaddr=127.0.0.1 port=" . $node->port); + +foreach my $c (@cases) +{ + # Don't use $node->command_ok(); it overrides PGHOST too. + command_ok( + [ 'libpq_pipeline', 'cancel', $c ], + "libpq_pipeline cancel, connstr: " . $c); +} + +$node->stop('fast'); + +done_testing(); -- 2.34.1