Blame SOURCES/0003-t-lib-git-svn-try-harder-to-find-a-port.patch

4b9f28
From aa5105dc115b43edc6c9c11714b092583f1221aa Mon Sep 17 00:00:00 2001
4b9f28
From: Todd Zullinger <tmz@pobox.com>
4b9f28
Date: Fri, 26 Aug 2022 18:28:44 -0400
4b9f28
Subject: [PATCH] t/lib-git-svn: try harder to find a port
4b9f28
4b9f28
As with the previous commits, try harder to find an open port to avoid
4b9f28
intermittent failures on busy/shared build systems.
4b9f28
4b9f28
By default, we make 3 attempts.  This may be overridden by setting
4b9f28
GIT_TEST_START_SVNSERVE_TRIES to a different value.
4b9f28
4b9f28
Run svnserve in daemon mode and use 'test_atexit' to stop it.  This is
4b9f28
cleaner than running in the foreground with --listen-once and having to
4b9f28
manage the PID ourselves.
4b9f28
4b9f28
Signed-off-by: Todd Zullinger <tmz@pobox.com>
4b9f28
---
4b9f28
 t/lib-git-svn.sh                    | 34 +++++++++++++++++++++++++----
4b9f28
 t/t9113-git-svn-dcommit-new-file.sh |  1 -
4b9f28
 2 files changed, 30 insertions(+), 5 deletions(-)
4b9f28
4b9f28
diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
4b9f28
index ea28971e8e..04e660e2ba 100644
4b9f28
--- a/t/lib-git-svn.sh
4b9f28
+++ b/t/lib-git-svn.sh
4b9f28
@@ -17,6 +17,7 @@ fi
96a48d
 GIT_DIR=$PWD/.git
96a48d
 GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
96a48d
 SVN_TREE=$GIT_SVN_DIR/svn-tree
96a48d
+SVNSERVE_PIDFILE="$PWD"/daemon.pid
96a48d
 test_set_port SVNSERVE_PORT
96a48d
 
96a48d
 svn >/dev/null 2>&1
4b9f28
@@ -119,10 +120,35 @@ require_svnserve () {
96a48d
 }
96a48d
 
96a48d
 start_svnserve () {
96a48d
-	svnserve --listen-port $SVNSERVE_PORT \
96a48d
-		 --root "$rawsvnrepo" \
96a48d
-		 --listen-once \
96a48d
-		 --listen-host 127.0.0.1 &
96a48d
+	test_atexit stop_svnserve
96a48d
+
96a48d
+	i=0
96a48d
+	while test $i -lt ${GIT_TEST_START_SVNSERVE_TRIES:-3}
96a48d
+	do
96a48d
+		say >&3 "Starting svnserve on port $SVNSERVE_PORT ..."
96a48d
+		svnserve --listen-port $SVNSERVE_PORT \
96a48d
+			 --root "$rawsvnrepo" \
96a48d
+			 --daemon --pid-file="$SVNSERVE_PIDFILE" \
96a48d
+			 --listen-host 127.0.0.1
96a48d
+		ret=$?
96a48d
+		# increment port and retry if unsuccessful
96a48d
+		if test $ret -ne 0
96a48d
+		then
96a48d
+			SVNSERVE_PORT=$(($SVNSERVE_PORT + 1))
96a48d
+			export SVNSERVE_PORT
96a48d
+		else
96a48d
+			break
96a48d
+		fi
96a48d
+	done
96a48d
+}
96a48d
+
96a48d
+stop_svnserve () {
96a48d
+	say >&3 "Stopping svnserve ..."
96a48d
+	SVNSERVE_PID="$(cat "$SVNSERVE_PIDFILE")"
96a48d
+	if test -n "$SVNSERVE_PID"
96a48d
+	then
96a48d
+		kill "$SVNSERVE_PID" 2>/dev/null
96a48d
+	fi
96a48d
 }
96a48d
 
4b9f28
 prepare_utf8_locale () {
4b9f28
diff --git a/t/t9113-git-svn-dcommit-new-file.sh b/t/t9113-git-svn-dcommit-new-file.sh
4b9f28
index e8479cec7a..5925891f5d 100755
4b9f28
--- a/t/t9113-git-svn-dcommit-new-file.sh
4b9f28
+++ b/t/t9113-git-svn-dcommit-new-file.sh
4b9f28
@@ -28,7 +28,6 @@ test_expect_success 'create files in new directory with dcommit' "
96a48d
 	echo hello > git-new-dir/world &&
96a48d
 	git update-index --add git-new-dir/world &&
96a48d
 	git commit -m hello &&
96a48d
-	start_svnserve &&
96a48d
 	git svn dcommit
96a48d
 	"
96a48d