diff --git c/meson.build i/meson.build
index cdf55957629..bed36153c7b 100644
--- c/meson.build
+++ i/meson.build
@@ -3414,6 +3414,8 @@ test_initdb_template = meson.build_root() / 'tmp_install' / 'initdb-template'
 test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
 test_env.set('INITDB_TEMPLATE', test_initdb_template)
+# for Cluster.pm's portlock logic
+test_env.set('top_builddir', meson.build_root())
 
 # Add the temporary installation to the library search path on platforms where
 # that works (everything but windows, basically). On windows everything
diff --git c/src/test/perl/PostgreSQL/Test/Cluster.pm i/src/test/perl/PostgreSQL/Test/Cluster.pm
index f31af70edb6..01ddaec4502 100644
--- c/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ i/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -169,8 +169,7 @@ INIT
 	# Otherwise, try to use a directory at the top of the build tree
 	# or as a last resort use the tmp_check directory
 	my $build_dir =
-		 $ENV{MESON_BUILD_ROOT}
-	  || $ENV{top_builddir}
+		 $ENV{top_builddir}
 	  || $PostgreSQL::Test::Utils::tmp_check;
 	$portdir ||= "$build_dir/portlock";
 	$portdir =~ s!\\!/!g;
