Skip to content

Commit b4ffe76

Browse files
authored
[e2e] Fix TIP test (#7533)
1 parent 301f34c commit b4ffe76

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

tests/e2e-playwright/tests/tip/test_ti_plan.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
expected_service_running,
2626
wait_for_service_running,
2727
)
28+
from tenacity import RetryError, retry, stop_after_delay, wait_fixed
2829

2930
_GET_NODE_OUTPUTS_REQUEST_PATTERN: Final[re.Pattern[str]] = re.compile(
3031
r"/storage/locations/[^/]+/files"
@@ -89,6 +90,17 @@ def __call__(self, message: str) -> bool:
8990
return False
9091

9192

93+
@retry(
94+
stop=stop_after_delay(_JLAB_RUN_OPTIMIZATION_MAX_TIME / 1000), # seconds
95+
wait=wait_fixed(2),
96+
reraise=True,
97+
)
98+
def _wait_for_optimization_complete(run_button):
99+
bg_color = run_button.evaluate("el => getComputedStyle(el).backgroundColor")
100+
if bg_color != "rgb(0, 128, 0)":
101+
raise ValueError("Optimization not finished yet: {bg_color=}, {run_button=}")
102+
103+
92104
def test_classic_ti_plan( # noqa: PLR0915
93105
page: Page,
94106
log_in_and_out: RobustWebSocket,
@@ -224,21 +236,15 @@ def test_classic_ti_plan( # noqa: PLR0915
224236
assert not ws_info.value.is_closed()
225237
restartable_jlab_websocket = RobustWebSocket(page, ws_info.value)
226238

227-
with (
228-
log_context(logging.INFO, "Run optimization"),
229-
restartable_jlab_websocket.expect_event(
230-
"framereceived",
231-
_JLabWebSocketWaiter(
232-
expected_header_msg_type="stream",
233-
expected_message_contents="All results evaluated",
234-
),
235-
timeout=_JLAB_RUN_OPTIMIZATION_MAX_TIME
236-
+ _JLAB_RUN_OPTIMIZATION_APPEARANCE_TIME,
237-
),
238-
):
239-
ti_iframe.get_by_role("button", name="Run Optimization").click(
240-
timeout=_JLAB_RUN_OPTIMIZATION_APPEARANCE_TIME
241-
)
239+
with log_context(logging.INFO, "Run optimization") as ctx:
240+
run_button = ti_iframe.get_by_role("button", name="Run Optimization")
241+
run_button.click(timeout=_JLAB_RUN_OPTIMIZATION_APPEARANCE_TIME)
242+
try:
243+
_wait_for_optimization_complete(run_button)
244+
ctx.logger.info("Optimization finished!")
245+
except RetryError as e:
246+
last_exc = e.last_attempt.exception()
247+
ctx.logger.warning(f"Optimization did not finish in time: {last_exc}")
242248

243249
with log_context(logging.INFO, "Create report"):
244250
with log_context(

0 commit comments

Comments
 (0)