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

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