tests: use 'test_atexit' to stop httpd

Use 'test_atexit' to run cleanup commands to stop httpd 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. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Mar 13, 2019 at 13:24 UTC 8c3b9f7faa4f39ddb89be229b706d4a9f9c659a4
25 files changed +1 -50
t/lib-git-svn.sh
-5
@@ -76,11 +76,6 @@ maybe_start_httpd () {
76 LIB_HTTPD_SVN="$loc"
77 start_httpd
78 ;;
79 - *)
80 - stop_httpd () {
81 - : noop
82 - }
83 - ;;
79 esac
80 }
81
t/lib-httpd.sh
+1 -5
@@ -14,7 +14,6 @@
14 #
15 # test_expect_success ...
16 #
17 -# stop_httpd
17 # test_done
18 #
19 # Can be configured using the following variables.
@@ -176,7 +175,7 @@ prepare_httpd() {
175 start_httpd() {
176 prepare_httpd >&3 2>&4
177
179 - trap 'code=$?; stop_httpd; (exit $code); die' EXIT
178 + test_atexit stop_httpd
179
180 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
181 -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
@@ -184,15 +183,12 @@ start_httpd() {
183 >&3 2>&4
184 if test $? -ne 0
185 then
187 - trap 'die' EXIT
186 cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
187 test_skip_or_die $GIT_TEST_HTTPD "web server setup failed"
188 fi
189 }
190
191 stop_httpd() {
194 - trap 'die' EXIT
195 -
192 "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
193 -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
194 }
t/t0410-partial-clone.sh
-2
@@ -518,6 +518,4 @@ test_expect_success 'fetching of missing objects from an HTTP server' '
518 git verify-pack --verbose "$IDX" | grep "$HASH"
519 '
520
521 -stop_httpd
522 -
521 test_done
t/t5500-fetch-pack.sh
-3
@@ -918,7 +918,4 @@ test_expect_success 'fetch with --filter=blob:limit=0 and HTTP' '
918 fetch_filter_blob_limit_zero "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
919 '
920
921 -stop_httpd
922 -
923 -
921 test_done
t/t5510-fetch.sh
-2
@@ -978,6 +978,4 @@ test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protoc
978 check_negotiation_tip
979 '
980
981 -stop_httpd
982 -
981 test_done
t/t5537-fetch-shallow.sh
-2
@@ -255,6 +255,4 @@ test_expect_success 'shallow fetches check connectivity before writing shallow f
255 git -C client fsck
256 '
257
258 -stop_httpd
259 -
258 test_done
t/t5539-fetch-http-shallow.sh
-1
@@ -146,5 +146,4 @@ test_expect_success 'fetching deepen' '
146 )
147 '
148
149 -stop_httpd
149 test_done
t/t5540-http-push-webdav.sh
-2
@@ -176,6 +176,4 @@ test_expect_failure 'push to password-protected repository (no user in URL)' '
176 test_cmp expect actual
177 '
178
179 -stop_httpd
180 -
179 test_done
t/t5541-http-push-smart.sh
-1
@@ -373,5 +373,4 @@ test_expect_success 'colorize errors/hints' '
373 test_i18ngrep ! "^hint: " decoded
374 '
375
376 -stop_httpd
376 test_done
t/t5542-push-http-shallow.sh
-1
@@ -90,5 +90,4 @@ EOF
90 )
91 '
92
93 -stop_httpd
93 test_done
t/t5545-push-options.sh
-2
@@ -278,6 +278,4 @@ test_expect_success 'push options keep quoted characters intact (http)' '
278 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
279 '
280
281 -stop_httpd
282 -
281 test_done
t/t5550-http-fetch-dumb.sh
-1
@@ -408,5 +408,4 @@ test_expect_success 'print HTTP error when any intermediate redirect throws erro
408 test_i18ngrep "unable to access.*/redir-to/502" stderr
409 '
410
411 -stop_httpd
411 test_done
t/t5551-http-fetch-smart.sh
-1
@@ -434,5 +434,4 @@ test_expect_success 'server-side error detected' '
434 grep "server-side error" actual
435 '
436
437 -stop_httpd
437 test_done
t/t5561-http-backend.sh
-1
@@ -132,5 +132,4 @@ test_expect_success 'server request log matches test results' '
132 check_access_log exp
133 '
134
135 -stop_httpd
135 test_done
t/t5581-http-curl-verbose.sh
-2
@@ -23,6 +23,4 @@ test_expect_success 'failure in git-upload-pack is shown' '
23 grep "< HTTP/1.1 500 Intentional Breakage" curl_log
24 '
25
26 -stop_httpd
27 -
26 test_done
t/t5601-clone.sh
-2
@@ -733,6 +733,4 @@ test_expect_success 'partial clone using HTTP' '
733 partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
734 '
735
736 -stop_httpd
737 -
736 test_done
t/t5616-partial-clone.sh
-2
@@ -331,6 +331,4 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
331 ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
332 '
333
334 -stop_httpd
335 -
334 test_done
t/t5700-protocol-v1.sh
-2
@@ -289,6 +289,4 @@ test_expect_success 'push with http:// using protocol v1' '
289 grep "git< version 1" log
290 '
291
292 -stop_httpd
293 -
292 test_done
t/t5702-protocol-v2.sh
-2
@@ -687,6 +687,4 @@ test_expect_success 'when server does not send "ready", expect FLUSH' '
687 test_i18ngrep "expected no other sections to be sent after no .ready." err
688 '
689
690 -stop_httpd
691 -
690 test_done
t/t5703-upload-pack-ref-in-want.sh
-2
@@ -257,8 +257,6 @@ test_expect_success 'server loses a ref - ref in want' '
257 test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
258 '
259
260 -stop_httpd
261 -
260 REPO="$(pwd)/repo"
261 LOCAL_PRISTINE="$(pwd)/local_pristine"
262
t/t5812-proto-disable-http.sh
-1
@@ -34,5 +34,4 @@ test_expect_success 'http can be limited to from-user' '
34 clone "$HTTPD_URL/smart-redir-perm/repo.git" redir.git
35 '
36
37 -stop_httpd
37 test_done
t/t9115-git-svn-dcommit-funky-renames.sh
-2
@@ -120,6 +120,4 @@ test_expect_success !MINGW,!UTF8_NFD_TO_NFC 'svn.pathnameencoding=cp932 rename o
120 git svn dcommit
121 '
122
123 -stop_httpd
124 -
123 test_done
t/t9118-git-svn-funky-branch-names.sh
-2
@@ -87,6 +87,4 @@ test_expect_success 'test dcommit to trailing_dotlock branch' '
87 )
88 '
89
90 -stop_httpd
91 -
90 test_done
t/t9120-git-svn-clone-with-percent-escapes.sh
-2
@@ -74,6 +74,4 @@ test_expect_success 'test clone -s with unescaped space' '
74 )
75 '
76
77 -stop_httpd
78 -
77 test_done
t/t9142-git-svn-shallow-clone.sh
-2
@@ -26,6 +26,4 @@ test_expect_success 'clone trunk with "-r HEAD"' '
26 ( cd g && git rev-parse --symbolic --verify HEAD )
27 '
28
29 -stop_httpd
30 -
29 test_done