mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-07-22 11:59:33 +00:00
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 <jvalleroy@mailbox.org>
This commit is contained in:
parent
962fb0d678
commit
996e5932a2
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user