From b33abe1e315b68fc1a5d880f6fdecd20714af8dc Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Fri, 18 Jul 2025 10:21:39 +0300
Subject: [PATCH v3 3/3] Check primary and standby are alive after regression
 tests in 027_stream_regress

Add a test for checking if the primary and the standby are alive after
the regression tests in 027_stream_regress.

Also, regression diffs are only meaningful if both the primary and the
standby are still alive after the regression test failure, otherwise
something else is broken. So, do not report anything if the primary or
standby are not alive although regression tests are failed.

Suggested-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAN55FZ1D6KXvjSs7YGsDeadqCxNF3UUhjRAfforzzP0k-cE%3DbA%40mail.gmail.com
---
 src/test/perl/PostgreSQL/Test/Cluster.pm  | 20 ++++++++++++++++++++
 src/test/recovery/t/027_stream_regress.pl | 10 +++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 301766d2ed9..3b9ce34db63 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -290,6 +290,26 @@ sub connstr
 
 =pod
 
+=item $node->is_alive()
+
+Check if the node is alive.
+
+=cut
+
+sub is_alive {
+    my ($self) = @_;
+	local %ENV = $self->_get_env();
+
+    my $host = $self->host;
+    my $port = $self->port;
+	my $null = File::Spec->devnull;
+
+    my $cmd = "pg_isready -h $host -p $port";
+	return !system("$cmd >$null 2>&1");
+}
+
+=pod
+
 =item $node->raw_connect()
 
 Open a raw TCP or Unix domain socket connection to the server. This is
diff --git a/src/test/recovery/t/027_stream_regress.pl b/src/test/recovery/t/027_stream_regress.pl
index 981e3aa7e77..3de570ead5d 100644
--- a/src/test/recovery/t/027_stream_regress.pl
+++ b/src/test/recovery/t/027_stream_regress.pl
@@ -81,7 +81,13 @@ my $rc =
 	  . "--max-concurrent-tests=20 "
 	  . "--inputdir=../regress "
 	  . "--outputdir=\"$outputdir\"");
-if ($rc != 0)
+my $primary_alive = $node_primary->is_alive;
+my $standby_alive = $node_standby_1->is_alive;
+# Regression diffs are only meaningful if both the primary and the standby are
+# still alive after the regression test failure, otherwise something else is
+# broken. So, do not report anything if the primary or standby are not alive
+# although regression tests are failed.
+if ($rc != 0 && $primary_alive && $standby_alive)
 {
 	# Dump out the regression diffs file, if there is one
 	my $diffs = "$outputdir/regression.diffs";
@@ -97,6 +103,8 @@ if ($rc != 0)
 	}
 }
 is($rc, 0, 'regression tests pass');
+is($primary_alive, 1, 'primary is alive after the regression tests');
+is($standby_alive, 1, 'standby is alive after the regression tests');
 
 # Clobber all sequences with their next value, so that we don't have
 # differences between nodes due to caching.
-- 
2.50.0

