Prevent port collisions between concurrent TAP tests
authorAndrew Dunstan <andrew@dunslane.net>
Tue, 22 Nov 2022 15:30:42 +0000 (10:30 -0500)
committerAndrew Dunstan <andrew@dunslane.net>
Tue, 22 Nov 2022 15:51:13 +0000 (10:51 -0500)
commit153e21567750d37b031123d3bbf14f9e2434f4b2
tree4a05f4d16b7fff192d2df591787a66b395f5499a
parent1118a8d2c4f5b6dccf1845c73403d036df679648
Prevent port collisions between concurrent TAP tests

Currently there is a race condition where if concurrent TAP tests both
test that they can open a port they will assume that it is free and use
it, causing one of them to fail. To prevent this we record a reservation
using an exclusive lock, and any TAP test that discovers a reservation
checks to see if the reserving process is still alive, and looks for
another free port if it is.

Ports are reserved in a directory set by the environment setting
PG_TEST_PORT_DIR, or if that doesn't exist a subdirectory of the top
build directory as set by Makefile.global, or its own
tmp_check directory.

The prove_check recipe in Makefile.global.in is extended to export
top_builddir to the TAP tests. This was already exported by the
prove_installcheck recipes.

Per complaint from Andres Freund

Backpatched from 9b4eafcaf4 to all live branches

Discussion: https://postgr.es/m/20221002164931.d57hlutrcz4d2zi7@awork3.anarazel.de
src/Makefile.global.in
src/test/perl/PostgreSQL/Test/Cluster.pm