On Wed, May 25, 2022 at 08:21:26AM +0200, Peter Eisentraut wrote:
> The 002_pg_upgrade.pl test leaves a file delete_old_cluster.sh in the source
> directory.  In vpath builds, there shouldn't be any files written to the
> source directory.
>
> Note that the TAP tests run with the source directory as the current
> directory, so this is the result of pg_upgrade leaving its output files in
> the current directory.

Good catch, thanks.

> It looks like an addition of
> 
>     chdir $ENV{TESTOUTDIR};
> 
> could fix it.  Please check the patch.

I think that you mean TESTDIR, and not TESTOUTDIR?  Doing a chdir at
the beginning of the tests would cause pg_regress to fail as we would
not find anymore the regression schedule in a VPATH build, but it is
possible to chdir before the execution of pg_upgrade, like the
attached.
--
Michael
From 719b25ee7182340ae37c126ca7c6e392db2465cc Mon Sep 17 00:00:00 2001
From: Michael Paquier <mich...@paquier.xyz>
Date: Wed, 25 May 2022 16:24:23 +0900
Subject: [PATCH v2] Run pg_upgrade test in build directory

In passing, add names to tests that didn't have any yet.
---
 src/bin/pg_upgrade/t/002_pg_upgrade.pl | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
index 75ac768a96..117514e38f 100644
--- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl
+++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Cwd qw(abs_path getcwd);
+use Cwd qw(abs_path);
 use File::Basename qw(dirname);
 use File::Compare;
 
@@ -23,7 +23,7 @@ sub generate_db
 	}
 
 	$dbname .= $suffix;
-	$node->command_ok([ 'createdb', $dbname ]);
+	$node->command_ok([ 'createdb', $dbname ], 'created database');
 }
 
 # The test of pg_upgrade requires two clusters, an old one and a new one
@@ -71,7 +71,8 @@ if (defined($ENV{olddump}))
 
 	# Load the dump using the "postgres" database as "regression" does
 	# not exist yet, and we are done here.
-	$oldnode->command_ok([ 'psql', '-X', '-f', $olddumpfile, 'postgres' ]);
+	$oldnode->command_ok([ 'psql', '-X', '-f', $olddumpfile, 'postgres' ],
+		'loaded old dump file');
 }
 else
 {
@@ -136,7 +137,8 @@ if (defined($ENV{oldinstall}))
 			'psql', '-X',
 			'-f', "$srcdir/src/bin/pg_upgrade/upgrade_adapt.sql",
 			'regression'
-		]);
+		],
+		'ran adapt script');
 }
 
 # Initialize a new node for the upgrade.
@@ -202,6 +204,14 @@ if (defined($ENV{oldinstall}))
 	}
 }
 
+# In a VPATH build, we'll be started in the source directory, but we want
+# to run pg_upgrade in the build directory so that any files generated finish
+# in it, like delete_old_cluster.sh.
+if ($ENV{TESTDIR})
+{
+	chdir $ENV{TESTDIR} or die "could not chdir to \"$ENV{TESTDIR}\": $!";
+}
+
 # Upgrade the instance.
 $oldnode->stop;
 command_ok(
@@ -233,7 +243,8 @@ $newnode->command_ok(
 		'pg_dumpall', '--no-sync',
 		'-d',         $newnode->connstr('postgres'),
 		'-f',         "$tempdir/dump2.sql"
-	]);
+	],
+	'dump before running pg_upgrade');
 
 # Compare the two dumps, there should be no differences.
 my $compare_res = compare("$tempdir/dump1.sql", "$tempdir/dump2.sql");
-- 
2.36.1

Attachment: signature.asc
Description: PGP signature

Reply via email to