From d32f5363e12c2dcce8f920f3ff4562bb23a45638 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 6 Aug 2024 11:17:47 +0200 Subject: [PATCH] FIXUP bring back timeout warning --- test/common/testlib.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/common/testlib.py b/test/common/testlib.py index 757cff767318..ae7a37d28981 100644 --- a/test/common/testlib.py +++ b/test/common/testlib.py @@ -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 @@ -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: