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

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