]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: Enhance get_timeout_delays()
authorDavid Zafman <dzafman@redhat.com>
Wed, 23 Nov 2016 05:32:34 +0000 (21:32 -0800)
committerDavid Zafman <dzafman@redhat.com>
Wed, 23 Nov 2016 05:32:34 +0000 (21:32 -0800)
Do all math using bc so we can have fractions
Allow caller to specify the first step (default 1)
Add testing of fractional first step

Signed-off-by: David Zafman <dzafman@redhat.com>
qa/workunits/ceph-helpers.sh

index 49dfac16a99c279c470f4d73bdf188f8d2dbd9c5..3fb89078e99c3bdd89000f9d94aa045824c8c401 100755 (executable)
@@ -1082,17 +1082,19 @@ function test_is_clean() {
 # @return a list of sleep delays
 #
 function get_timeout_delays() {
-    local -i timeout=$1
-    local -i first_step=1
+    local timeout=$1
+    local first_step=${2:-1}
 
-    local -i i
-    local -i total=0
-    for (( i = $first_step ; $total + $i <= $timeout ; i *= 2 )) ; do
+    local i
+    local total="0"
+    i=$first_step
+    while test "$(echo $total + $i \<= $timeout | bc -l)" = "1"; do
         echo -n "$i "
-        total+=$i
+        total=$(echo $total + $i | bc -l)
+        i=$(echo $i \* 2 | bc -l)
     done
-    if (( $total < $timeout )) ; then
-        echo -n $(( $timeout - $total ))
+    if test "$(echo $total \< $timeout | bc -l)" = "1"; then
+        echo -n $(echo $timeout - $total | bc -l)
     fi
 }
 
@@ -1102,6 +1104,12 @@ function test_get_timeout_delays() {
     test "$(get_timeout_delays 6)" = "1 2 3" || return 1
     test "$(get_timeout_delays 7)" = "1 2 4 " || return 1
     test "$(get_timeout_delays 8)" = "1 2 4 1" || return 1
+    test "$(get_timeout_delays 1 .1)" = ".1 .2 .4 .3" || return 1
+    test "$(get_timeout_delays 1.5 .1)" = ".1 .2 .4 .8 " || return 1
+    test "$(get_timeout_delays 5 .1)" = ".1 .2 .4 .8 1.6 1.9" || return 1
+    test "$(get_timeout_delays 6 .1)" = ".1 .2 .4 .8 1.6 2.9" || return 1
+    test "$(get_timeout_delays 6.3 .1)" = ".1 .2 .4 .8 1.6 3.2 " || return 1
+    test "$(get_timeout_delays 20 .1)" = ".1 .2 .4 .8 1.6 3.2 6.4 7.3" || return 1
 }
 
 #######################################################################