Skip to content

Commit 99e37c2

Browse files
dschogitster
authored andcommitted
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>
1 parent 3bc2702 commit 99e37c2

35 files changed

+9
-139
lines changed

t/lib-git-p4.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,23 @@ cleanup () {
7474
kill -9 $(cat "$pidfile") 2>/dev/null && exit 255
7575
fi
7676
}
77-
trap cleanup EXIT
7877

7978
# git p4 submit generates a temp file, which will
8079
# not get cleaned up if the submission fails. Don't
8180
# clutter up /tmp on the test machine.
8281
TMPDIR="$TRASH_DIRECTORY"
8382
export TMPDIR
8483

84+
registered_stop_p4d_atexit_handler=
8585
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+
8694
mkdir -p "$db" "$cli" "$git" &&
8795
rm -f "$pidfile" &&
8896
(

t/t9800-git-p4-basic.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,4 @@ test_expect_success 'submit from worktree' '
326326
)
327327
'
328328

329-
test_expect_success 'kill p4d' '
330-
kill_p4d
331-
'
332-
333329
test_done

t/t9801-git-p4-branch.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,4 @@ test_expect_success 'Update a file in git side and submit to P4 using client vie
610610
)
611611
'
612612

613-
test_expect_success 'kill p4d' '
614-
kill_p4d
615-
'
616-
617613
test_done

t/t9802-git-p4-filetype.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,4 @@ test_expect_success SYMLINKS 'empty symlink target' '
333333
)
334334
'
335335

336-
test_expect_success 'kill p4d' '
337-
kill_p4d
338-
'
339-
340336
test_done

t/t9803-git-p4-shell-metachars.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,4 @@ test_expect_success 'branch with shell char' '
105105
)
106106
'
107107

108-
test_expect_success 'kill p4d' '
109-
kill_p4d
110-
'
111-
112108
test_done

t/t9804-git-p4-label.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,4 @@ test_expect_failure 'two labels on the same changelist' '
108108
)
109109
'
110110

111-
test_expect_success 'kill p4d' '
112-
kill_p4d
113-
'
114-
115111
test_done

t/t9805-git-p4-skip-submit-edit.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,4 @@ test_expect_success 'no config, edited' '
9898
)
9999
'
100100

101-
test_expect_success 'kill p4d' '
102-
kill_p4d
103-
'
104-
105101
test_done

t/t9806-git-p4-options.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,4 @@ test_expect_success 'use --git-dir option and GIT_DIR' '
300300
test_path_is_file "$git"/cli_file2.t
301301
'
302302

303-
304-
test_expect_success 'kill p4d' '
305-
kill_p4d
306-
'
307-
308303
test_done

t/t9807-git-p4-submit.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,4 @@ test_expect_success 'update a shelve involving moved and copied files' '
593593
)
594594
'
595595

596-
test_expect_success 'kill p4d' '
597-
kill_p4d
598-
'
599-
600596
test_done

t/t9808-git-p4-chdir.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,4 @@ test_expect_success SYMLINKS 'p4 client root symlink should stay symbolic' '
8383
)
8484
'
8585

86-
test_expect_success 'kill p4d' '
87-
kill_p4d
88-
'
89-
9086
test_done

0 commit comments

Comments
 (0)