git-p4: add p4d timeout in tests

In rare cases p4d seems to hang. This watchdog will kill the p4d process after 300s in any case. That means each individual git p4 test needs to finish before 300s or it will fail. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Jeff King <peff@peff.net>

Lars Schneider committed Nov 19, 2015 at 09:58 UTC 842addef70e41f8bb8a16f4d9084432301c3f50f
1 file changed +19 -1
t/lib-git-p4.sh
+19 -1
@@ -10,6 +10,10 @@ TEST_NO_CREATE_REPO=NoThanks
10 # here the maximal retry timeout in seconds.
11 RETRY_TIMEOUT=60
12
13 +# Sometimes p4d seems to hang. Terminate the p4d process automatically after
14 +# the defined timeout in seconds.
15 +P4D_TIMEOUT=300
16 +
17 . ./test-lib.sh
18
19 if ! test_have_prereq PYTHON
@@ -94,6 +98,19 @@ start_p4d() {
98 # will be caught with the "kill -0" check below.
99 i=${P4D_START_PATIENCE:-300}
100 pid=$(cat "$pidfile")
101 +
102 + timeout=$(($(time_in_seconds) + $P4D_TIMEOUT))
103 + while true
104 + do
105 + if test $(time_in_seconds) -gt $timeout
106 + then
107 + kill -9 $pid
108 + exit 1
109 + fi
110 + sleep 1
111 + done &
112 + watchdog_pid=$!
113 +
114 ready=
115 while test $i -gt 0
116 do
@@ -156,7 +173,8 @@ kill_p4d() {
173 retry_until_fail kill -9 $pid
174 # complain if it would not die
175 test_must_fail kill $pid >/dev/null 2>&1 &&
159 - rm -rf "$db" "$cli" "$pidfile"
176 + rm -rf "$db" "$cli" "$pidfile" &&
177 + retry_until_fail kill -9 $watchdog_pid
178 }
179
180 cleanup_git() {