git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/11] git p4 test: simplify timeout handling

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Mar 13, 2019, 12:24 UTC
Message-ID
<20190313122419.2210-10-szeder.dev@gmail.com>
In-Reply-To
<20190313122419.2210-1-szeder.dev@gmail.com>

'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>
---
 t/lib-git-p4.sh | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index b5cb5075c2..c18f85082f 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
 }
 
-- 
2.21.0.499.g4d310c7a8e.dirty
Previous: SZEDER GáborNext: SZEDER Gábor
Message 19 of 21 in “tests: introduce 'test_atexit'”
  1. 00/11 tests: introduce 'test_atexit'SZEDER Gábor, Mar 13, 2019
  2. 01/11 test-lib: fix interrupt handling with 'dash' and '--verbose-log -x'SZEDER Gábor, Mar 13, 2019
  3. Junio C HamanoMar 14, 2019
  4. SZEDER GáborMar 14, 2019
  5. 02/11 t/lib-git-daemon: make sure to kill the 'git-daemon' processSZEDER Gábor, Mar 13, 2019
  6. Junio C HamanoMar 14, 2019
  7. 04/11 git-daemon: use 'test_atexit` to stop 'git-daemon'SZEDER Gábor, Mar 13, 2019
  8. 03/11 test-lib: introduce 'test_atexit'SZEDER Gábor, Mar 13, 2019
  9. Junio C HamanoMar 14, 2019
  10. SZEDER GáborMar 14, 2019
  11. Junio C HamanoMar 18, 2019
  12. 05/11 tests: use 'test_atexit' to stop httpdSZEDER Gábor, Mar 13, 2019
  13. Junio C HamanoMar 14, 2019
  14. Junio C HamanoMar 14, 2019
  15. SZEDER GáborMar 14, 2019
  16. 06/11 t0301-credential-cache: use 'test_atexit' to stop the credentials helperSZEDER Gábor, Mar 13, 2019
  17. 07/11 git p4 test: use 'test_atexit' to kill p4d and the watchdog processSZEDER Gábor, Mar 13, 2019
  18. 10/11 git p4 test: disable '-x' tracing in the p4d watchdog loopSZEDER Gábor, Mar 13, 2019
  19. 09/11 git p4 test: simplify timeout handlingSZEDER Gábor, Mar 13, 2019
  20. 11/11 t9811-git-p4-label-import: fix pipeline negationSZEDER Gábor, Mar 13, 2019
  21. 08/11 git p4 test: clean up the p4d cleanup functionsSZEDER Gábor, Mar 13, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.