Parameterize polling retry count and wait period
@@ -4,18 +4,22 @@ function poll_until_equals() {
local what="$1"
local expected="$2"
local check_cmd="$3"
- poll_until_true "$what" "[ '$expected' = \"\$( $check_cmd )\" ]"
+ local retries="$4"
+ local wait_period="$5"
+ poll_until_true "$what" "[ '$expected' = \"\$( $check_cmd )\" ]" "$retries" "$wait_period"
}
function poll_until_true() {
local what="$1"
local check_cmd="$2"
+ # timeout after $retries * $wait_period seconds
+ local retries=${3:-24}
+ local wait_period=${4:-5}
echo -n ">>> Waiting for $what " >&3
- retries=24
count=0
until eval "$check_cmd"; do
echo -n '.' >&3
- sleep 5
+ sleep $wait_period
count=$(($count + 1))
if [[ ${count} -eq ${retries} ]]; then
echo ' No more retries left!' >&3
