Blame SOURCES/0002-t-lib-git-daemon-try-harder-to-find-a-port.patch

c9cf78
From 16750d024ce038b019ab2e9ee5639901e445af37 Mon Sep 17 00:00:00 2001
c9cf78
From: Todd Zullinger <tmz@pobox.com>
c9cf78
Date: Fri, 26 Aug 2022 18:28:44 -0400
c9cf78
Subject: [PATCH] t/lib-git-daemon: try harder to find a port
c9cf78
c9cf78
As with the previous commit, try harder to find an open port to avoid
c9cf78
intermittent failures on busy/shared build systems.
c9cf78
c9cf78
By default, we make 3 attempts.  This may be overridden by setting
c9cf78
GIT_TEST_START_GIT_DAEMON_TRIES to a different value.
c9cf78
c9cf78
Signed-off-by: Todd Zullinger <tmz@pobox.com>
c9cf78
---
c9cf78
 t/lib-git-daemon.sh | 60 ++++++++++++++++++++++++++++-----------------
c9cf78
 1 file changed, 37 insertions(+), 23 deletions(-)
c9cf78
c9cf78
diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh
c9cf78
index e62569222b..c3e8dda9ff 100644
c9cf78
--- a/t/lib-git-daemon.sh
c9cf78
+++ b/t/lib-git-daemon.sh
c9cf78
@@ -51,30 +51,44 @@ start_git_daemon() {
c9cf78
 		registered_stop_git_daemon_atexit_handler=AlreadyDone
c9cf78
 	fi
c9cf78
 
c9cf78
-	say >&3 "Starting git daemon ..."
c9cf78
-	mkfifo git_daemon_output
c9cf78
-	${LIB_GIT_DAEMON_COMMAND:-git daemon} \
c9cf78
-		--listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
c9cf78
-		--reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \
c9cf78
-		--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
c9cf78
-		"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
c9cf78
-		>&3 2>git_daemon_output &
c9cf78
-	GIT_DAEMON_PID=$!
c9cf78
-	{
c9cf78
-		read -r line <&7
c9cf78
-		printf "%s\n" "$line" >&4
c9cf78
-		cat <&7 >&4 &
c9cf78
-	} 7
c9cf78
+	i=0
c9cf78
+	while test $i -lt ${GIT_TEST_START_GIT_DAEMON_TRIES:-3}
c9cf78
+	do
c9cf78
+		say >&3 "Starting git daemon on port $LIB_GIT_DAEMON_PORT ..."
c9cf78
+		mkfifo git_daemon_output
c9cf78
+		${LIB_GIT_DAEMON_COMMAND:-git daemon} \
c9cf78
+			--listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
c9cf78
+			--reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \
c9cf78
+			--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
c9cf78
+			"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
c9cf78
+			>&3 2>git_daemon_output &
c9cf78
+		GIT_DAEMON_PID=$!
c9cf78
+		{
c9cf78
+			read -r line <&7
c9cf78
+			printf "%s\n" "$line" >&4
c9cf78
+			cat <&7 >&4 &
c9cf78
+		} 7
c9cf78
 
c9cf78
-	# Check expected output
c9cf78
-	if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
c9cf78
-	then
c9cf78
-		kill "$GIT_DAEMON_PID"
c9cf78
-		wait "$GIT_DAEMON_PID"
c9cf78
-		unset GIT_DAEMON_PID
c9cf78
-		test_skip_or_die GIT_TEST_GIT_DAEMON \
c9cf78
-			"git daemon failed to start"
c9cf78
-	fi
c9cf78
+		# Check expected output
c9cf78
+		output="$(expr "$line" : "\[[0-9]*\] \(.*\)")"
c9cf78
+		# Return if found
c9cf78
+		test x"$output" = x"Ready to rumble" && return
c9cf78
+		# Increment port for retry if not found
c9cf78
+		LIB_GIT_DAEMON_PORT=$(($LIB_GIT_DAEMON_PORT + 1))
c9cf78
+		export LIB_GIT_DAEMON_PORT
c9cf78
+		GIT_DAEMON_HOST_PORT=127.0.0.1:$LIB_GIT_DAEMON_PORT
c9cf78
+		GIT_DAEMON_URL=git://$GIT_DAEMON_HOST_PORT
c9cf78
+		# unset GIT_DAEMON_PID; remove the fifo & pid file
c9cf78
+		GIT_DAEMON_PID=
c9cf78
+		rm -f git_daemon_output "$GIT_DAEMON_PIDFILE"
c9cf78
+	done
c9cf78
+
c9cf78
+	# Clean up and return failure
c9cf78
+	kill "$GIT_DAEMON_PID"
c9cf78
+	wait "$GIT_DAEMON_PID"
c9cf78
+	unset GIT_DAEMON_PID
c9cf78
+	test_skip_or_die GIT_TEST_GIT_DAEMON \
c9cf78
+		"git daemon failed to start"
c9cf78
 }
c9cf78
 
c9cf78
 stop_git_daemon() {