From 23ec33085bd2ff5459567cab311fb1addc546f17 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Thu, 9 Nov 2023 20:54:29 +0000 Subject: [PATCH 1/6] Start runner on setup and stop on clenaup --- app/chip_tool/chip_tool.py | 27 +++++++++++++++------------ app/chip_tool/test_suite.py | 4 ---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/chip_tool/chip_tool.py b/app/chip_tool/chip_tool.py index b6e8d4f2..4b464005 100644 --- a/app/chip_tool/chip_tool.py +++ b/app/chip_tool/chip_tool.py @@ -322,9 +322,10 @@ def __wait_for_server_exit(self) -> Optional[int]: return exit_code async def stop_chip_tool_server(self) -> None: - await self.__test_harness_runner.start() + await self.start_runner() await self.__test_harness_runner._client.send("quit()") self.__wait_for_server_exit() + self.stop_runner() self.__server_started = False def __get_gateway_ip(self) -> str: @@ -393,12 +394,15 @@ async def start_container( def destroy_device(self) -> None: """Destroy the device container.""" + self.stop_chip_tool_server() + if self.__chip_tool_container is not None: container_manager.destroy(self.__chip_tool_container) self.__chip_tool_container = None async def start_runner(self) -> None: - await self.__test_harness_runner.start() + if not self.__test_harness_runner.is_connected: + await self.__test_harness_runner.start() async def stop_runner(self) -> None: await self.__test_harness_runner.stop() @@ -470,12 +474,8 @@ def last_command_exit_code(self) -> Optional[int]: return exit_code async def send_websocket_command(self, cmd: str) -> Union[str, bytes, bytearray]: - response = None - try: - await self.__test_harness_runner.start() - response = await self.__test_harness_runner.execute(cmd) - finally: - await self.__test_harness_runner.stop() + await self.start_runner() + response = await self.__test_harness_runner.execute(cmd) # Log response if response: @@ -523,12 +523,15 @@ async def run_websocket_test( ) self.__runner_hooks = test_step_interface runner_config = TestRunnerConfig( - adapter, self.pseudo_clusters, runner_options, test_step_interface + adapter, + self.pseudo_clusters, + runner_options, + test_step_interface, + auto_start_stop=False, ) - web_socket_config = WebSocketRunnerConfig() - web_socket_config.server_address = self.__get_gateway_ip() - self.__test_harness_runner = WebSocketRunner(config=web_socket_config) + await self.start_runner() + return await self.__test_harness_runner.run( parser_builder_config, runner_config ) diff --git a/app/chip_tool/test_suite.py b/app/chip_tool/test_suite.py index 7fb57a85..629b861c 100644 --- a/app/chip_tool/test_suite.py +++ b/app/chip_tool/test_suite.py @@ -163,12 +163,8 @@ async def cleanup(self) -> None: # the test completes. So we need to start it again to # perform decommissioning elif self.test_type == ChipToolTestType.CHIP_APP: - logger.info("Run simulated app instance to perform decommissioning") - await self.chip_tool.start_runner() logger.info("Prompt user to perform decommissioning") await self.__prompt_user_to_perform_decommission() - logger.info("Stop simulated app instance") - await self.chip_tool.stop_runner() logger.info("Stopping chip-tool container") self.chip_tool.destroy_device() From 4aeae9adca1d1b17a621f9d29eb0cae464d33839 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Tue, 14 Nov 2023 15:07:37 +0000 Subject: [PATCH 2/6] Update SDK SHA --- app/core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/core/config.py b/app/core/config.py index 886f6b3d..41a8c12e 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -115,7 +115,7 @@ def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool: SDK_DOCKER_IMAGE: str = "connectedhomeip/chip-cert-bins" SDK_DOCKER_TAG: str = "f06d9520d02d68076c5accbf839f168cda89c47c" # SDK SHA: used to fetch test YAML from SDK. - SDK_SHA: str = "f06d9520d02d68076c5accbf839f168cda89c47c" + SDK_SHA: str = "4fde331ac902b7349653f069e9da6c933efa1466" class Config: case_sensitive = True From 397a07bed6ac5c5bddfab6491785e3fc0113f289 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Tue, 14 Nov 2023 19:27:26 +0000 Subject: [PATCH 3/6] Fix mypy error --- app/chip_tool/chip_tool.py | 15 ++++++++------- app/chip_tool/test_suite.py | 2 +- app/tests/chip_tool/test_chip_tool.py | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/chip_tool/chip_tool.py b/app/chip_tool/chip_tool.py index 4b464005..e5b5b7a3 100644 --- a/app/chip_tool/chip_tool.py +++ b/app/chip_tool/chip_tool.py @@ -322,11 +322,12 @@ def __wait_for_server_exit(self) -> Optional[int]: return exit_code async def stop_chip_tool_server(self) -> None: - await self.start_runner() - await self.__test_harness_runner._client.send("quit()") - self.__wait_for_server_exit() - self.stop_runner() - self.__server_started = False + if self.__server_started: + await self.start_runner() + await self.__test_harness_runner._client.send("quit()") + self.__wait_for_server_exit() + await self.stop_runner() + self.__server_started = False def __get_gateway_ip(self) -> str: """ @@ -392,9 +393,9 @@ async def start_container( self.__chip_tool_log = await self.start_chip_server(test_type, use_paa_certs) - def destroy_device(self) -> None: + async def destroy_device(self) -> None: """Destroy the device container.""" - self.stop_chip_tool_server() + await self.stop_chip_tool_server() if self.__chip_tool_container is not None: container_manager.destroy(self.__chip_tool_container) diff --git a/app/chip_tool/test_suite.py b/app/chip_tool/test_suite.py index 629b861c..9bc1c62f 100644 --- a/app/chip_tool/test_suite.py +++ b/app/chip_tool/test_suite.py @@ -167,7 +167,7 @@ async def cleanup(self) -> None: await self.__prompt_user_to_perform_decommission() logger.info("Stopping chip-tool container") - self.chip_tool.destroy_device() + await self.chip_tool.destroy_device() if self.border_router is not None: logger.info("Stopping border router container") self.border_router.destroy_device() diff --git a/app/tests/chip_tool/test_chip_tool.py b/app/tests/chip_tool/test_chip_tool.py index 139e8899..871b0d1f 100644 --- a/app/tests/chip_tool/test_chip_tool.py +++ b/app/tests/chip_tool/test_chip_tool.py @@ -364,7 +364,7 @@ async def test_destroy_container_running() -> None: assert chip_tool._ChipTool__chip_tool_container is not None - chip_tool.destroy_device() + await chip_tool.destroy_device() mock_destroy.assert_called() assert chip_tool._ChipTool__chip_tool_container is None @@ -377,7 +377,7 @@ async def test_destroy_container_not_running() -> None: with mock.patch.object( target=container_manager, attribute="destroy" ) as mock_destroy: - chip_tool.destroy_device() + await chip_tool.destroy_device() mock_destroy.assert_not_called() assert chip_tool._ChipTool__chip_tool_container is None @@ -405,8 +405,8 @@ async def test_destroy_container_once() -> None: ): await chip_tool.start_container(test_type) - chip_tool.destroy_device() - chip_tool.destroy_device() + await chip_tool.destroy_device() + await chip_tool.destroy_device() mock_destroy.assert_called_once() assert chip_tool._ChipTool__chip_tool_container is None From c7c6efe0dfb69f96f059b33496f73f0a65d17825 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Tue, 14 Nov 2023 21:47:09 +0000 Subject: [PATCH 4/6] Fix unit tests --- app/tests/chip_tool/test_chip_tool.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/tests/chip_tool/test_chip_tool.py b/app/tests/chip_tool/test_chip_tool.py index 871b0d1f..3f417780 100644 --- a/app/tests/chip_tool/test_chip_tool.py +++ b/app/tests/chip_tool/test_chip_tool.py @@ -585,6 +585,9 @@ async def test_run_test_default_config() -> None: return_value=fake_container, ), mock.patch.object( target=chip_tool, attribute="start_chip_server" + ), mock.patch( + target="app.chip_tool.chip_tool.WebSocketRunner.start", + return_value=True, ), mock.patch( target="app.chip_tool.chip_tool.WebSocketRunner.run", return_value=True, @@ -610,7 +613,7 @@ async def test_run_test_default_config() -> None: runner_config: TestRunnerConfig = mock_run.mock_calls[0].args[1] runner_options = runner_config.options assert runner_options.stop_on_error is not CHIP_TOOL_CONTINUE_ON_FAILURE_VALUE - assert runner_options.stop_on_warning is False + assert runner_options.stop_on_warning is False assert runner_options.stop_at_number == -1 assert runner_options.delay_in_ms == TEST_STEP_DELAY_VALUE @@ -639,6 +642,9 @@ async def test_run_test_custom_timeout() -> None: return_value=fake_container, ), mock.patch.object( target=chip_tool, attribute="start_chip_server" + ), mock.patch( + target="app.chip_tool.chip_tool.WebSocketRunner.start", + return_value=True, ), mock.patch( target="app.chip_tool.chip_tool.WebSocketRunner.run", return_value=True, @@ -687,6 +693,9 @@ async def test_run_test_with_custom_parameter() -> None: return_value=fake_container, ), mock.patch.object( target=chip_tool, attribute="start_chip_server" + ), mock.patch( + target="app.chip_tool.chip_tool.WebSocketRunner.start", + return_value=True, ), mock.patch( target="app.chip_tool.chip_tool.WebSocketRunner.run", return_value=True, @@ -736,6 +745,9 @@ async def test_run_test_with_endpoint_parameter() -> None: return_value=fake_container, ), mock.patch.object( target=chip_tool, attribute="start_chip_server" + ), mock.patch( + target="app.chip_tool.chip_tool.WebSocketRunner.start", + return_value=True, ), mock.patch( target="app.chip_tool.chip_tool.WebSocketRunner.run", return_value=True, @@ -784,6 +796,9 @@ async def test_run_test_with_nodeID_and_cluster_parameters() -> None: return_value=fake_container, ), mock.patch.object( target=chip_tool, attribute="start_chip_server" + ), mock.patch( + target="app.chip_tool.chip_tool.WebSocketRunner.start", + return_value=True, ), mock.patch( target="app.chip_tool.chip_tool.WebSocketRunner.run", return_value=True, From 99aa58855970d70f79359e50ba10000f576fce1f Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Tue, 14 Nov 2023 21:54:48 +0000 Subject: [PATCH 5/6] Remove trailing whitespace --- app/tests/chip_tool/test_chip_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/tests/chip_tool/test_chip_tool.py b/app/tests/chip_tool/test_chip_tool.py index 3f417780..aa45635d 100644 --- a/app/tests/chip_tool/test_chip_tool.py +++ b/app/tests/chip_tool/test_chip_tool.py @@ -613,7 +613,7 @@ async def test_run_test_default_config() -> None: runner_config: TestRunnerConfig = mock_run.mock_calls[0].args[1] runner_options = runner_config.options assert runner_options.stop_on_error is not CHIP_TOOL_CONTINUE_ON_FAILURE_VALUE - assert runner_options.stop_on_warning is False + assert runner_options.stop_on_warning is False assert runner_options.stop_at_number == -1 assert runner_options.delay_in_ms == TEST_STEP_DELAY_VALUE From 2a1919830c9c01c901393ef8b5cc6d07448aa618 Mon Sep 17 00:00:00 2001 From: Carolina Lopes Date: Wed, 22 Nov 2023 18:49:23 +0000 Subject: [PATCH 6/6] Update python tests submodule --- test_collections/python_tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_collections/python_tests b/test_collections/python_tests index 49998e9f..43812f22 160000 --- a/test_collections/python_tests +++ b/test_collections/python_tests @@ -1 +1 @@ -Subproject commit 49998e9f4da0dc60995a05917ef61ecec7c6f603 +Subproject commit 43812f22805302c63645834efbea77ff90a708fa