Merge branch 'sg/test-atexit'

Test framework update to more robustly clean up leftover files and
processes after tests are done.

* sg/test-atexit:
  t9811-git-p4-label-import: fix pipeline negation
  git p4 test: disable '-x' tracing in the p4d watchdog loop
  git p4 test: simplify timeout handling
  git p4 test: clean up the p4d cleanup functions
  git p4 test: use 'test_atexit' to kill p4d and the watchdog process
  t0301-credential-cache: use 'test_atexit' to stop the credentials helper
  tests: use 'test_atexit' to stop httpd
  git-daemon: use 'test_atexit` to stop 'git-daemon'
  test-lib: introduce 'test_atexit'
  t/lib-git-daemon: make sure to kill the 'git-daemon' process
  test-lib: fix interrupt handling with 'dash' and '--verbose-log -x'
maint
Junio C Hamano 2019-04-25 16:41:12 +09:00
commit 579b75ad95
68 changed files with 136 additions and 247 deletions

View File

@ -871,6 +871,26 @@ library for your script to use.
... ...
' '


- test_atexit <script>

Prepend <script> to a list of commands to run unconditionally to
clean up before the test script exits, e.g. to stop a daemon:

test_expect_success 'test git daemon' '
git daemon &
daemon_pid=$! &&
test_atexit 'kill $daemon_pid' &&
hello world
'

The commands will be executed before the trash directory is removed,
i.e. the atexit commands will still be able to access any pidfiles or
socket files.

Note that these commands will be run even when a test script run
with '--immediate' fails. Be careful with your atexit commands to
minimize any changes to the failed state.

- test_write_lines <lines> - test_write_lines <lines>


Write <lines> on standard output, one line per argument. Write <lines> on standard output, one line per argument.

View File

@ -37,5 +37,4 @@ test_expect_success "fetch with $VERSION_B" '
test_cmp expect actual test_cmp expect actual
' '


stop_git_daemon
test_done test_done

View File

@ -13,7 +13,6 @@
# #
# test_expect_success ... # test_expect_success ...
# #
# stop_git_daemon
# test_done # test_done


test_tristate GIT_TEST_GIT_DAEMON test_tristate GIT_TEST_GIT_DAEMON
@ -31,10 +30,12 @@ fi
test_set_port LIB_GIT_DAEMON_PORT test_set_port LIB_GIT_DAEMON_PORT


GIT_DAEMON_PID= GIT_DAEMON_PID=
GIT_DAEMON_PIDFILE="$PWD"/daemon.pid
GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
GIT_DAEMON_HOST_PORT=127.0.0.1:$LIB_GIT_DAEMON_PORT GIT_DAEMON_HOST_PORT=127.0.0.1:$LIB_GIT_DAEMON_PORT
GIT_DAEMON_URL=git://$GIT_DAEMON_HOST_PORT GIT_DAEMON_URL=git://$GIT_DAEMON_HOST_PORT


registered_stop_git_daemon_atexit_handler=
start_git_daemon() { start_git_daemon() {
if test -n "$GIT_DAEMON_PID" if test -n "$GIT_DAEMON_PID"
then then
@ -43,13 +44,19 @@ start_git_daemon() {


mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH" mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"


trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT # One of the test scripts stops and then re-starts 'git daemon'.
# Don't register and then run the same atexit handlers several times.
if test -z "$registered_stop_git_daemon_atexit_handler"
then
test_atexit 'stop_git_daemon'
registered_stop_git_daemon_atexit_handler=AlreadyDone
fi


say >&3 "Starting git daemon ..." say >&3 "Starting git daemon ..."
mkfifo git_daemon_output mkfifo git_daemon_output
${LIB_GIT_DAEMON_COMMAND:-git daemon} \ ${LIB_GIT_DAEMON_COMMAND:-git daemon} \
--listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \ --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
--reuseaddr --verbose \ --reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \
--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \ --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \ "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
>&3 2>git_daemon_output & >&3 2>git_daemon_output &
@ -65,7 +72,7 @@ start_git_daemon() {
then then
kill "$GIT_DAEMON_PID" kill "$GIT_DAEMON_PID"
wait "$GIT_DAEMON_PID" wait "$GIT_DAEMON_PID"
trap 'die' EXIT unset GIT_DAEMON_PID
test_skip_or_die $GIT_TEST_GIT_DAEMON \ test_skip_or_die $GIT_TEST_GIT_DAEMON \
"git daemon failed to start" "git daemon failed to start"
fi fi
@ -77,8 +84,6 @@ stop_git_daemon() {
return return
fi fi


trap 'die' EXIT

# kill git-daemon child of git # kill git-daemon child of git
say >&3 "Stopping git daemon ..." say >&3 "Stopping git daemon ..."
kill "$GIT_DAEMON_PID" kill "$GIT_DAEMON_PID"
@ -88,8 +93,9 @@ stop_git_daemon() {
then then
error "git daemon exited with status: $ret" error "git daemon exited with status: $ret"
fi fi
kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null
GIT_DAEMON_PID= GIT_DAEMON_PID=
rm -f git_daemon_output rm -f git_daemon_output "$GIT_DAEMON_PIDFILE"
} }


# A stripped-down version of a netcat client, that connects to a "host:port" # A stripped-down version of a netcat client, that connects to a "host:port"

View File

@ -44,15 +44,6 @@ native_path () {
echo "$path" echo "$path"
} }


# On Solaris the 'date +%s' function is not supported and therefore we
# need this replacement.
# Attention: This function is not safe again against time offset updates
# at runtime (e.g. via NTP). The 'clock_gettime(CLOCK_MONOTONIC)'
# function could fix that but it is not in Python until 3.3.
time_in_seconds () {
(cd / && "$PYTHON_PATH" -c 'import time; print(int(time.time()))')
}

test_set_port P4DPORT test_set_port P4DPORT


P4PORT=localhost:$P4DPORT P4PORT=localhost:$P4DPORT
@ -67,14 +58,9 @@ cli="$TRASH_DIRECTORY/cli"
git="$TRASH_DIRECTORY/git" git="$TRASH_DIRECTORY/git"
pidfile="$TRASH_DIRECTORY/p4d.pid" pidfile="$TRASH_DIRECTORY/p4d.pid"


# Sometimes "prove" seems to hang on exit because p4d is still running stop_p4d_and_watchdog () {
cleanup () { kill -9 $p4d_pid $watchdog_pid
if test -f "$pidfile"
then
kill -9 $(cat "$pidfile") 2>/dev/null && exit 255
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 +68,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 'stop_p4d_and_watchdog'
registered_stop_p4d_atexit_handler=AlreadyDone
fi

mkdir -p "$db" "$cli" "$git" && mkdir -p "$db" "$cli" "$git" &&
rm -f "$pidfile" && rm -f "$pidfile" &&
( (
@ -92,6 +87,7 @@ start_p4d () {
echo $! >"$pidfile" echo $! >"$pidfile"
} }
) && ) &&
p4d_pid=$(cat "$pidfile")


# This gives p4d a long time to start up, as it can be # This gives p4d a long time to start up, as it can be
# quite slow depending on the machine. Set this environment # quite slow depending on the machine. Set this environment
@ -99,18 +95,18 @@ start_p4d () {
# an automated test setup. If the p4d process dies, that # an automated test setup. If the p4d process dies, that
# will be caught with the "kill -0" check below. # will be caught with the "kill -0" check below.
i=${P4D_START_PATIENCE:-300} i=${P4D_START_PATIENCE:-300}
pid=$(cat "$pidfile")


timeout=$(($(time_in_seconds) + $P4D_TIMEOUT)) nr_tries_left=$P4D_TIMEOUT
while true while true
do do
if test $(time_in_seconds) -gt $timeout if test $nr_tries_left -eq 0
then then
kill -9 $pid kill -9 $p4d_pid
exit 1 exit 1
fi fi
sleep 1 sleep 1
done & nr_tries_left=$(($nr_tries_left - 1))
done 2>/dev/null 4>&2 &
watchdog_pid=$! watchdog_pid=$!


ready= ready=
@ -123,7 +119,7 @@ start_p4d () {
break break
fi fi
# fail if p4d died # fail if p4d died
kill -0 $pid 2>/dev/null || break kill -0 $p4d_pid 2>/dev/null || break
echo waiting for p4d to start echo waiting for p4d to start
sleep 1 sleep 1
i=$(( $i - 1 )) i=$(( $i - 1 ))
@ -163,29 +159,18 @@ p4_add_job () {
} }


retry_until_success () { retry_until_success () {
timeout=$(($(time_in_seconds) + $RETRY_TIMEOUT)) nr_tries_left=$RETRY_TIMEOUT
until "$@" 2>/dev/null || test $(time_in_seconds) -gt $timeout until "$@" 2>/dev/null || test $nr_tries_left -eq 0
do do
sleep 1 sleep 1
nr_tries_left=$(($nr_tries_left - 1))
done done
} }


retry_until_fail () { stop_and_cleanup_p4d () {
timeout=$(($(time_in_seconds) + $RETRY_TIMEOUT)) kill -9 $p4d_pid $watchdog_pid
until ! "$@" 2>/dev/null || test $(time_in_seconds) -gt $timeout wait $p4d_pid
do rm -rf "$db" "$cli" "$pidfile"
sleep 1
done
}

kill_p4d () {
pid=$(cat "$pidfile")
retry_until_fail kill $pid
retry_until_fail kill -9 $pid
# complain if it would not die
test_must_fail kill $pid >/dev/null 2>&1 &&
rm -rf "$db" "$cli" "$pidfile" &&
retry_until_fail kill -9 $watchdog_pid
} }


cleanup_git () { cleanup_git () {

View File

@ -76,11 +76,6 @@ maybe_start_httpd () {
LIB_HTTPD_SVN="$loc" LIB_HTTPD_SVN="$loc"
start_httpd start_httpd
;; ;;
*)
stop_httpd () {
: noop
}
;;
esac esac
} }



View File

@ -14,7 +14,6 @@
# #
# test_expect_success ... # test_expect_success ...
# #
# stop_httpd
# test_done # test_done
# #
# Can be configured using the following variables. # Can be configured using the following variables.
@ -176,7 +175,7 @@ prepare_httpd() {
start_httpd() { start_httpd() {
prepare_httpd >&3 2>&4 prepare_httpd >&3 2>&4


trap 'code=$?; stop_httpd; (exit $code); die' EXIT test_atexit stop_httpd


"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
-f "$TEST_PATH/apache.conf" $HTTPD_PARA \ -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
@ -184,15 +183,12 @@ start_httpd() {
>&3 2>&4 >&3 2>&4
if test $? -ne 0 if test $? -ne 0
then then
trap 'die' EXIT
cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
test_skip_or_die $GIT_TEST_HTTPD "web server setup failed" test_skip_or_die $GIT_TEST_HTTPD "web server setup failed"
fi fi
} }


stop_httpd() { stop_httpd() {
trap 'die' EXIT

"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
-f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
} }

View File

@ -825,6 +825,24 @@ test_expect_success 'tests clean up even on failures' "
EOF EOF
" "


test_expect_success 'test_atexit is run' "
test_must_fail run_sub_test_lib_test \
atexit-cleanup 'Run atexit commands' -i <<-\\EOF &&
test_expect_success 'tests clean up even after a failure' '
> ../../clean-atexit &&
test_atexit rm ../../clean-atexit &&
> ../../also-clean-atexit &&
test_atexit rm ../../also-clean-atexit &&
> ../../dont-clean-atexit &&
(exit 1)
'
test_done
EOF
test_path_is_file dont-clean-atexit &&
test_path_is_missing clean-atexit &&
test_path_is_missing also-clean-atexit
"

test_expect_success 'test_oid setup' ' test_expect_success 'test_oid setup' '
test_oid_init test_oid_init
' '

View File

@ -10,7 +10,7 @@ test -z "$NO_UNIX_SOCKETS" || {
} }


# don't leave a stale daemon running # don't leave a stale daemon running
trap 'code=$?; git credential-cache exit; (exit $code); die' EXIT test_atexit 'git credential-cache exit'


# test that the daemon works with no special setup # test that the daemon works with no special setup
helper_test cache helper_test cache
@ -108,9 +108,4 @@ test_expect_success SYMLINKS 'use user socket if user directory is a symlink to


helper_test_timeout cache --timeout=1 helper_test_timeout cache --timeout=1


# we can't rely on our "trap" above working after test_done,
# as test_done will delete the trash directory containing
# our socket, leaving us with no way to access the daemon.
git credential-cache exit

test_done test_done

View File

@ -518,6 +518,4 @@ test_expect_success 'fetching of missing objects from an HTTP server' '
git verify-pack --verbose "$IDX" | grep "$HASH" git verify-pack --verbose "$IDX" | grep "$HASH"
' '


stop_httpd

test_done test_done

View File

@ -920,7 +920,4 @@ test_expect_success 'fetch with --filter=blob:limit=0 and HTTP' '
fetch_filter_blob_limit_zero "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server" fetch_filter_blob_limit_zero "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
' '


stop_httpd


test_done test_done

View File

@ -978,6 +978,4 @@ test_expect_success '--negotiation-tip limits "have" lines sent with HTTP protoc
check_negotiation_tip check_negotiation_tip
' '


stop_httpd

test_done test_done

View File

@ -255,6 +255,4 @@ test_expect_success 'shallow fetches check connectivity before writing shallow f
git -C client fsck git -C client fsck
' '


stop_httpd

test_done test_done

View File

@ -149,5 +149,4 @@ test_expect_success 'fetching deepen' '
) )
' '


stop_httpd
test_done test_done

View File

@ -176,6 +176,4 @@ test_expect_failure 'push to password-protected repository (no user in URL)' '
test_cmp expect actual test_cmp expect actual
' '


stop_httpd

test_done test_done

View File

@ -383,5 +383,4 @@ test_expect_success 'colorize errors/hints' '
test_i18ngrep ! "^hint: " decoded test_i18ngrep ! "^hint: " decoded
' '


stop_httpd
test_done test_done

View File

@ -90,5 +90,4 @@ EOF
) )
' '


stop_httpd
test_done test_done

View File

@ -278,6 +278,4 @@ test_expect_success 'push options keep quoted characters intact (http)' '
test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
' '


stop_httpd

test_done test_done

View File

@ -424,5 +424,4 @@ test_expect_success 'fetching via http alternates works' '
git -c http.followredirects=true clone "$HTTPD_URL/dumb/alt-child.git" git -c http.followredirects=true clone "$HTTPD_URL/dumb/alt-child.git"
' '


stop_httpd
test_done test_done

View File

@ -469,5 +469,4 @@ test_expect_success 'server-side error detected' '
grep "server-side error" actual grep "server-side error" actual
' '


stop_httpd
test_done test_done

View File

@ -132,5 +132,4 @@ test_expect_success 'server request log matches test results' '
check_access_log exp check_access_log exp
' '


stop_httpd
test_done test_done

View File

@ -198,5 +198,4 @@ test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
test_cmp expect actual test_cmp expect actual
' '


stop_git_daemon
test_done test_done

View File

@ -23,6 +23,4 @@ test_expect_success 'failure in git-upload-pack is shown' '
grep "< HTTP/1.1 500 Intentional Breakage" curl_log grep "< HTTP/1.1 500 Intentional Breakage" curl_log
' '


stop_httpd

test_done test_done

View File

@ -733,6 +733,4 @@ test_expect_success 'partial clone using HTTP' '
partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server" partial_clone "$HTTPD_DOCUMENT_ROOT_PATH/server" "$HTTPD_URL/smart/server"
' '


stop_httpd

test_done test_done

View File

@ -331,6 +331,4 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
! test -e "$HTTPD_ROOT_PATH/one-time-sed" ! test -e "$HTTPD_ROOT_PATH/one-time-sed"
' '


stop_httpd

test_done test_done

View File

@ -292,6 +292,4 @@ test_expect_success 'push with http:// using protocol v1' '
grep "git< version 1" log grep "git< version 1" log
' '


stop_httpd

test_done test_done

View File

@ -687,6 +687,4 @@ test_expect_success 'when server does not send "ready", expect FLUSH' '
test_i18ngrep "expected no other sections to be sent after no .ready." err test_i18ngrep "expected no other sections to be sent after no .ready." err
' '


stop_httpd

test_done test_done

View File

@ -257,8 +257,6 @@ test_expect_success 'server loses a ref - ref in want' '
test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
' '


stop_httpd

REPO="$(pwd)/repo" REPO="$(pwd)/repo"
LOCAL_PRISTINE="$(pwd)/local_pristine" LOCAL_PRISTINE="$(pwd)/local_pristine"



View File

@ -34,5 +34,4 @@ test_expect_success 'http can be limited to from-user' '
clone "$HTTPD_URL/smart-redir-perm/repo.git" redir.git clone "$HTTPD_URL/smart-redir-perm/repo.git" redir.git
' '


stop_httpd
test_done test_done

View File

@ -120,6 +120,4 @@ test_expect_success !MINGW,!UTF8_NFD_TO_NFC 'svn.pathnameencoding=cp932 rename o
git svn dcommit git svn dcommit
' '


stop_httpd

test_done test_done

View File

@ -87,6 +87,4 @@ test_expect_success 'test dcommit to trailing_dotlock branch' '
) )
' '


stop_httpd

test_done test_done

View File

@ -74,6 +74,4 @@ test_expect_success 'test clone -s with unescaped space' '
) )
' '


stop_httpd

test_done test_done

View File

@ -26,6 +26,4 @@ test_expect_success 'clone trunk with "-r HEAD"' '
( cd g && git rev-parse --symbolic --verify HEAD ) ( cd g && git rev-parse --symbolic --verify HEAD )
' '


stop_httpd

test_done test_done

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

@ -151,7 +151,7 @@ test_expect_success 'import depot, branch detection, branchList branch definitio
' '


test_expect_success 'restart p4d' ' test_expect_success 'restart p4d' '
kill_p4d && stop_and_cleanup_p4d &&
start_p4d start_p4d
' '


@ -505,7 +505,7 @@ test_expect_success 'use-client-spec detect-branches skips files in branches' '
' '


test_expect_success 'restart p4d' ' test_expect_success 'restart p4d' '
kill_p4d && stop_and_cleanup_p4d &&
start_p4d start_p4d
' '


@ -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

@ -191,7 +191,7 @@ test_expect_success 'tag that cannot be exported' '
( (
cd "$cli" && cd "$cli" &&
p4 sync ... && p4 sync ... &&
!(p4 labels | grep GIT_TAG_ON_A_BRANCH) ! p4 labels | grep GIT_TAG_ON_A_BRANCH
) )
' '


@ -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

View File

@ -943,6 +943,34 @@ test_when_finished () {
} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup" } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
} }


# This function can be used to schedule some commands to be run
# unconditionally at the end of the test script, e.g. to stop a daemon:
#
# test_expect_success 'test git daemon' '
# git daemon &
# daemon_pid=$! &&
# test_atexit 'kill $daemon_pid' &&
# hello world
# '
#
# The commands will be executed before the trash directory is removed,
# i.e. the atexit commands will still be able to access any pidfiles or
# socket files.
#
# Note that these commands will be run even when a test script run
# with '--immediate' fails. Be careful with your atexit commands to
# minimize any changes to the failed state.

test_atexit () {
# We cannot detect when we are in a subshell in general, but by
# doing so on Bash is better than nothing (the test will
# silently pass on other shells).
test "${BASH_SUBSHELL-0}" = 0 ||
error "bug in test script: test_atexit does nothing in a subshell"
test_atexit_cleanup="{ $*
} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
}

# Most tests can use the created repository, but some may need to create more. # Most tests can use the created repository, but some may need to create more.
# Usage: test_create_repo <directory> # Usage: test_create_repo <directory>
test_create_repo () { test_create_repo () {

View File

@ -634,6 +634,10 @@ test_external_has_tap=0


die () { die () {
code=$? code=$?
# This is responsible for running the atexit commands even when a
# test script run with '--immediate' fails, or when the user hits
# ctrl-C, i.e. when 'test_done' is not invoked at all.
test_atexit_handler || code=$?
if test -n "$GIT_EXIT_OK" if test -n "$GIT_EXIT_OK"
then then
exit $code exit $code
@ -645,7 +649,10 @@ die () {


GIT_EXIT_OK= GIT_EXIT_OK=
trap 'die' EXIT trap 'die' EXIT
trap 'exit $?' INT TERM HUP # Disable '-x' tracing, because with some shells, notably dash, it
# prevents running the cleanup commands when a test script run with
# '--verbose-log -x' is interrupted.
trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP


# The user-facing functions are loaded from a separate file so that # The user-facing functions are loaded from a separate file so that
# test_perf subshells can have them too # test_perf subshells can have them too
@ -1056,9 +1063,28 @@ write_junit_xml_testcase () {
junit_have_testcase=t junit_have_testcase=t
} }


test_atexit_cleanup=:
test_atexit_handler () {
# In a succeeding test script 'test_atexit_handler' is invoked
# twice: first from 'test_done', then from 'die' in the trap on
# EXIT.
# This condition and resetting 'test_atexit_cleanup' below makes
# sure that the registered cleanup commands are run only once.
test : != "$test_atexit_cleanup" || return 0

setup_malloc_check
test_eval_ "$test_atexit_cleanup"
test_atexit_cleanup=:
teardown_malloc_check
}

test_done () { test_done () {
GIT_EXIT_OK=t GIT_EXIT_OK=t


# Run the atexit commands _before_ the trash directory is
# removed, so the commands can access pidfiles and socket files.
test_atexit_handler

if test -n "$write_junit_xml" && test -n "$junit_xml_path" if test -n "$write_junit_xml" && test -n "$junit_xml_path"
then then
test -n "$junit_have_testcase" || { test -n "$junit_have_testcase" || {