From e4479f1b4f9c5b8e7d48d727cff2dfed9164fbf6 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavuz81@gmail.com>
Date: Thu, 4 Dec 2025 14:47:25 +0300
Subject: [PATCH v5 2/2] Improve error reporting in 027_stream_regress test

Previously, the 027_stream_regress test only reported that the regression
test had failed, without showing the actual error. The detailed failure
information was hidden in the regression.diffs file.

This commit improves the situation by including the head and tail of
regression.diffs directly in the failure message. This helps quickly
identify the root cause without needing to open extra files.

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/recovery/t/027_stream_regress.pl | 35 +++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/test/recovery/t/027_stream_regress.pl b/src/test/recovery/t/027_stream_regress.pl
index 589c79d97d3..60025dd4c86 100644
--- a/src/test/recovery/t/027_stream_regress.pl
+++ b/src/test/recovery/t/027_stream_regress.pl
@@ -97,6 +97,41 @@ if ($rc != 0 && $primary_alive && $standby_alive)
 		print "=== dumping $diffs ===\n";
 		print slurp_file($diffs);
 		print "=== EOF ===\n";
+
+		# Dump out 50 lines from head and tail of regression diffs to the
+		# failure message. Number of lines may change depending on the
+		# PG_TEST_FILE_READ_LINES environment variable.
+		my ($head, $head_size, $tail, $tail_size, $entire_file, $line_count)
+		  = read_file_ends($diffs, 50);
+
+		if ($entire_file)
+		{
+			diag("\n=== dumping $diffs ===\n");
+			foreach my $line (@$head)
+			{
+				diag($line);
+			}
+		}
+		if (!$entire_file && $head_size)
+		{
+			diag("\n=== dumping $line_count lines from head of $diffs ===\n");
+			foreach my $line (@$head)
+			{
+				diag($line);
+			}
+		}
+		if (!$entire_file && $tail_size)
+		{
+			diag("\n=== dumping $line_count lines from tail of $diffs ===\n");
+			foreach my $line (@$tail)
+			{
+				diag($line);
+			}
+		}
+		if ($entire_file || $head_size || $tail_size)
+		{
+			diag("=== EOF ===\n\n");
+		}
 	}
 }
 is($rc, 0, 'regression tests pass');
-- 
2.51.0

