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

9574ab
From aa5105dc115b43edc6c9c11714b092583f1221aa 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-svn: try harder to find a port
9574ab
9574ab
As with the previous commits, 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_SVNSERVE_TRIES to a different value.
9574ab
9574ab
Run svnserve in daemon mode and use 'test_atexit' to stop it.  This is
9574ab
cleaner than running in the foreground with --listen-once and having to
9574ab
manage the PID ourselves.
9574ab
9574ab
Signed-off-by: Todd Zullinger <tmz@pobox.com>
9574ab
---
9574ab
 t/lib-git-svn.sh                    | 34 +++++++++++++++++++++++++----
9574ab
 t/t9113-git-svn-dcommit-new-file.sh |  1 -
9574ab
 2 files changed, 30 insertions(+), 5 deletions(-)
9574ab
9574ab
diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
9574ab
index ea28971e8e..04e660e2ba 100644
9574ab
--- a/t/lib-git-svn.sh
9574ab
+++ b/t/lib-git-svn.sh
9574ab
@@ -17,6 +17,7 @@ fi
9574ab
 GIT_DIR=$PWD/.git
9574ab
 GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
9574ab
 SVN_TREE=$GIT_SVN_DIR/svn-tree
9574ab
+SVNSERVE_PIDFILE="$PWD"/daemon.pid
9574ab
 test_set_port SVNSERVE_PORT
9574ab
 
9574ab
 svn >/dev/null 2>&1
9574ab
@@ -119,10 +120,35 @@ require_svnserve () {
9574ab
 }
9574ab
 
9574ab
 start_svnserve () {
9574ab
-	svnserve --listen-port $SVNSERVE_PORT \
9574ab
-		 --root "$rawsvnrepo" \
9574ab
-		 --listen-once \
9574ab
-		 --listen-host 127.0.0.1 &
9574ab
+	test_atexit stop_svnserve
9574ab
+
9574ab
+	i=0
9574ab
+	while test $i -lt ${GIT_TEST_START_SVNSERVE_TRIES:-3}
9574ab
+	do
9574ab
+		say >&3 "Starting svnserve on port $SVNSERVE_PORT ..."
9574ab
+		svnserve --listen-port $SVNSERVE_PORT \
9574ab
+			 --root "$rawsvnrepo" \
9574ab
+			 --daemon --pid-file="$SVNSERVE_PIDFILE" \
9574ab
+			 --listen-host 127.0.0.1
9574ab
+		ret=$?
9574ab
+		# increment port and retry if unsuccessful
9574ab
+		if test $ret -ne 0
9574ab
+		then
9574ab
+			SVNSERVE_PORT=$(($SVNSERVE_PORT + 1))
9574ab
+			export SVNSERVE_PORT
9574ab
+		else
9574ab
+			break
9574ab
+		fi
9574ab
+	done
9574ab
+}
9574ab
+
9574ab
+stop_svnserve () {
9574ab
+	say >&3 "Stopping svnserve ..."
9574ab
+	SVNSERVE_PID="$(cat "$SVNSERVE_PIDFILE")"
9574ab
+	if test -n "$SVNSERVE_PID"
9574ab
+	then
9574ab
+		kill "$SVNSERVE_PID" 2>/dev/null
9574ab
+	fi
9574ab
 }
9574ab
 
9574ab
 prepare_utf8_locale () {
9574ab
diff --git a/t/t9113-git-svn-dcommit-new-file.sh b/t/t9113-git-svn-dcommit-new-file.sh
9574ab
index e8479cec7a..5925891f5d 100755
9574ab
--- a/t/t9113-git-svn-dcommit-new-file.sh
9574ab
+++ b/t/t9113-git-svn-dcommit-new-file.sh
9574ab
@@ -28,7 +28,6 @@ test_expect_success 'create files in new directory with dcommit' "
9574ab
 	echo hello > git-new-dir/world &&
9574ab
 	git update-index --add git-new-dir/world &&
9574ab
 	git commit -m hello &&
9574ab
-	start_svnserve &&
9574ab
 	git svn dcommit
9574ab
 	"
9574ab