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

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