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>
Pete Wyckoff committed
Jun 27, 2012 at 22:48 UTC
f89f35a9d41535b3e8ebe500489634e623ae8d83
1 file changed
+32
-6
t/lib-git-p4.sh
+32
-6
@@ -33,17 +33,42 @@ pidfile="$TRASH_DIRECTORY/p4d.pid"
33
34
start_p4d() {
35
mkdir -p "$db" "$cli" "$git" &&
36
+ rm -f "$pidfile" &&
37
(
38
p4d -q -r "$db" -p $P4DPORT &
39
echo $! >"$pidfile"
40
) &&
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
61
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
72
(
73
cd "$cli" &&
74
p4 client -i <<-EOF
@@ -53,6 +78,7 @@ start_p4d() {
78
View: //depot/... //client/...
79
EOF
80
)
81
+ return 0
82
}
83
84
kill_p4d() {