Skip to content

Commit

Permalink
Merge branch 'project-chip:main' into feature/74_phase3-add_python_te…
Browse files Browse the repository at this point in the history
…sts_model_classes
  • Loading branch information
rquidute authored Nov 27, 2023
2 parents 77cf574 + 83958eb commit 63e39e2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
36 changes: 20 additions & 16 deletions app/chip_tool/chip_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,12 @@ 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.__test_harness_runner._client.send("quit()")
self.__wait_for_server_exit()
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:
"""
Expand Down Expand Up @@ -408,14 +410,17 @@ async def start_server(

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."""
await 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()
Expand Down Expand Up @@ -487,12 +492,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:
Expand Down Expand Up @@ -540,12 +541,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
)
Expand Down
6 changes: 1 addition & 5 deletions app/chip_tool/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,11 @@ 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()
await self.chip_tool.destroy_device()
if self.border_router is not None:
logger.info("Stopping border router container")
self.border_router.destroy_device()
Expand Down
2 changes: 1 addition & 1 deletion app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions app/tests/chip_tool/test_chip_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -405,8 +405,8 @@ async def test_destroy_container_once() -> None:
):
await chip_tool.start_server(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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test_collections/python_tests

0 comments on commit 63e39e2

Please sign in to comment.