path: root/t/
diff options
authorSZEDER Gábor <>2019-01-05 01:08:58 (GMT)
committerJunio C Hamano <>2019-01-07 17:24:06 (GMT)
commitfa840581805c794e93e03a83a944839f15ba08d0 (patch)
tree1d1ffe0cee02ae22700f1ac8dbcf023b880ec5f0 /t/
parent61f292db4e1df5b4e871cefffff3e9ec01ef2ade (diff)
test-lib-functions: introduce the 'test_set_port' helper function
Several test scripts run daemons like 'git-daemon' or Apache, and communicate with them through TCP sockets. To have unique ports where these daemons are accessible, the ports are usually the number of the corresponding test scripts, unless the user overrides them via environment variables, and thus all those tests and test libs contain more or less the same bit of one-liner boilerplate code to find out the port. The last patch in this series will make this a bit more complicated. Factor out finding the port for a daemon into the common helper function 'test_set_port' to avoid repeating ourselves. Take special care of test scripts with "low" numbers: - Test numbers below 1024 would result in a port that's only usable as root, so set their port to '10000 + test-nr' to make sure it doesn't interfere with other tests in the test suite. This makes the hardcoded port number in '' unnecessary, remove it. - The shell's arithmetic evaluation interprets numbers with leading zeros as octal values, which means that test number below 1000 and containing the digits 8 or 9 will trigger an error. Remove all leading zeros from the test numbers to prevent this. Note that the 'git p4' tests are unlike the other tests involving daemons in that: - '' doesn't use the test's number for unique port as is, but does a bit of additional arithmetic on top [1]. - The port is not overridable via an environment variable. With this patch even 'git p4' tests will use the test's number as default port, and it will be overridable via the P4DPORT environment variable. [1] Commit fc00233071 (git-p4 tests: refactor and cleanup, 2011-08-22) introduced that "unusual" unique port computation without explaining why it was necessary (as opposed to simply using the test number as is). It seems to be just unnecessary complication, and in any case that commit came way before the "test nr as unique port" got "standardized" for other daemons in commits c44132fcf3 (tests: auto-set git-daemon port, 2014-02-10), 3bb486e439 (tests: auto-set LIB_HTTPD_PORT from test name, 2014-02-10), and bf9d7df950 (t/ improve svnserve tests with parallel make test, 2017-12-01). Signed-off-by: SZEDER Gábor <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 't/')
1 files changed, 1 insertions, 1 deletions
diff --git a/t/ b/t/
index f98de95..41eb1e3 100644
--- a/t/
+++ b/t/
@@ -28,7 +28,7 @@ then
test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
+test_set_port LIB_GIT_DAEMON_PORT