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

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