Blame SOURCES/0001-t-lib-httpd-try-harder-to-find-a-port-for-apache.patch

96a48d
From aedeaaf788bd8a7fc5a1887196b6f6d8a5c31362 Mon Sep 17 00:00:00 2001
96a48d
From: Todd Zullinger <tmz@pobox.com>
96a48d
Date: Sun, 21 Aug 2022 13:49:57 -0400
96a48d
Subject: [PATCH] t/lib-httpd: try harder to find a port for apache
96a48d
MIME-Version: 1.0
96a48d
Content-Type: text/plain; charset=UTF-8
96a48d
Content-Transfer-Encoding: 8bit
96a48d
96a48d
When running multiple builds concurrently, tests which run daemons, like
96a48d
apache httpd, sometimes conflict with each other, leading to spurious
96a48d
failures:
96a48d
96a48d
    ++ /usr/sbin/httpd -d '/tmp/git-t.ck9I/trash directory.t9118-git-svn-funky-branch-names/httpd' \
96a48d
       -f /builddir/build/BUILD/git-2.37.2/t/lib-httpd/apache.conf -DDAV -DSVN -c 'Listen 127.0.0.1:9118' \
96a48d
       -k start
96a48d
    (98)Address already in use: AH00072: make_sock: could not bind to address 127.0.0.1:9118
96a48d
    no listening sockets available, shutting down
96a48d
    AH00015: Unable to open logs
96a48d
    ++ test 1 -ne 0
96a48d
96a48d
Try a bit harder to find an open port to use to avoid these intermittent
96a48d
failures.  If we fail to start httpd, increment the port number and try
96a48d
again.  By default, we make 3 attempts.  This may be overridden by
96a48d
setting GIT_TEST_START_HTTPD_TRIES to a different value.
96a48d
96a48d
Helped-by: Ondřej Pohořelský <opohorel@redhat.com>
96a48d
Signed-off-by: Todd Zullinger <tmz@pobox.com>
96a48d
---
96a48d
 t/lib-httpd.sh | 29 ++++++++++++++++++-----------
96a48d
 1 file changed, 18 insertions(+), 11 deletions(-)
96a48d
96a48d
diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh
96a48d
index 1f6b9b08d1..9279dcd659 100644
96a48d
--- a/t/lib-httpd.sh
96a48d
+++ b/t/lib-httpd.sh
96a48d
@@ -175,19 +175,26 @@ prepare_httpd() {
96a48d
 }
96a48d
 
96a48d
 start_httpd() {
96a48d
-	prepare_httpd >&3 2>&4
96a48d
-
96a48d
 	test_atexit stop_httpd
96a48d
 
96a48d
-	"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
96a48d
-		-f "$TEST_PATH/apache.conf" $HTTPD_PARA \
96a48d
-		-c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
96a48d
-		>&3 2>&4
96a48d
-	if test $? -ne 0
96a48d
-	then
96a48d
-		cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
96a48d
-		test_skip_or_die GIT_TEST_HTTPD "web server setup failed"
96a48d
-	fi
96a48d
+	i=0
96a48d
+	while test $i -lt ${GIT_TEST_START_HTTPD_TRIES:-3}
96a48d
+	do
96a48d
+		i=$(($i + 1))
96a48d
+		prepare_httpd >&3 2>&4
96a48d
+		say >&3 "Starting httpd on port $LIB_HTTPD_PORT"
96a48d
+		"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
96a48d
+			-f "$TEST_PATH/apache.conf" $HTTPD_PARA \
96a48d
+			-c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
96a48d
+			>&3 2>&4
96a48d
+		test $? -eq 0 && return
96a48d
+		LIB_HTTPD_PORT=$(($LIB_HTTPD_PORT + 1))
96a48d
+		export LIB_HTTPD_PORT
96a48d
+		# clean up modules symlink, prepare_httpd will re-create it
96a48d
+		rm -f "$HTTPD_ROOT_PATH/modules"
96a48d
+	done
96a48d
+	cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
96a48d
+	test_skip_or_die GIT_TEST_HTTPD "web server setup failed"
96a48d
 }
96a48d
 
96a48d
 stop_httpd() {