|
25 | 25 | expected_service_running, |
26 | 26 | wait_for_service_running, |
27 | 27 | ) |
| 28 | +from tenacity import RetryError, retry, stop_after_delay, wait_fixed |
28 | 29 |
|
29 | 30 | _GET_NODE_OUTPUTS_REQUEST_PATTERN: Final[re.Pattern[str]] = re.compile( |
30 | 31 | r"/storage/locations/[^/]+/files" |
@@ -89,6 +90,17 @@ def __call__(self, message: str) -> bool: |
89 | 90 | return False |
90 | 91 |
|
91 | 92 |
|
| 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 | + |
92 | 104 | def test_classic_ti_plan( # noqa: PLR0915 |
93 | 105 | page: Page, |
94 | 106 | log_in_and_out: RobustWebSocket, |
@@ -224,21 +236,15 @@ def test_classic_ti_plan( # noqa: PLR0915 |
224 | 236 | assert not ws_info.value.is_closed() |
225 | 237 | restartable_jlab_websocket = RobustWebSocket(page, ws_info.value) |
226 | 238 |
|
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}") |
242 | 248 |
|
243 | 249 | with log_context(logging.INFO, "Create report"): |
244 | 250 | with log_context( |
|
0 commit comments