pgsql: Prevent port collisions between concurrent TAP tests

Started by Andrew Dunstanover 3 years ago4 messagescomitters
Jump to latest
#1Andrew Dunstan
andrew@dunslane.net

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: /messages/by-id/20221002164931.d57hlutrcz4d2zi7@awork3.anarazel.de

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/870d6218e6d73dca8ec37b4d7f5076b74eeaeffe

Modified Files
--------------
src/Makefile.global.in | 1 +
src/test/perl/PostgresNode.pm | 64 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 60 insertions(+), 5 deletions(-)

#2Michael Paquier
michael@paquier.xyz
In reply to: Andrew Dunstan (#1)
Re: pgsql: Prevent port collisions between concurrent TAP tests

Hi Andrew,

On Tue, Nov 22, 2022 at 03:56:43PM +0000, Andrew Dunstan wrote:

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.

Wouldn't it be better to update .gitgnore at the root of the source
folder to discard portlock/ so as we will never include by accident in
a commit?

Thanks,
--
Michael

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Michael Paquier (#2)
Re: pgsql: Prevent port collisions between concurrent TAP tests

On 2022-11-26 Sa 06:15, Michael Paquier wrote:

Hi Andrew,

On Tue, Nov 22, 2022 at 03:56:43PM +0000, Andrew Dunstan wrote:

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.

Wouldn't it be better to update .gitgnore at the root of the source
folder to discard portlock/ so as we will never include by accident in
a commit?

Yes, good point. Will do.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#4Michael Paquier
michael@paquier.xyz
In reply to: Andrew Dunstan (#3)
Re: pgsql: Prevent port collisions between concurrent TAP tests

On Sat, Nov 26, 2022 at 07:40:52AM -0500, Andrew Dunstan wrote:

Yes, good point. Will do.

Thanks.
--
Michael