summaryrefslogtreecommitdiff
path: root/t/lib-git-p4.sh
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder.dev@gmail.com>2019-03-13 12:24:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-03-14 03:34:39 (GMT)
commit0e67c32955cee24c5ff534dd3f5f0de58ba91d02 (patch)
tree947e5f77fb2fc47bada532c3c8900f4ed054fc01 /t/lib-git-p4.sh
parent07353d9042f19fec749ec8413ff7e6824460ee59 (diff)
downloadgit-0e67c32955cee24c5ff534dd3f5f0de58ba91d02.zip
git-0e67c32955cee24c5ff534dd3f5f0de58ba91d02.tar.gz
git-0e67c32955cee24c5ff534dd3f5f0de58ba91d02.tar.bz2
git p4 test: simplify timeout handling
'lib-git-p4.sh' uses timeouts in a watchdog process to kill a potentially stuck 'p4d' process and for certain cleanup operation between tests. It does so by first computing when the timeout should expire, and then repeatedly asking for the current time in seconds until it exceeds the expiration time, and for portability reasons it uses a one-liner Python script to ask for the current time. Replace these timeouts with downcounters, which, though not necessarily shorter, are much simpler, at least in the sense that they don't execute the Python interpreter every second. After this change the helper function with that Python one-liner has no callers left, remove it. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/lib-git-p4.sh')
-rw-r--r--t/lib-git-p4.sh19
1 files changed, 6 insertions, 13 deletions
diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index b5cb507..c18f850 100644
--- a/t/lib-git-p4.sh
+++ b/t/lib-git-p4.sh
@@ -44,15 +44,6 @@ native_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
P4PORT=localhost:$P4DPORT
@@ -105,15 +96,16 @@ start_p4d () {
# will be caught with the "kill -0" check below.
i=${P4D_START_PATIENCE:-300}
- timeout=$(($(time_in_seconds) + $P4D_TIMEOUT))
+ nr_tries_left=$P4D_TIMEOUT
while true
do
- if test $(time_in_seconds) -gt $timeout
+ if test $nr_tries_left -eq 0
then
kill -9 $p4d_pid
exit 1
fi
sleep 1
+ nr_tries_left=$(($nr_tries_left - 1))
done &
watchdog_pid=$!
@@ -167,10 +159,11 @@ p4_add_job () {
}
retry_until_success () {
- timeout=$(($(time_in_seconds) + $RETRY_TIMEOUT))
- until "$@" 2>/dev/null || test $(time_in_seconds) -gt $timeout
+ nr_tries_left=$RETRY_TIMEOUT
+ until "$@" 2>/dev/null || test $nr_tries_left -eq 0
do
sleep 1
+ nr_tries_left=$(($nr_tries_left - 1))
done
}