Skip to content

Commit

Permalink
FIXUP bring back timeout warning
Browse files Browse the repository at this point in the history
  • Loading branch information
martinpitt committed Aug 6, 2024
1 parent cb40703 commit d32f536
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,13 +744,19 @@ def wait(self, predicate: Callable[[], _T | None]) -> _T:
raise Error('timed out waiting for predicate to become true')

def wait_js_cond(self, cond: str, error_description: str = "null") -> None:
# TODO: bring back the "WARNING: Waiting for {cond} took {duration:.1f} seconds" warning
timeout = self.timeout * self.timeout_factor
start = time.time()
last_error = None
for _retry in range(5):
try:
self.bidi("script.evaluate",
expression=f"ph_wait_cond(() => {cond}, {self.timeout * 1000}, {error_description})",
expression=f"ph_wait_cond(() => {cond}, {timeout * 1000}, {error_description})",
awaitPromise=True, target={"context": self.driver.context})

duration = time.time() - start
percent = int(duration / timeout * 100)
if percent >= 50:
print(f"WARNING: Waiting for {cond} took {duration:.1f} seconds, which is {percent}% of the timeout.")
return
except Error as e:
last_error = e
Expand All @@ -769,11 +775,15 @@ def wait_js_cond(self, cond: str, error_description: str = "null") -> None:
"MessageHandlerFrame' destroyed" in str(e)
):
bidi.log_command.info("wait_js_cond: Ignoring/retrying %r", e)
if time.time() - start > timeout:
break

time.sleep(1)
continue

break

assert last_error
raise last_error

def wait_js_func(self, func: str, *args: object) -> None:
Expand Down

0 comments on commit d32f536

Please sign in to comment.