From 996e5932a2c90b7463bbe0067695a1b513073707 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Mon, 15 Oct 2018 16:00:11 -0700 Subject: [PATCH] tests: More accurately compute waited time If test function takes significant time, this will ensure that we don't wait more the requested wait time. Reviewed-by: James Valleroy --- functional_tests/support/service.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/functional_tests/support/service.py b/functional_tests/support/service.py index aa5d6436f..1ef9b85a3 100644 --- a/functional_tests/support/service.py +++ b/functional_tests/support/service.py @@ -16,7 +16,7 @@ # from contextlib import contextmanager -from time import sleep +import time from selenium.common.exceptions import StaleElementReferenceException from selenium.webdriver.support.ui import WebDriverWait @@ -49,13 +49,14 @@ def is_not_running(browser, service_name): def eventually(function, args=[], timeout=30): """Execute a function returning a boolean expression till it returns True or a timeout is reached""" - waited_time = 0 - while waited_time < timeout: + end_time = time.time() + timeout + current_time = time.time() + while current_time < end_time: if function(*args): return True - sleep(0.1) - waited_time += 0.1 + time.sleep(0.1) + current_time = time.time() return False