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

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