Prevent port collisions between concurrent TAP tests
authorAndrew Dunstan <[email protected]>
Tue, 22 Nov 2022 15:35:04 +0000 (10:35 -0500)
committerAndrew Dunstan <[email protected]>
Tue, 22 Nov 2022 15:52:42 +0000 (10:52 -0500)
commitbaa78ff5404c9d870309207edbb168e1ec7c5af7
tree98b8798003185bfff89710411b0bee4da7235b82
parente9c8907c3b39de09618c3f62c499f45c22ca8ce7
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[email protected]
src/Makefile.global.in
src/test/perl/PostgresNode.pm