git-p4: add trap to kill p4d on test exit

Sometimes the "prove" test runner hangs on test exit because p4d is still running. Add a trap to always kill "p4d" on test exit. You can reproduce the problem by commenting "P4D_TIMEOUT" in "lib-git-p4.sh" and running "prove ./t9800-git-p4-basic.sh". Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Jeff King <peff@peff.net>

Lars Schneider committed Nov 19, 2015 at 09:58 UTC dfe90e8b528be4d9668b1bdc6329f8227cbf307a
1 file changed +9
t/lib-git-p4.sh
+9
@@ -74,6 +74,15 @@ cli="$TRASH_DIRECTORY/cli"
74 git="$TRASH_DIRECTORY/git"
75 pidfile="$TRASH_DIRECTORY/p4d.pid"
76
77 +# Sometimes "prove" seems to hang on exit because p4d is still running
78 +cleanup() {
79 + if test -f "$pidfile"
80 + then
81 + kill -9 $(cat "$pidfile") 2>/dev/null && exit 255
82 + fi
83 +}
84 +trap cleanup EXIT
85 +
86 # git p4 submit generates a temp file, which will
87 # not get cleaned up if the submission fails. Don't
88 # clutter up /tmp on the test machine.