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()