Skip to content

Commit 5886b75

Browse files
committed
add waiter
1 parent 2e432ba commit 5886b75

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

tests/e2e-playwright/tests/jupyterlabs/test_jupyterlab.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
from typing import Any, Final, Literal
1515

1616
from playwright.sync_api import Page, WebSocket
17-
from pydantic import ByteSize
17+
from pydantic import AnyUrl, ByteSize
1818
from pytest_simcore.helpers.logging_tools import log_context
1919
from pytest_simcore.helpers.playwright import (
2020
MINUTE,
2121
SECOND,
2222
RestartableWebSocket,
2323
ServiceType,
24+
wait_for_service_running,
2425
)
2526

2627
_WAITING_FOR_SERVICE_TO_START: Final[int] = (
@@ -46,45 +47,61 @@ class _JLabTerminalWebSocketWaiter:
4647
def __call__(self, message: str) -> bool:
4748
with log_context(logging.DEBUG, msg=f"handling websocket {message=}"):
4849
decoded_message = json.loads(message)
49-
if (
50+
return bool(
5051
self.expected_message_type == decoded_message[0]
5152
and self.expected_message_contents in decoded_message[1]
52-
):
53-
return True
54-
55-
return False
53+
)
5654

5755

5856
@dataclass
5957
class _JLabWaitForTerminalWebSocket:
6058
def __call__(self, new_websocket: WebSocket) -> bool:
6159
with log_context(logging.DEBUG, msg=f"received {new_websocket=}"):
62-
if "terminals/websocket" in new_websocket.url:
63-
return True
64-
65-
return False
60+
return "terminals/websocket" in new_websocket.url
6661

6762

6863
def test_jupyterlab(
6964
page: Page,
65+
log_in_and_out: RestartableWebSocket,
7066
create_project_from_service_dashboard: Callable[
7167
[ServiceType, str, str | None], dict[str, Any]
7268
],
7369
service_key: str,
7470
large_file_size: ByteSize,
7571
large_file_block_size: ByteSize,
72+
product_url: AnyUrl,
7673
):
7774
# NOTE: this waits for the jupyter to send message, but is not quite enough
78-
with log_context(
79-
logging.INFO,
80-
f"Waiting for {service_key} to be responsive (waiting for {_SERVICE_NAME_EXPECTED_RESPONSE_TO_WAIT_FOR.get(service_key, _DEFAULT_RESPONSE_TO_WAIT_FOR)})",
81-
), page.expect_response(
82-
_SERVICE_NAME_EXPECTED_RESPONSE_TO_WAIT_FOR.get(
83-
service_key, _DEFAULT_RESPONSE_TO_WAIT_FOR
75+
with (
76+
log_context(
77+
logging.INFO,
78+
f"Waiting for {service_key} to be responsive (waiting for {_SERVICE_NAME_EXPECTED_RESPONSE_TO_WAIT_FOR.get(service_key, _DEFAULT_RESPONSE_TO_WAIT_FOR)})",
79+
),
80+
page.expect_response(
81+
_SERVICE_NAME_EXPECTED_RESPONSE_TO_WAIT_FOR.get(
82+
service_key, _DEFAULT_RESPONSE_TO_WAIT_FOR
83+
),
84+
timeout=_WAITING_FOR_SERVICE_TO_START,
8485
),
85-
timeout=_WAITING_FOR_SERVICE_TO_START,
8686
):
87-
create_project_from_service_dashboard(ServiceType.DYNAMIC, service_key, None)
87+
project_data = create_project_from_service_dashboard(
88+
ServiceType.DYNAMIC, service_key, None
89+
)
90+
assert "workbench" in project_data, "Expected workbench to be in project data!"
91+
assert isinstance(
92+
project_data["workbench"], dict
93+
), "Expected workbench to be a dict!"
94+
node_ids: list[str] = list(project_data["workbench"])
95+
assert len(node_ids) == 1, "Expected 1 node in the workbench!"
96+
97+
wait_for_service_running(
98+
page=page,
99+
node_id=node_ids[0],
100+
websocket=log_in_and_out,
101+
timeout=_WAITING_FOR_SERVICE_TO_START,
102+
press_start_button=False,
103+
product_url=product_url,
104+
)
88105

89106
iframe = page.frame_locator("iframe")
90107
if service_key == "jupyter-octave-python-math":

0 commit comments

Comments
 (0)