From ef3d0b4237e4a0eb10e1394d22119488ca1c54d0 Mon Sep 17 00:00:00 2001
From: Nitin Motiani <nitinmotiani@google.com>
Date: Thu, 22 May 2025 10:20:15 +0000
Subject: [PATCH v9 5/5] [POC] Add tests to pg_dump.pl

* POC test in pg_dump.pl. More tests will be added and this patch
  merged with the other test patch.

* Add extra logging for POC.
---
 src/bin/pg_dump/compress_none.c  | 10 +++++++++-
 src/bin/pg_dump/t/002_pg_dump.pl | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_dump/compress_none.c b/src/bin/pg_dump/compress_none.c
index bc63ccabdb6..465ff861688 100644
--- a/src/bin/pg_dump/compress_none.c
+++ b/src/bin/pg_dump/compress_none.c
@@ -212,9 +212,15 @@ close_none(CompressFileHandle *CFH)
 	{
 		errno = 0;
 		if (CFH->path_is_pipe_command)
-			ret = pclose(fp);
+		{
+			pg_log_debug("closing pipe %p.", (void*) fp);
+			ret = pclose_check(fp);
+		}
 		else
+		{
+			pg_log_debug("closing normal file.");
 			ret = fclose(fp);
+		}
 		if (ret != 0)
 			pg_log_error("could not close file: %m");
 	}
@@ -246,6 +252,7 @@ open_none(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
 	if (CFH->private_data == NULL)
 		return false;
 
+	pg_log_debug("After successful open, the filep is %p", (void*) CFH->private_data);
 	return true;
 }
 
@@ -265,6 +272,7 @@ open_write_none(const char *path, const char *mode, CompressFileHandle *CFH)
 	if (CFH->private_data == NULL)
 		return false;
 
+	pg_log_debug("After successful open_write, the filep is %p", (void*) CFH->private_data);
 	return true;
 }
 
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index f15bd06adcc..e1a843b59f2 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -223,6 +223,25 @@ my %pgdump_runs = (
 		],
 	},
 
+	# This test kept failing.
+	defaults_dir_format_pipe => {
+		test_key => 'defaults',
+		dump_cmd => [
+			'pg_dump',
+			'--format' => 'directory',
+			'--pipe-command' => "cat > $tempdir/defaults_dir_format/%f",
+			'--statistics',
+			'postgres',
+		],
+	restore_cmd => [
+			'pg_restore',
+			'--format' => 'directory',
+			'--file' => "$tempdir/defaults_dir_format_pipe.sql",
+			'--statistics',
+			"$tempdir/defaults_dir_format",
+		],
+	},
+
 	# Do not use --no-sync to give test coverage for data sync.
 	defaults_parallel => {
 		test_key => 'defaults',
-- 
2.53.0.473.g4a7958ca14-goog

