From ca99ec5ff7f23308279098f26ac58a8e927d2646 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyoga.ntt@gmail.com>
Date: Fri, 1 May 2020 09:54:21 +0900
Subject: [PATCH 2/2] Don't setup tablespace directory while testing pg_upgrade

While make check of pg_upgrade, output directory is placed at a
separate place from ordinary tmp_install. However Makefile
reinitializes tablespace directory under the ordinary tmp_install,
which may be being used by concurrent backend make check.  The
dedicate output directory doesn't need initialization so we just avoid
tablespace initialization for the case.
---
 GNUmakefile.in               | 4 ++--
 src/bin/pg_upgrade/test.sh   | 2 +-
 src/test/regress/GNUmakefile | 4 +++-
 src/tools/msvc/vcregress.pl  | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/GNUmakefile.in b/GNUmakefile.in
index ee636e3b50..943878e99b 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -63,8 +63,8 @@ distclean maintainer-clean:
 	@rm -rf autom4te.cache/
 	rm -f config.cache config.log config.status GNUmakefile
 
-check check-tests installcheck installcheck-parallel installcheck-tests: CHECKPREP_TOP=src/test/regress
-check check-tests installcheck installcheck-parallel installcheck-tests: submake-generated-headers
+check check-tests installcheck installcheck-parallel installcheck-parallel-notspsetup installcheck-tests: CHECKPREP_TOP=src/test/regress
+check check-tests installcheck installcheck-parallel installcheck-parallel-notspsetup installcheck-tests: submake-generated-headers
 	$(MAKE) -C src/test/regress $@
 
 $(call recurse,check-world,src/test src/pl src/interfaces/ecpg contrib src/bin,check)
diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index 10a28d8133..7be62bd49a 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -166,7 +166,7 @@ createdb "regression$dbname1" || createdb_status=$?
 createdb "regression$dbname2" || createdb_status=$?
 createdb "regression$dbname3" || createdb_status=$?
 
-if "$MAKE" -C "$oldsrc" installcheck-parallel; then
+if "$MAKE" -C "$oldsrc" installcheck-parallel-notspsetup; then
 	oldpgversion=`psql -X -A -t -d regression -c "SHOW server_version_num"`
 
 	# before dumping, get rid of objects not existing in later versions
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index 1a3164065f..b8681dbd17 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -137,7 +137,9 @@ check-tests: all tablespace-setup | temp-install
 installcheck: all tablespace-setup
 	$(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/serial_schedule $(EXTRA_TESTS)
 
-installcheck-parallel: all tablespace-setup
+installcheck-parallel: tablespace-setup installcheck-parallel-notspsetup
+
+installcheck-parallel-notspsetup: all
 	$(pg_regress_installcheck) $(REGRESS_OPTS) --schedule=$(srcdir)/parallel_schedule $(MAXCONNOPT) $(EXTRA_TESTS)
 
 installcheck-tests: all tablespace-setup
diff --git a/src/tools/msvc/vcregress.pl b/src/tools/msvc/vcregress.pl
index 74d37a31de..4516db1f38 100644
--- a/src/tools/msvc/vcregress.pl
+++ b/src/tools/msvc/vcregress.pl
@@ -115,7 +115,6 @@ sub installcheck_internal
 		"--no-locale");
 	push(@args, $maxconn) if $maxconn;
 	push(@args, @EXTRA_REGRESS_OPTS);
-	CleanupTablespaceDirectory();
 	system(@args);
 	my $status = $? >> 8;
 	exit $status if $status;
@@ -125,6 +124,7 @@ sub installcheck_internal
 sub installcheck
 {
 	my $schedule = shift || 'serial';
+	CleanupTablespaceDirectory();
 	installcheck_internal($schedule);
 	return;
 }
-- 
2.18.2

