Hi,

I reapplied the patch and tested the patch with (enable-tap-tests +
readline and enable-tap-tests + without-readline). I think the issue
was caused by differences in how psql emits prompts and echoed output
without readline which could lead to banner interleaving, timeouts or
premature TAP termination. In my patch I included the fixes that make
banner detection in BackgroundPsql.pm to be tolerant while keeping
strict line-based cleanup to preserve correct TAP behavior. The fix is
behavior-based and does not rely on configuration variables or test
skipping.
Kindly review my patch attached herewith and please let me know the feedback.

Regards
Soumya
From 7bd670d85c80fb3a71cbf7cb78b1a4897502e7b0 Mon Sep 17 00:00:00 2001
From: Soumya S Murali <[email protected]>
Date: Fri, 2 Jan 2026 15:21:13 +0530
Subject: [PATCH] Fix authentication test failure with or without readline

Signed-off-by: Soumya S Murali <[email protected]>
---
 .../perl/PostgreSQL/Test/BackgroundPsql.pm    | 28 ++++++++++++++-----
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm b/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
index 60bbd5dd445..549032c07a1 100644
--- a/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
+++ b/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm
@@ -155,11 +155,12 @@ sub wait_connect
 	#
 	# See query() for details about why/how the banner is used.
 	my $banner = "background_psql: ready";
-	my $banner_match = qr/(^|\n)$banner\r?\n/;
+	my $banner_match = qr/\Q$banner\E/;
+
 	$self->{stdin} .= "\\echo $banner\n\\warn $banner\n";
 	$self->{run}->pump()
 	  until ($self->{stdout} =~ /$banner_match/
-		  && $self->{stderr} =~ /$banner\r?\n/)
+		  && $self->{stderr} =~ /(^|\n)\Q$banner\E\r?\n/)
 	  || $self->{timeout}->is_expired;
 
 	note "connect output:\n",
@@ -265,14 +266,18 @@ sub query
 	# to be careful that we don't e.g. match the echoed \echo command, rather
 	# than its output.
 	my $banner = "background_psql: QUERY_SEPARATOR $query_cnt:";
-	my $banner_match = qr/(^|\n)$banner\r?\n/;
+	my $banner_detect_stdout = qr/\Q$banner\E/;
+	my $banner_detect_stderr = qr/(^|\n)\Q$banner\E\r?\n/;
+	# strict cleanup regex (must be line-based)
+	my $banner_cleanup = $banner_detect_stderr;
+	
 	$self->{stdin} .= "$query\n;\n\\echo $banner\n\\warn $banner\n";
 	pump_until(
 		$self->{run}, $self->{timeout},
-		\$self->{stdout}, qr/$banner_match/);
+		\$self->{stdout}, $banner_detect_stdout);
 	pump_until(
 		$self->{run}, $self->{timeout},
-		\$self->{stderr}, qr/$banner_match/);
+		\$self->{stderr}, $banner_detect_stderr);
 
 	die "psql query timed out" if $self->{timeout}->is_expired;
 
@@ -286,8 +291,17 @@ sub query
 	# first newline is optional, as there would not be one if consuming an
 	# empty query result.
 	$output = $self->{stdout};
-	$output =~ s/$banner_match//;
-	$self->{stderr} =~ s/$banner_match//;
+	if ($output =~ s/$banner_detect_stderr//)
+	{
+		# cleaned via strict match
+	}
+	else
+	{
+		# fallback for non-readline output where banner may be inline
+		$output =~ s/\Q$banner\E//;
+	}
+
+	$self->{stderr} =~ s/$banner_detect_stderr//;
 
 	# clear out output for the next query
 	$self->{stdout} = '';
-- 
2.34.1

Reply via email to