From fd8582906d7878287b37786c05bfc98187adfe4d Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Wed, 1 Aug 2018 20:02:59 -0300 Subject: [PATCH] lib: show run_and_expect spent time Standardize run_and_expect to show start and end time along with maximum estimated wait time. Signed-off-by: Rafael Zalamena --- tests/topotests/lib/topotest.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 1cbde825ac..b5c9bbe165 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -27,6 +27,7 @@ import os import errno import re import sys +import functools import glob import StringIO import subprocess @@ -207,13 +208,32 @@ def run_and_expect(func, what, count=20, wait=3): Returns (True, func-return) on success or (False, func-return) on failure. """ + start_time = time.time() + func_name = "" + if func.__class__ == functools.partial: + func_name = func.func.__name__ + else: + func_name = func.__name__ + + logger.info( + "'{}' polling started (interval {} secs, maximum wait {} secs)".format( + func_name, wait, int(wait * count))) + while count > 0: result = func() if result != what: time.sleep(wait) count -= 1 continue + + end_time = time.time() + logger.info("'{}' succeeded after {:.2f} seconds".format( + func_name, end_time - start_time)) return (True, result) + + end_time = time.time() + logger.error("'{}' failed after {:.2f} seconds".format( + func_name, end_time - start_time)) return (False, result) -- 2.39.5