Merge 'poll-busy-wait' into HEAD
[git/mingw/4msysgit.git] / t / lib-git-daemon.sh
blob394b06b32f838463221e9c2f49380fd9eb08bb9d
1 # Shell library to run git-daemon in tests. Ends the test early if
2 # GIT_TEST_GIT_DAEMON is not set.
4 # Usage:
6 # . ./test-lib.sh
7 # . "$TEST_DIRECTORY"/lib-git-daemon.sh
8 # start_git_daemon
10 # test_expect_success '...' '
11 # ...
12 # '
14 # test_expect_success ...
16 # stop_git_daemon
17 # test_done
19 if test -z "$GIT_TEST_GIT_DAEMON"
20 then
21 skip_all="git-daemon testing disabled (define GIT_TEST_GIT_DAEMON to enable)"
22 test_done
25 LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-'8121'}
27 GIT_DAEMON_PID=
28 GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
29 GIT_DAEMON_URL=git://127.0.0.1:$LIB_GIT_DAEMON_PORT
31 start_git_daemon() {
32 if test -n "$GIT_DAEMON_PID"
33 then
34 error "start_git_daemon already called"
37 mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
39 trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
41 say >&3 "Starting git daemon ..."
42 mkfifo git_daemon_output
43 git daemon --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
44 --reuseaddr --verbose \
45 --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
46 "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
47 >&3 2>git_daemon_output &
48 GIT_DAEMON_PID=$!
50 read line <&7
51 echo >&4 "$line"
52 cat <&7 >&4 &
53 } 7<git_daemon_output &&
55 # Check expected output
56 if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
57 then
58 kill "$GIT_DAEMON_PID"
59 wait "$GIT_DAEMON_PID"
60 trap 'die' EXIT
61 error "git daemon failed to start"
65 stop_git_daemon() {
66 if test -z "$GIT_DAEMON_PID"
67 then
68 return
71 trap 'die' EXIT
73 # kill git-daemon child of git
74 say >&3 "Stopping git daemon ..."
75 kill "$GIT_DAEMON_PID"
76 wait "$GIT_DAEMON_PID" >&3 2>&4
77 ret=$?
78 # expect exit with status 143 = 128+15 for signal TERM=15
79 if test $ret -ne 143
80 then
81 error "git daemon exited with status: $ret"
83 GIT_DAEMON_PID=
84 rm -f git_daemon_output