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

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