Skip to content

Commit f89f35a

Browse files
Pete Wyckoffgitster
authored andcommitted
git p4 test: wait longer for p4d to start and test its pid
Running tests at high parallelism on a slow machine, 5 sec is not enough to wait for p4d to start. Change it to 5 minutes, adding an environment variable P4D_START_PATIENCE to shrink that if needed in automated test environments. Also check if the pid of the p4d that we started is still around. If not, quit waiting for it immediately. Remove all the confusing && chaining and simplify the code. Thanks-to: Junio C Hamano <gitster@pobox.com> Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4c8a9db commit f89f35a

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

t/lib-git-p4.sh

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,42 @@ pidfile="$TRASH_DIRECTORY/p4d.pid"
3333

3434
start_p4d() {
3535
mkdir -p "$db" "$cli" "$git" &&
36+
rm -f "$pidfile" &&
3637
(
3738
p4d -q -r "$db" -p $P4DPORT &
3839
echo $! >"$pidfile"
3940
) &&
40-
for i in 1 2 3 4 5 ; do
41-
p4 info >/dev/null 2>&1 && break || true &&
42-
echo waiting for p4d to start &&
41+
42+
# This gives p4d a long time to start up, as it can be
43+
# quite slow depending on the machine. Set this environment
44+
# variable to something smaller to fail faster in, say,
45+
# an automated test setup. If the p4d process dies, that
46+
# will be caught with the "kill -0" check below.
47+
i=${P4D_START_PATIENCE:-300}
48+
pid=$(cat "$pidfile")
49+
ready=
50+
while test $i -gt 0
51+
do
52+
# succeed when p4 client commands start to work
53+
if p4 info >/dev/null 2>&1
54+
then
55+
ready=true
56+
break
57+
fi
58+
# fail if p4d died
59+
kill -0 $pid 2>/dev/null || break
60+
echo waiting for p4d to start
4361
sleep 1
44-
done &&
45-
# complain if it never started
46-
p4 info >/dev/null &&
62+
i=$(( $i - 1 ))
63+
done
64+
65+
if test -z "$ready"
66+
then
67+
# p4d failed to start
68+
return 1
69+
fi
70+
71+
# build a client
4772
(
4873
cd "$cli" &&
4974
p4 client -i <<-EOF
@@ -53,6 +78,7 @@ start_p4d() {
5378
View: //depot/... //client/...
5479
EOF
5580
)
81+
return 0
5682
}
5783

5884
kill_p4d() {

0 commit comments

Comments
 (0)