ctdb-tests: Move test duration calculation to ctdb_test_run()
authorMartin Schwenke <martin@meltin.net>
Tue, 10 Sep 2019 00:51:31 +0000 (10:51 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 4 Oct 2019 09:41:29 +0000 (09:41 +0000)
It makes sense to do this in one place in case other headers/footers
are added.

Reindent ctdb_test_begin() while touching this function.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/run_tests.sh

index a97ce63e3d54057bafe7045ef6bac604f58d50f5..6e4082e396a98c4129a341395c50c38ec5ba4529 100755 (executable)
@@ -87,14 +87,11 @@ fi
 
 ctdb_test_begin ()
 {
-    local name="$1"
+       local name="$1"
 
-    teststarttime=$(date '+%s')
-    testduration=0
-
-    echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
-    echo "Running test $name ($(date '+%T'))"
-    echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
+       echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
+       echo "Running test $name ($(date '+%T'))"
+       echo "--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--"
 }
 
 ctdb_test_end ()
@@ -102,6 +99,7 @@ ctdb_test_end ()
        local f="$1"
        local status="$2"
        local interp="$3"
+       local duration="$4"
 
        local statstr=""
        if [ "$status" -eq 0 ] ; then
@@ -110,10 +108,8 @@ ctdb_test_end ()
                statstr=" (status $status)"
        fi
 
-       testduration=$(($(date +%s) - teststarttime))
-
        echo "=========================================================================="
-       echo "TEST ${interp}: ${f}${statstr} (duration: ${testduration}s)"
+       echo "TEST ${interp}: ${f}${statstr} (duration: ${duration}s)"
        echo "=========================================================================="
 }
 
@@ -124,6 +120,10 @@ ctdb_test_run ()
        $no_header || ctdb_test_begin "$f"
 
        local status=0
+       local start_time
+
+       start_time=$(date '+%s')
+
        if [ -x "$f" ] ; then
                timeout "$test_time_limit" "$f" | show_progress
                status=$?
@@ -132,6 +132,8 @@ ctdb_test_run ()
                status=99
        fi
 
+       local duration=$(($(date +%s) - start_time))
+
        tests_total=$((tests_total + 1))
 
        local interp
@@ -158,7 +160,7 @@ ctdb_test_run ()
                ;;
        esac
 
-       $no_header || ctdb_test_end "$f" "$status" "$interp"
+       $no_header || ctdb_test_end "$f" "$status" "$interp" "$duration"
 
        if $with_summary ; then
                local t