Skip to contentSkip to conversation

testcases/lib/test.sh: add tst_retry() to ensure cmd exec succeed

PATCH Cyril Hrubis 1 participant 1 message Jul 16, 2015 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

Hi!

Quoted 18 lines
---
 testcases/lib/test.sh | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
testcases/lib/test.sh +5 -0
index 1c9b126..60a9984 100644
@@ -134,6 +134,26 @@ tst_check_cmds()
 	done
 }
 
+# tst_retry "command" [times]
+# try run command for specified times, default is 3.
+# Function returns 0 if succeed in RETRIES times or the last retcode the cmd
+# returned
+tst_retry()

testcases/lib/test.sh tst_check_cmds() · line 151

Quoted 10 lines
testcases/lib/test.sh +10 -0
+{
+	local cmd="$1"
+	local RETRIES=${2:-"3"}
+	while [ $RETRIES -gt 0 ]; do
+		eval "$cmd"
+		ret=$?
+		if [ $ret -eq 0 ]; then
+			break
+		fi
+		let RETRIES=$((RETRIES-1))

The let keyword is known only by bash. So the whole line should just be the RETRIES=$((RETRIES-1)).

Have a look at https://wiki.ubuntu.com/DashAsBinSh#let

Quoted 11 lines
testcases/lib/test.sh +5 -0
+		sleep 1
+	done
+	return $ret
+}
+
 # tst_timeout "command arg1 arg2 ..." timeout
 # Runs command for specified timeout (in seconds).
 # Function returns retcode of command or 1 if arguments are invalid.
Signature · 1 line
1.9.3
Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list