Skip to content

Commit 0e67c32

Browse files
szedergitster
authored andcommitted
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>
1 parent 07353d9 commit 0e67c32

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

t/lib-git-p4.sh

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ native_path () {
4444
echo "$path"
4545
}
4646

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

5849
P4PORT=localhost:$P4DPORT
@@ -105,15 +96,16 @@ start_p4d () {
10596
# will be caught with the "kill -0" check below.
10697
i=${P4D_START_PATIENCE:-300}
10798

108-
timeout=$(($(time_in_seconds) + $P4D_TIMEOUT))
99+
nr_tries_left=$P4D_TIMEOUT
109100
while true
110101
do
111-
if test $(time_in_seconds) -gt $timeout
102+
if test $nr_tries_left -eq 0
112103
then
113104
kill -9 $p4d_pid
114105
exit 1
115106
fi
116107
sleep 1
108+
nr_tries_left=$(($nr_tries_left - 1))
117109
done &
118110
watchdog_pid=$!
119111

@@ -167,10 +159,11 @@ p4_add_job () {
167159
}
168160

169161
retry_until_success () {
170-
timeout=$(($(time_in_seconds) + $RETRY_TIMEOUT))
171-
until "$@" 2>/dev/null || test $(time_in_seconds) -gt $timeout
162+
nr_tries_left=$RETRY_TIMEOUT
163+
until "$@" 2>/dev/null || test $nr_tries_left -eq 0
172164
do
173165
sleep 1
166+
nr_tries_left=$(($nr_tries_left - 1))
174167
done
175168
}
176169

0 commit comments

Comments
 (0)