git-daemon: use 'test_atexit` to stop 'git-daemon'
Use 'test_atexit' to run cleanup commands to stop 'git-daemon' at the end of the test script or upon interrupt or failure, as it is shorter, simpler, and more robust than registering such cleanup commands in the trap on EXIT in the test scripts. Note that in 't5570-git-daemon.sh' the daemon is stopped and then re-started in the middle of the test script; take care that the cleanup functions to stop the daemon are only registered once. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Mar 13, 2019 at 13:24 UTC
9f82b2a6a754c7cec37282d954208b4b429a3a05
3 files changed
+9
-7
t/interop/i5500-git-daemon.sh
-1
@@ -37,5 +37,4 @@ test_expect_success "fetch with $VERSION_B" '
37
test_cmp expect actual
38
'
39
40
-stop_git_daemon
40
test_done
t/lib-git-daemon.sh
+9
-5
@@ -13,7 +13,6 @@
13
#
14
# test_expect_success ...
15
#
16
-# stop_git_daemon
16
# test_done
17
18
test_tristate GIT_TEST_GIT_DAEMON
@@ -36,6 +35,7 @@ GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
35
GIT_DAEMON_HOST_PORT=127.0.0.1:$LIB_GIT_DAEMON_PORT
36
GIT_DAEMON_URL=git://$GIT_DAEMON_HOST_PORT
37
38
+registered_stop_git_daemon_atexit_handler=
39
start_git_daemon() {
40
if test -n "$GIT_DAEMON_PID"
41
then
@@ -44,7 +44,13 @@ start_git_daemon() {
44
45
mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
46
47
- trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
47
+ # One of the test scripts stops and then re-starts 'git daemon'.
48
+ # Don't register and then run the same atexit handlers several times.
49
+ if test -z "$registered_stop_git_daemon_atexit_handler"
50
+ then
51
+ test_atexit 'stop_git_daemon'
52
+ registered_stop_git_daemon_atexit_handler=AlreadyDone
53
+ fi
54
55
say >&3 "Starting git daemon ..."
56
mkfifo git_daemon_output
@@ -66,7 +72,7 @@ start_git_daemon() {
72
then
73
kill "$GIT_DAEMON_PID"
74
wait "$GIT_DAEMON_PID"
69
- trap 'die' EXIT
75
+ unset GIT_DAEMON_PID
76
test_skip_or_die $GIT_TEST_GIT_DAEMON \
77
"git daemon failed to start"
78
fi
@@ -78,8 +84,6 @@ stop_git_daemon() {
84
return
85
fi
86
81
- trap 'die' EXIT
82
-
87
# kill git-daemon child of git
88
say >&3 "Stopping git daemon ..."
89
kill "$GIT_DAEMON_PID"
t/t5570-git-daemon.sh
-1
@@ -198,5 +198,4 @@ test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
198
test_cmp expect actual
199
'
200
201
-stop_git_daemon
201
test_done