diff options
| author | Tom Lane | 2019-08-04 17:07:12 +0000 |
|---|---|---|
| committer | Tom Lane | 2019-08-04 17:07:12 +0000 |
| commit | 803466b6ffaa2e5b94d8ce4d7fffa8185f2a0184 (patch) | |
| tree | bcff820cbc633771ee7c3795a154f027917971dc /src/test/ldap | |
| parent | 489247b0e615592111226297a0564e11616361a5 (diff) | |
Avoid picking already-bound TCP ports in kerberos and ldap test suites.
src/test/kerberos and src/test/ldap need to run a private authentication
server of the relevant type, for which they need a free TCP port.
They were just picking a random port number in 48K-64K, which works
except when something's already using the particular port. Notably,
the probability of failure rises dramatically if one simply runs those
tests in a tight loop, because each test cycle leaves behind a bunch of
high ports that are transiently in TIME_WAIT state.
To fix, split out the code that PostgresNode.pm already had for
identifying a free TCP port number, so that it can be invoked to choose
a port for the KDC or LDAP server. This isn't 100% bulletproof, since
conceivably something else on the machine could grab the port between
the time we check and the time we actually start the server. But that's
a pretty short window, so in practice this should be good enough.
Back-patch to v11 where these test suites were added.
Patch by me, reviewed by Andrew Dunstan.
Discussion: https://postgr.es/m/3397.1564872168@sss.pgh.pa.us
Diffstat (limited to 'src/test/ldap')
| -rw-r--r-- | src/test/ldap/t/001_auth.pl | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/test/ldap/t/001_auth.pl b/src/test/ldap/t/001_auth.pl index 84a3300d964..47bc090f618 100644 --- a/src/test/ldap/t/001_auth.pl +++ b/src/test/ldap/t/001_auth.pl @@ -55,7 +55,7 @@ my $slapd_pidfile = "${TestLib::tmp_check}/slapd.pid"; my $slapd_logfile = "${TestLib::tmp_check}/slapd.log"; my $ldap_conf = "${TestLib::tmp_check}/ldap.conf"; my $ldap_server = 'localhost'; -my $ldap_port = int(rand() * 16384) + 49152; +my $ldap_port = get_free_port(); my $ldaps_port = $ldap_port + 1; my $ldap_url = "ldap://$ldap_server:$ldap_port"; my $ldaps_url = "ldaps://$ldap_server:$ldaps_port"; |
