Skip to content

Commit e4326eb

Browse files
authored
🎨E2E: adapt test to new service startup status (#6363)
1 parent 4699e19 commit e4326eb

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class NodeProgressType(str, Enum):
5858
SERVICE_OUTPUTS_PULLING = "SERVICE_OUTPUTS_PULLING"
5959
SERVICE_STATE_PULLING = "SERVICE_STATE_PULLING"
6060
SERVICE_IMAGES_PULLING = "SERVICE_IMAGES_PULLING"
61+
SERVICE_CONTAINERS_STARTING = "SERVICE_CONTAINERS_STARTING"
6162

6263
@classmethod
6364
def required_types_for_started_service(cls) -> set["NodeProgressType"]:
@@ -67,6 +68,7 @@ def required_types_for_started_service(cls) -> set["NodeProgressType"]:
6768
NodeProgressType.SERVICE_OUTPUTS_PULLING,
6869
NodeProgressType.SERVICE_STATE_PULLING,
6970
NodeProgressType.SERVICE_IMAGES_PULLING,
71+
NodeProgressType.SERVICE_CONTAINERS_STARTING,
7072
}
7173

7274

packages/pytest-simcore/src/pytest_simcore/helpers/playwright_sim4life.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import logging
33
import re
44
from dataclasses import dataclass
5-
from typing import Dict, Final, Union
5+
from typing import Final, TypedDict
66

77
import arrow
88
from playwright.sync_api import FrameLocator, Page, WebSocket, expect
99

1010
from .logging_tools import log_context
1111
from .playwright import (
12-
SECOND,
1312
MINUTE,
13+
SECOND,
1414
SOCKETIO_MESSAGE_PREFIX,
1515
SocketIOEvent,
1616
decode_socketio_42_message,
@@ -30,6 +30,7 @@
3030
_S4L_STARTUP_SCREEN_MAX_TIME: Final[int] = 45 * SECOND
3131
_S4L_COPY_WORKSPACE_TIME: Final[int] = 60 * SECOND
3232

33+
3334
@dataclass(kw_only=True)
3435
class S4LWaitForWebsocket:
3536
logger: logging.Logger
@@ -84,7 +85,19 @@ def __call__(self, message: str) -> bool:
8485
return False
8586

8687

87-
def launch_S4L(page: Page, node_id, log_in_and_out: WebSocket, autoscaled: bool, copy_workspace: bool = False) -> Dict[str, Union[WebSocket, FrameLocator]]:
88+
class WaitForS4LDict(TypedDict):
89+
websocket: WebSocket
90+
iframe: FrameLocator
91+
92+
93+
def wait_for_launched_s4l(
94+
page: Page,
95+
node_id,
96+
log_in_and_out: WebSocket,
97+
*,
98+
autoscaled: bool,
99+
copy_workspace: bool,
100+
) -> WaitForS4LDict:
88101
with log_context(logging.INFO, "launch S4L") as ctx:
89102
predicate = S4LWaitForWebsocket(logger=ctx.logger)
90103
with page.expect_websocket(
@@ -95,11 +108,7 @@ def launch_S4L(page: Page, node_id, log_in_and_out: WebSocket, autoscaled: bool,
95108
if autoscaled
96109
else _S4L_MAX_STARTUP_TIME
97110
)
98-
+ (
99-
_S4L_COPY_WORKSPACE_TIME
100-
if copy_workspace
101-
else 0
102-
)
111+
+ (_S4L_COPY_WORKSPACE_TIME if copy_workspace else 0)
103112
+ 10 * SECOND,
104113
) as ws_info:
105114
s4l_iframe = wait_for_service_running(
@@ -111,30 +120,28 @@ def launch_S4L(page: Page, node_id, log_in_and_out: WebSocket, autoscaled: bool,
111120
if autoscaled
112121
else _S4L_MAX_STARTUP_TIME
113122
)
114-
+ (
115-
_S4L_COPY_WORKSPACE_TIME
116-
if copy_workspace
117-
else 0
118-
),
123+
+ (_S4L_COPY_WORKSPACE_TIME if copy_workspace else 0),
119124
press_start_button=False,
120125
)
121126
s4l_websocket = ws_info.value
122127
ctx.logger.info("acquired S4L websocket!")
123128
return {
124129
"websocket": s4l_websocket,
125-
"iframe" : s4l_iframe,
130+
"iframe": s4l_iframe,
126131
}
127132

128133

129-
def interact_with_S4L(page: Page, s4l_iframe: FrameLocator) -> None:
134+
def interact_with_s4l(page: Page, s4l_iframe: FrameLocator) -> None:
130135
# Wait until grid is shown
131136
# NOTE: the startup screen should disappear very fast after the websocket was acquired
132137
with log_context(logging.INFO, "Interact with S4l"):
133138
s4l_iframe.get_by_test_id("tree-item-Grid").nth(0).click()
134139
page.wait_for_timeout(3000)
135140

136141

137-
def check_video_streaming(page: Page, s4l_iframe: FrameLocator, s4l_websocket: WebSocket) -> None:
142+
def check_video_streaming(
143+
page: Page, s4l_iframe: FrameLocator, s4l_websocket: WebSocket
144+
) -> None:
138145
with log_context(logging.INFO, "Check videostreaming works") as ctx:
139146
waiter = _S4LSocketIOCheckBitRateIncreasesMessagePrinter(
140147
observation_time=datetime.timedelta(

tests/e2e-playwright/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,18 @@ $(SLEEPERS_INPUT_FILE) $(JUPYTER_LAB_INPUT_FILE) $(CLASSIC_TIP_INPUT_FILE) $(S4L
131131
read -p "Enter the size of the large file (human readable form e.g. 3Gib): " LARGE_FILE_SIZE; \
132132
echo "--service-key=jupyter-math --large-file-size=$$LARGE_FILE_SIZE" >> $@; \
133133
elif [ "$@" = "$(S4L_INPUT_FILE)" ]; then \
134-
echo "--plus_button_test_id=startS4LButton" >> $@; \
135134
read -p "Do you want to check the videostreaming ? (requires to run with chrome/msedge) [y/n]: " VIDEOSTREAM; \
136135
if [ "$$VIDEOSTREAM" = "y" ]; then \
137136
echo "--check-videostreaming" >> $@; \
138137
fi; \
139138
read -p "Do you want to use the plus button (NOTE: if yes then pass the osparc-test-ID of the plus button in the service key) ? [y/n]: " PLUS_BUTTON; \
140139
if [ "$$PLUS_BUTTON" = "y" ]; then \
140+
echo "--service-key=startS4LButton" >> $@; \
141141
echo "--use-plus-button" >> $@; \
142+
else \
143+
read -p "Enter the service key: " SERVICE_KEY; \
144+
echo "--service-key=$$SERVICE_KEY" >> $@; \
142145
fi; \
143-
read -p "Enter the service key: " SERVICE_KEY; \
144-
echo "--service-key=$$SERVICE_KEY" >> $@; \
145146
elif [ "$@" = "$(SLEEPERS_INPUT_FILE)" ]; then \
146147
read -p "Enter the number of sleepers: " NUM_SLEEPERS; \
147148
echo "--num-sleepers=$$NUM_SLEEPERS" >> $@; \

tests/e2e-playwright/tests/sim4life/test_sim4life.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
from playwright.sync_api import Page, WebSocket
1414
from pytest_simcore.helpers.playwright import ServiceType
1515
from pytest_simcore.helpers.playwright_sim4life import (
16-
launch_S4L,
17-
interact_with_S4L,
1816
check_video_streaming,
17+
interact_with_s4l,
18+
wait_for_launched_s4l,
1919
)
2020

2121

@@ -45,10 +45,12 @@ def test_sim4life(
4545
node_ids: list[str] = list(project_data["workbench"])
4646
assert len(node_ids) == 1, "Expected 1 node in the workbench!"
4747

48-
resp = launch_S4L(page, node_ids[0], log_in_and_out, autoscaled)
48+
resp = wait_for_launched_s4l(
49+
page, node_ids[0], log_in_and_out, autoscaled=autoscaled, copy_workspace=False
50+
)
4951
s4l_websocket = resp["websocket"]
5052
s4l_iframe = resp["iframe"]
51-
interact_with_S4L(page, s4l_iframe)
53+
interact_with_s4l(page, s4l_iframe)
5254

5355
if check_videostreaming:
5456
check_video_streaming(page, s4l_iframe, s4l_websocket)

tests/e2e-playwright/tests/sim4life/test_template.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
from playwright.sync_api import Page, WebSocket
1414
from pytest_simcore.helpers.playwright_sim4life import (
15-
launch_S4L,
16-
interact_with_S4L,
1715
check_video_streaming,
16+
interact_with_s4l,
17+
wait_for_launched_s4l,
1818
)
1919

2020

@@ -35,10 +35,12 @@ def test_template(
3535
node_ids: list[str] = list(project_data["workbench"])
3636
assert len(node_ids) == 1, "Expected 1 node in the workbench!"
3737

38-
resp = launch_S4L(page, node_ids[0], log_in_and_out, autoscaled, copy_workspace=True)
38+
resp = wait_for_launched_s4l(
39+
page, node_ids[0], log_in_and_out, autoscaled=autoscaled, copy_workspace=True
40+
)
3941
s4l_websocket = resp["websocket"]
4042
s4l_iframe = resp["iframe"]
41-
interact_with_S4L(page, s4l_iframe)
43+
interact_with_s4l(page, s4l_iframe)
4244

4345
if check_videostreaming:
4446
check_video_streaming(page, s4l_iframe, s4l_websocket)

0 commit comments

Comments
 (0)