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

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