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>
This commit is contained in:
Johannes Schindelin 2019-03-13 13:24:15 +01:00 committed by Junio C Hamano
parent 3bc2702b88
commit 99e37c2560
35 changed files with 9 additions and 139 deletions

View File

@ -74,7 +74,6 @@ cleanup () {
kill -9 $(cat "$pidfile") 2>/dev/null && exit 255 kill -9 $(cat "$pidfile") 2>/dev/null && exit 255
fi fi
} }
trap cleanup EXIT
# git p4 submit generates a temp file, which will # git p4 submit generates a temp file, which will
# not get cleaned up if the submission fails. Don't # not get cleaned up if the submission fails. Don't
@ -82,7 +81,16 @@ trap cleanup EXIT
TMPDIR="$TRASH_DIRECTORY" TMPDIR="$TRASH_DIRECTORY"
export TMPDIR export TMPDIR
registered_stop_p4d_atexit_handler=
start_p4d () { start_p4d () {
# One of the test scripts stops and then re-starts p4d.
# Don't register and then run the same atexit handlers several times.
if test -z "$registered_stop_p4d_atexit_handler"
then
test_atexit 'kill_p4d; cleanup'
registered_stop_p4d_atexit_handler=AlreadyDone
fi
mkdir -p "$db" "$cli" "$git" && mkdir -p "$db" "$cli" "$git" &&
rm -f "$pidfile" && rm -f "$pidfile" &&
( (

View File

@ -326,8 +326,4 @@ test_expect_success 'submit from worktree' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -610,8 +610,4 @@ test_expect_success 'Update a file in git side and submit to P4 using client vie
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -333,8 +333,4 @@ test_expect_success SYMLINKS 'empty symlink target' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -105,8 +105,4 @@ test_expect_success 'branch with shell char' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -108,8 +108,4 @@ test_expect_failure 'two labels on the same changelist' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -98,8 +98,4 @@ test_expect_success 'no config, edited' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -300,9 +300,4 @@ test_expect_success 'use --git-dir option and GIT_DIR' '
test_path_is_file "$git"/cli_file2.t test_path_is_file "$git"/cli_file2.t
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -593,8 +593,4 @@ test_expect_success 'update a shelve involving moved and copied files' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -83,8 +83,4 @@ test_expect_success SYMLINKS 'p4 client root symlink should stay symbolic' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -836,8 +836,4 @@ test_expect_success 'quotes on both sides' '
git_verify "cdir 1/file11" "cdir 1/file12" git_verify "cdir 1/file11" "cdir 1/file12"
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -360,8 +360,4 @@ test_expect_failure 'Add keywords in git which do not match the default p4 value
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -259,9 +259,4 @@ test_expect_success 'importing labels with missing revisions' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -211,8 +211,4 @@ test_expect_success 'wildcard files requiring keyword scrub' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -138,8 +138,4 @@ test_expect_success 'not preserving user with mixed authorship' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -242,8 +242,4 @@ test_expect_success P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW \
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -422,8 +422,4 @@ test_expect_success 'cleanup chmod after submit cancel' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -138,8 +138,4 @@ test_expect_failure 'move with lock taken' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -64,8 +64,4 @@ test_expect_success 'clone, then sync with exclude' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -146,8 +146,4 @@ test_expect_success 'Clone repo with self-sizing block size' '
test_line_count \> 10 log test_line_count \> 10 log
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -53,8 +53,4 @@ test_expect_failure 'Clone UC repo with lc name' '
test_must_fail git p4 clone //depot/uc/... test_must_fail git p4 clone //depot/uc/...
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -31,8 +31,4 @@ test_expect_success 'EDITOR with options' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -193,8 +193,4 @@ test_expect_success 'Add a new file and clone path with new file (ignorecase)' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -67,8 +67,4 @@ test_expect_success 'Delete iso8859-1 encoded paths and clone' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -185,8 +185,4 @@ test_expect_success 'Run git p4 submit in repo configured with large file system
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -287,8 +287,4 @@ test_expect_success 'Add big files to repo and store files in LFS based on compr
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -43,8 +43,4 @@ test_expect_failure 'clone depot with invalid UTF-16 file in non-verbose mode' '
git p4 clone --dest="$git" //depot git p4 clone --dest="$git" //depot
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -127,8 +127,4 @@ test_expect_success 'Clone repo subdir with all history' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -59,8 +59,4 @@ test_expect_success SYMLINKS 'change symbolic link to file' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -54,8 +54,4 @@ test_expect_success 'Clone repo root path with all history' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -92,8 +92,4 @@ test_expect_success 'check log message of changelist with more jobs' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -36,8 +36,4 @@ test_expect_success 'symlinked directory' '
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -96,8 +96,4 @@ test_expect_success 'submit description with extra info lines from verbose p4 ch
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -174,8 +174,5 @@ test_expect_success 'unshelve specifying the origin' '
test_path_is_file file_to_shelve test_path_is_file file_to_shelve
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done

View File

@ -45,9 +45,4 @@ test_expect_success 'ticket logged out' '
) )
' '
test_expect_success 'kill p4d' '
kill_p4d
'
test_done test_done