git p4 test: use 'test_atexit' to kill p4d and the watchdog process

Use 'test_atexit' to run cleanup commands to stop 'p4d' 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 one of the test scripts, 't9801-git-p4-branch.sh', stops and then re-starts 'p4d' twice in the middle of the script; take care that the cleanup functions to stop 'p4d' are only registered once. Note also that 'git p4' tests invoke different functions in the trap on EXIT ('cleanup') and in the last test before 'test_done' ('kill_p4d'). Register both of these functions with 'test_atexit' for now, and a a later patch in this series will then clean up the redundancy. 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 99e37c2560ecb1cc44bb743a2e4aaaedb5da1a90
35 files changed +9 -139
t/lib-git-p4.sh
+9 -1
@@ -74,7 +74,6 @@ cleanup () {
74 kill -9 $(cat "$pidfile") 2>/dev/null && exit 255
75 fi
76 }
77 -trap cleanup EXIT
77
78 # git p4 submit generates a temp file, which will
79 # not get cleaned up if the submission fails. Don't
@@ -82,7 +81,16 @@ trap cleanup EXIT
81 TMPDIR="$TRASH_DIRECTORY"
82 export TMPDIR
83
84 +registered_stop_p4d_atexit_handler=
85 start_p4d () {
86 + # One of the test scripts stops and then re-starts p4d.
87 + # Don't register and then run the same atexit handlers several times.
88 + if test -z "$registered_stop_p4d_atexit_handler"
89 + then
90 + test_atexit 'kill_p4d; cleanup'
91 + registered_stop_p4d_atexit_handler=AlreadyDone
92 + fi
93 +
94 mkdir -p "$db" "$cli" "$git" &&
95 rm -f "$pidfile" &&
96 (
t/t9800-git-p4-basic.sh
-4
@@ -326,8 +326,4 @@ test_expect_success 'submit from worktree' '
326 )
327 '
328
329 -test_expect_success 'kill p4d' '
330 - kill_p4d
331 -'
332 -
329 test_done
t/t9801-git-p4-branch.sh
-4
@@ -610,8 +610,4 @@ test_expect_success 'Update a file in git side and submit to P4 using client vie
610 )
611 '
612
613 -test_expect_success 'kill p4d' '
614 - kill_p4d
615 -'
616 -
613 test_done
t/t9802-git-p4-filetype.sh
-4
@@ -333,8 +333,4 @@ test_expect_success SYMLINKS 'empty symlink target' '
333 )
334 '
335
336 -test_expect_success 'kill p4d' '
337 - kill_p4d
338 -'
339 -
336 test_done
t/t9803-git-p4-shell-metachars.sh
-4
@@ -105,8 +105,4 @@ test_expect_success 'branch with shell char' '
105 )
106 '
107
108 -test_expect_success 'kill p4d' '
109 - kill_p4d
110 -'
111 -
108 test_done
t/t9804-git-p4-label.sh
-4
@@ -108,8 +108,4 @@ test_expect_failure 'two labels on the same changelist' '
108 )
109 '
110
111 -test_expect_success 'kill p4d' '
112 - kill_p4d
113 -'
114 -
111 test_done
t/t9805-git-p4-skip-submit-edit.sh
-4
@@ -98,8 +98,4 @@ test_expect_success 'no config, edited' '
98 )
99 '
100
101 -test_expect_success 'kill p4d' '
102 - kill_p4d
103 -'
104 -
101 test_done
t/t9806-git-p4-options.sh
-5
@@ -300,9 +300,4 @@ test_expect_success 'use --git-dir option and GIT_DIR' '
300 test_path_is_file "$git"/cli_file2.t
301 '
302
303 -
304 -test_expect_success 'kill p4d' '
305 - kill_p4d
306 -'
307 -
303 test_done
t/t9807-git-p4-submit.sh
-4
@@ -593,8 +593,4 @@ test_expect_success 'update a shelve involving moved and copied files' '
593 )
594 '
595
596 -test_expect_success 'kill p4d' '
597 - kill_p4d
598 -'
599 -
596 test_done
t/t9808-git-p4-chdir.sh
-4
@@ -83,8 +83,4 @@ test_expect_success SYMLINKS 'p4 client root symlink should stay symbolic' '
83 )
84 '
85
86 -test_expect_success 'kill p4d' '
87 - kill_p4d
88 -'
89 -
86 test_done
t/t9809-git-p4-client-view.sh
-4
@@ -836,8 +836,4 @@ test_expect_success 'quotes on both sides' '
836 git_verify "cdir 1/file11" "cdir 1/file12"
837 '
838
839 -test_expect_success 'kill p4d' '
840 - kill_p4d
841 -'
842 -
839 test_done
t/t9810-git-p4-rcs.sh
-4
@@ -360,8 +360,4 @@ test_expect_failure 'Add keywords in git which do not match the default p4 value
360 )
361 '
362
363 -test_expect_success 'kill p4d' '
364 - kill_p4d
365 -'
366 -
363 test_done
t/t9811-git-p4-label-import.sh
-5
@@ -259,9 +259,4 @@ test_expect_success 'importing labels with missing revisions' '
259 )
260 '
261
262 -
263 -test_expect_success 'kill p4d' '
264 - kill_p4d
265 -'
266 -
262 test_done
t/t9812-git-p4-wildcards.sh
-4
@@ -211,8 +211,4 @@ test_expect_success 'wildcard files requiring keyword scrub' '
211 )
212 '
213
214 -test_expect_success 'kill p4d' '
215 - kill_p4d
216 -'
217 -
214 test_done
t/t9813-git-p4-preserve-users.sh
-4
@@ -138,8 +138,4 @@ test_expect_success 'not preserving user with mixed authorship' '
138 )
139 '
140
141 -test_expect_success 'kill p4d' '
142 - kill_p4d
143 -'
144 -
141 test_done
t/t9814-git-p4-rename.sh
-4
@@ -242,8 +242,4 @@ test_expect_success P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW \
242 )
243 '
244
245 -test_expect_success 'kill p4d' '
246 - kill_p4d
247 -'
248 -
245 test_done
t/t9815-git-p4-submit-fail.sh
-4
@@ -422,8 +422,4 @@ test_expect_success 'cleanup chmod after submit cancel' '
422 )
423 '
424
425 -test_expect_success 'kill p4d' '
426 - kill_p4d
427 -'
428 -
425 test_done
t/t9816-git-p4-locked.sh
-4
@@ -138,8 +138,4 @@ test_expect_failure 'move with lock taken' '
138 )
139 '
140
141 -test_expect_success 'kill p4d' '
142 - kill_p4d
143 -'
144 -
141 test_done
t/t9817-git-p4-exclude.sh
-4
@@ -64,8 +64,4 @@ test_expect_success 'clone, then sync with exclude' '
64 )
65 '
66
67 -test_expect_success 'kill p4d' '
68 - kill_p4d
69 -'
70 -
67 test_done
t/t9818-git-p4-block.sh
-4
@@ -146,8 +146,4 @@ test_expect_success 'Clone repo with self-sizing block size' '
146 test_line_count \> 10 log
147 '
148
149 -test_expect_success 'kill p4d' '
150 - kill_p4d
151 -'
152 -
149 test_done
t/t9819-git-p4-case-folding.sh
-4
@@ -53,8 +53,4 @@ test_expect_failure 'Clone UC repo with lc name' '
53 test_must_fail git p4 clone //depot/uc/...
54 '
55
56 -test_expect_success 'kill p4d' '
57 - kill_p4d
58 -'
59 -
56 test_done
t/t9820-git-p4-editor-handling.sh
-4
@@ -31,8 +31,4 @@ test_expect_success 'EDITOR with options' '
31 )
32 '
33
34 -test_expect_success 'kill p4d' '
35 - kill_p4d
36 -'
37 -
34 test_done
t/t9821-git-p4-path-variations.sh
-4
@@ -193,8 +193,4 @@ test_expect_success 'Add a new file and clone path with new file (ignorecase)' '
193 )
194 '
195
196 -test_expect_success 'kill p4d' '
197 - kill_p4d
198 -'
199 -
196 test_done
t/t9822-git-p4-path-encoding.sh
-4
@@ -67,8 +67,4 @@ test_expect_success 'Delete iso8859-1 encoded paths and clone' '
67 )
68 '
69
70 -test_expect_success 'kill p4d' '
71 - kill_p4d
72 -'
73 -
70 test_done
t/t9823-git-p4-mock-lfs.sh
-4
@@ -185,8 +185,4 @@ test_expect_success 'Run git p4 submit in repo configured with large file system
185 )
186 '
187
188 -test_expect_success 'kill p4d' '
189 - kill_p4d
190 -'
191 -
188 test_done
t/t9824-git-p4-git-lfs.sh
-4
@@ -287,8 +287,4 @@ test_expect_success 'Add big files to repo and store files in LFS based on compr
287 )
288 '
289
290 -test_expect_success 'kill p4d' '
291 - kill_p4d
292 -'
293 -
290 test_done
t/t9825-git-p4-handle-utf16-without-bom.sh
-4
@@ -43,8 +43,4 @@ test_expect_failure 'clone depot with invalid UTF-16 file in non-verbose mode' '
43 git p4 clone --dest="$git" //depot
44 '
45
46 -test_expect_success 'kill p4d' '
47 - kill_p4d
48 -'
49 -
46 test_done
t/t9826-git-p4-keep-empty-commits.sh
-4
@@ -127,8 +127,4 @@ test_expect_success 'Clone repo subdir with all history' '
127 )
128 '
129
130 -test_expect_success 'kill p4d' '
131 - kill_p4d
132 -'
133 -
130 test_done
t/t9827-git-p4-change-filetype.sh
-4
@@ -59,8 +59,4 @@ test_expect_success SYMLINKS 'change symbolic link to file' '
59 )
60 '
61
62 -test_expect_success 'kill p4d' '
63 - kill_p4d
64 -'
65 -
62 test_done
t/t9828-git-p4-map-user.sh
-4
@@ -54,8 +54,4 @@ test_expect_success 'Clone repo root path with all history' '
54 )
55 '
56
57 -test_expect_success 'kill p4d' '
58 - kill_p4d
59 -'
60 -
57 test_done
t/t9829-git-p4-jobs.sh
-4
@@ -92,8 +92,4 @@ test_expect_success 'check log message of changelist with more jobs' '
92 )
93 '
94
95 -test_expect_success 'kill p4d' '
96 - kill_p4d
97 -'
98 -
95 test_done
t/t9830-git-p4-symlink-dir.sh
-4
@@ -36,8 +36,4 @@ test_expect_success 'symlinked directory' '
36
37 '
38
39 -test_expect_success 'kill p4d' '
40 - kill_p4d
41 -'
42 -
39 test_done
t/t9831-git-p4-triggers.sh
-4
@@ -96,8 +96,4 @@ test_expect_success 'submit description with extra info lines from verbose p4 ch
96 )
97 '
98
99 -test_expect_success 'kill p4d' '
100 - kill_p4d
101 -'
102 -
99 test_done
t/t9832-unshelve.sh
-3
@@ -174,8 +174,5 @@ test_expect_success 'unshelve specifying the origin' '
174 test_path_is_file file_to_shelve
175 )
176 '
177 -test_expect_success 'kill p4d' '
178 - kill_p4d
179 -'
177
178 test_done
t/t9833-errors.sh
-5
@@ -45,9 +45,4 @@ test_expect_success 'ticket logged out' '
45 )
46 '
47
48 -test_expect_success 'kill p4d' '
49 - kill_p4d
50 -'
51 -
52 -
48 test_done