diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index bd291787..f4b58d06 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -23,7 +23,7 @@ jobs: - name: Run Pytest unit tests env: CUSTOMER_IDENTIFIER: "ci-unit-tests" - INTEGRATION_TEST_URL: "https://plugin-testing.canvasmedical.com" + INTEGRATION_TEST_URL: "https://api-test-clinic.canvasmedical.com" INTEGRATION_TEST_CLIENT_ID: ${{ secrets.INTEGRATION_TEST_CLIENT_ID }} INTEGRATION_TEST_CLIENT_SECRET: ${{ secrets.INTEGRATION_TEST_CLIENT_SECRET }} run: poetry run pytest -m "not integtest" --ff --verbosity 2 @@ -33,7 +33,7 @@ jobs: if: matrix.version == '3.12' env: CUSTOMER_IDENTIFIER: "ci-integration-tests" - INTEGRATION_TEST_URL: "https://plugin-testing.canvasmedical.com" + INTEGRATION_TEST_URL: "https://api-test-clinic.canvasmedical.com" INTEGRATION_TEST_CLIENT_ID: ${{ secrets.INTEGRATION_TEST_CLIENT_ID }} INTEGRATION_TEST_CLIENT_SECRET: ${{ secrets.INTEGRATION_TEST_CLIENT_SECRET }} run: poetry run pytest -m "integtest" --ff --verbosity 2 diff --git a/canvas_sdk/commands/tests/protocol/tests.py b/canvas_sdk/commands/tests/protocol/tests.py index d1b83fe2..174477e3 100644 --- a/canvas_sdk/commands/tests/protocol/tests.py +++ b/canvas_sdk/commands/tests/protocol/tests.py @@ -1,8 +1,10 @@ from collections.abc import Generator from datetime import datetime +from typing import cast import pytest +import settings from canvas_sdk.commands.tests.test_utils import ( COMMANDS, MaskedValue, @@ -12,6 +14,7 @@ get_token, install_plugin, trigger_plugin_event, + wait_for_log, write_protocol_code, ) @@ -40,10 +43,18 @@ def write_and_install_protocol_and_clean_up( ) -> Generator[None, None, None]: """Write the protocol code, install the plugin, and clean up after the test.""" write_protocol_code(new_note["externallyExposableId"], plugin_name, COMMANDS) + message_received_event, thread, ws = wait_for_log( + cast(str, settings.INTEGRATION_TEST_URL), + token.value, + f"Loading plugin '{plugin_name}", + ) install_plugin(plugin_name, token) + message_received_event.wait(timeout=5.0) yield + ws.close() + thread.join() clean_up_files_and_plugins(plugin_name, token) @@ -57,8 +68,7 @@ def test_protocol_that_inserts_every_command( commands_in_body = get_original_note_body_commands(new_note["id"], token) # TODO: Temporary workaround to ignore the updateGoal command until the integration test instance is fixed. - command_keys = [c.Meta.key for c in COMMANDS if c.Meta.key != "updateGoal"] - + command_keys = [c.Meta.key for c in COMMANDS] assert len(command_keys) == len(commands_in_body) for i, command_key in enumerate(command_keys): assert commands_in_body[i] == command_key diff --git a/canvas_sdk/commands/tests/test_utils.py b/canvas_sdk/commands/tests/test_utils.py index 092417bf..af71c74d 100644 --- a/canvas_sdk/commands/tests/test_utils.py +++ b/canvas_sdk/commands/tests/test_utils.py @@ -190,11 +190,6 @@ def compute(self): def install_plugin(plugin_name: str, token: MaskedValue) -> None: """Install a plugin.""" with open(_build_package(Path(f"./custom-plugins/{plugin_name}")), "rb") as package: - message_received_event = wait_for_log( - cast(str, settings.INTEGRATION_TEST_URL), - token.value, - f"Loading plugin '{plugin_name}", - ) response = requests.post( plugin_url(cast(str, settings.INTEGRATION_TEST_URL)), data={"is_enabled": True}, @@ -203,8 +198,6 @@ def install_plugin(plugin_name: str, token: MaskedValue) -> None: ) response.raise_for_status() - message_received_event.wait(timeout=5.0) - def trigger_plugin_event(token: MaskedValue) -> None: """Trigger a plugin event.""" @@ -328,7 +321,9 @@ def get_token() -> MaskedValue: return MaskedValue(response.json()["access_token"]) -def wait_for_log(host: str, token: str, message: str) -> threading.Event: +def wait_for_log( + host: str, token: str, message: str +) -> tuple[threading.Event, threading.Thread, websocket.WebSocketApp]: """Wait for a specific log message.""" hostname = cast(str, urlparse(host).hostname) instance = hostname.removesuffix(".canvasmedical.com") @@ -362,4 +357,4 @@ def _on_error(ws: websocket.WebSocket, error: str) -> None: connected_event.wait(timeout=5.0) - return message_received_event + return message_received_event, thread, ws diff --git a/canvas_sdk/effects/banner_alert/tests.py b/canvas_sdk/effects/banner_alert/tests.py index 5619cccd..b3edc7be 100644 --- a/canvas_sdk/effects/banner_alert/tests.py +++ b/canvas_sdk/effects/banner_alert/tests.py @@ -92,10 +92,10 @@ def compute(self): protocol.write(protocol_code) with open(_build_package(Path(f"./custom-plugins/{plugin_name}")), "rb") as package: - message_received_event = wait_for_log( + message_received_event, thread, ws = wait_for_log( settings.INTEGRATION_TEST_URL, token.value, - f"Loading plugin '{plugin_name}:{plugin_name}.protocols.my_protocol:Protocol'", + f"Loading plugin '{plugin_name}", ) # install the plugin @@ -111,6 +111,9 @@ def compute(self): yield + ws.close() + thread.join() + # clean up if Path(f"./custom-plugins/{plugin_name}").exists(): shutil.rmtree(Path(f"./custom-plugins/{plugin_name}"))