tmz / rpms / git

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