From 88a349b6d0b39e636f28b09f23cfea8d3ac85b9f Mon Sep 17 00:00:00 2001 From: matusdrobuliak66 Date: Wed, 29 Jan 2025 13:07:12 +0100 Subject: [PATCH] be compatible with legacy services --- .../src/pytest_simcore/helpers/playwright.py | 12 +++++++++++- .../pytest_simcore/helpers/playwright_sim4life.py | 2 ++ tests/e2e-playwright/tests/conftest.py | 12 ++++++++++++ .../tests/jupyterlabs/test_jupyterlab.py | 2 ++ tests/e2e-playwright/tests/sim4life/test_sim4life.py | 2 ++ tests/e2e-playwright/tests/sim4life/test_template.py | 2 ++ tests/e2e-playwright/tests/tip/test_ti_plan.py | 4 ++++ 7 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py b/packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py index e6c1bf3cabe5..987457182893 100644 --- a/packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py +++ b/packages/pytest-simcore/src/pytest_simcore/helpers/playwright.py @@ -294,6 +294,7 @@ class SocketIONodeProgressCompleteWaiter: logger: logging.Logger product_url: AnyUrl api_request_context: APIRequestContext + is_service_legacy: bool _current_progress: dict[NodeProgressType, float] = field( default_factory=defaultdict ) @@ -336,7 +337,12 @@ def __call__(self, message: str) -> bool: _current_timestamp = datetime.now(UTC) if _current_timestamp - self._last_poll_timestamp > timedelta(seconds=5): - url = f"https://{self.node_id}.services.{self.get_partial_product_url()}" + if self.is_service_legacy: + url = f"https://{self.get_partial_product_url()}x/{self.node_id}/" + else: + url = ( + f"https://{self.node_id}.services.{self.get_partial_product_url()}" + ) response = self.api_request_context.get(url, timeout=1000) level = logging.DEBUG if (response.status >= 400) and (response.status not in (502, 503)): @@ -431,6 +437,7 @@ def expected_service_running( timeout: int, press_start_button: bool, product_url: AnyUrl, + is_service_legacy: bool, ) -> Generator[ServiceRunning, None, None]: with log_context( logging.INFO, msg=f"Waiting for node to run. Timeout: {timeout}" @@ -440,6 +447,7 @@ def expected_service_running( logger=ctx.logger, product_url=product_url, api_request_context=page.request, + is_service_legacy=is_service_legacy, ) service_running = ServiceRunning(iframe_locator=None) @@ -472,6 +480,7 @@ def wait_for_service_running( timeout: int, press_start_button: bool, product_url: AnyUrl, + is_service_legacy: bool, ) -> FrameLocator: """NOTE: if the service was already started this will not work as some of the required websocket events will not be emitted again In which case this will need further adjutment""" @@ -484,6 +493,7 @@ def wait_for_service_running( logger=ctx.logger, product_url=product_url, api_request_context=page.request, + is_service_legacy=is_service_legacy, ) with websocket.expect_event("framereceived", waiter, timeout=timeout): if press_start_button: diff --git a/packages/pytest-simcore/src/pytest_simcore/helpers/playwright_sim4life.py b/packages/pytest-simcore/src/pytest_simcore/helpers/playwright_sim4life.py index 8c5b74d032bf..ae2f3d28a0ed 100644 --- a/packages/pytest-simcore/src/pytest_simcore/helpers/playwright_sim4life.py +++ b/packages/pytest-simcore/src/pytest_simcore/helpers/playwright_sim4life.py @@ -106,6 +106,7 @@ def wait_for_launched_s4l( autoscaled: bool, copy_workspace: bool, product_url: AnyUrl, + is_service_legacy: bool, ) -> WaitForS4LDict: with log_context(logging.INFO, "launch S4L") as ctx: predicate = S4LWaitForWebsocket(logger=ctx.logger) @@ -132,6 +133,7 @@ def wait_for_launched_s4l( + (_S4L_COPY_WORKSPACE_TIME if copy_workspace else 0), press_start_button=False, product_url=product_url, + is_service_legacy=is_service_legacy, ) s4l_websocket = ws_info.value ctx.logger.info("acquired S4L websocket!") diff --git a/tests/e2e-playwright/tests/conftest.py b/tests/e2e-playwright/tests/conftest.py index 600a314c7168..f166dfe893ac 100644 --- a/tests/e2e-playwright/tests/conftest.py +++ b/tests/e2e-playwright/tests/conftest.py @@ -106,6 +106,12 @@ def pytest_addoption(parser: pytest.Parser) -> None: default=None, help="Service Key", ) + group.addoption( + "--service-is-legacy", + action="store_true", + default=False, + help="Whether service is a legacy service (no sidecar)", + ) group.addoption( "--template-id", action="store", @@ -260,6 +266,12 @@ def service_key(request: pytest.FixtureRequest) -> str: return os.environ["SERVICE_KEY"] +@pytest.fixture(scope="session") +def is_service_legacy(request: pytest.FixtureRequest) -> bool: + autoscaled = request.config.getoption("--service-is-legacy") + return TypeAdapter(bool).validate_python(autoscaled) + + @pytest.fixture(scope="session") def template_id(request: pytest.FixtureRequest) -> str | None: if key := request.config.getoption("--template-id"): diff --git a/tests/e2e-playwright/tests/jupyterlabs/test_jupyterlab.py b/tests/e2e-playwright/tests/jupyterlabs/test_jupyterlab.py index 911bb5e6b603..fcd20bbbd042 100644 --- a/tests/e2e-playwright/tests/jupyterlabs/test_jupyterlab.py +++ b/tests/e2e-playwright/tests/jupyterlabs/test_jupyterlab.py @@ -70,6 +70,7 @@ def test_jupyterlab( large_file_size: ByteSize, large_file_block_size: ByteSize, product_url: AnyUrl, + is_service_legacy: bool, ): # NOTE: this waits for the jupyter to send message, but is not quite enough with ( @@ -101,6 +102,7 @@ def test_jupyterlab( timeout=_WAITING_FOR_SERVICE_TO_START, press_start_button=False, product_url=product_url, + is_service_legacy=is_service_legacy, ) iframe = page.frame_locator("iframe") diff --git a/tests/e2e-playwright/tests/sim4life/test_sim4life.py b/tests/e2e-playwright/tests/sim4life/test_sim4life.py index 28b6ecf56a7c..10a9ddcf97ec 100644 --- a/tests/e2e-playwright/tests/sim4life/test_sim4life.py +++ b/tests/e2e-playwright/tests/sim4life/test_sim4life.py @@ -32,6 +32,7 @@ def test_sim4life( is_autoscaled: bool, check_videostreaming: bool, product_url: AnyUrl, + is_service_legacy: bool, ): if use_plus_button: project_data = create_project_from_new_button(service_key) @@ -54,6 +55,7 @@ def test_sim4life( autoscaled=is_autoscaled, copy_workspace=False, product_url=product_url, + is_service_legacy=is_service_legacy, ) s4l_websocket = resp["websocket"] s4l_iframe = resp["iframe"] diff --git a/tests/e2e-playwright/tests/sim4life/test_template.py b/tests/e2e-playwright/tests/sim4life/test_template.py index 423437e04a45..0ead8379e1db 100644 --- a/tests/e2e-playwright/tests/sim4life/test_template.py +++ b/tests/e2e-playwright/tests/sim4life/test_template.py @@ -28,6 +28,7 @@ def test_template( is_autoscaled: bool, check_videostreaming: bool, product_url: AnyUrl, + is_service_legacy: bool, ): project_data = create_project_from_template_dashboard(template_id) @@ -45,6 +46,7 @@ def test_template( autoscaled=is_autoscaled, copy_workspace=True, product_url=product_url, + is_service_legacy=is_service_legacy, ) s4l_websocket = resp["websocket"] s4l_iframe = resp["iframe"] diff --git a/tests/e2e-playwright/tests/tip/test_ti_plan.py b/tests/e2e-playwright/tests/tip/test_ti_plan.py index e03055db3241..157778ff549f 100644 --- a/tests/e2e-playwright/tests/tip/test_ti_plan.py +++ b/tests/e2e-playwright/tests/tip/test_ti_plan.py @@ -95,6 +95,7 @@ def test_classic_ti_plan( # noqa: PLR0915 is_product_lite: bool, create_tip_plan_from_dashboard: Callable[[str], dict[str, Any]], product_url: AnyUrl, + is_service_legacy: bool, ): with log_context(logging.INFO, "Checking 'Access TIP' teaser"): # click to open and expand @@ -145,6 +146,7 @@ def test_classic_ti_plan( # noqa: PLR0915 ), press_start_button=False, product_url=product_url, + is_service_legacy=is_service_legacy, ) # NOTE: Sometimes this iframe flicks and shows a white page. This wait will avoid it page.wait_for_timeout(_ELECTRODE_SELECTOR_FLICKERING_WAIT_TIME) @@ -205,6 +207,7 @@ def test_classic_ti_plan( # noqa: PLR0915 ), press_start_button=False, product_url=product_url, + is_service_legacy=is_service_legacy, ) as service_running: app_mode_trigger_next_app(page) ti_iframe = service_running.iframe_locator @@ -318,6 +321,7 @@ def test_classic_ti_plan( # noqa: PLR0915 ), press_start_button=False, product_url=product_url, + is_service_legacy=is_service_legacy, ) as service_running: app_mode_trigger_next_app(page) s4l_postpro_iframe = service_running.iframe_locator